I'm writing code so that, every time a hall monitor senses, my code additively measures 5 liters of volume as it prints each detection. Then, this data is sent via Bluetooth to a phone. (This is for a tipping bucket device that distributes 5 liters of water every time it tips). I am using the LightBlue app for the bluetooth connection. My code connects to the bluetooth app, but the LightBlue log does not show what's being printed on my serial monitor. Does anyone have any suggestions?

    // https://makersportal.com/blog/2018/10/3/arduino-tachometer-using-a-hall-effect-sensor-to-measure-rotations-from-a-fan
#include <ArduinoBLE.h>
// digital pin 2 is the hall pin

int hall_pin = 2;

// set number of hall trips for RPM reading (higher improves accuracy)

float hall_thresh = 1000000000.0;

// BLE Battery Service
        BLEService Vol_valServ("180F");

        // BLE Battery Level Characteristic
        BLEUnsignedCharCharacteristic VolumeChar("2A19",  // standard 16-bit characteristic UUID
            BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes

        long previousMillis = 0;  // last time the volume level was checked, in ms
void setup() {

  // initialize serial communication at 9600 bits per second:


   while (!Serial);

          pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected

          // begin initialization
          if (!BLE.begin()) {
            Serial.println("starting BLE failed!");

            while (1);

          /* Set a local name for the BLE device
             This name will appear in advertising packets
             and can be used by remote devices to identify this BLE device
             The name can be changed but maybe be truncated based on space left in advertisement packet
          BLE.setAdvertisedService(Vol_valServ); // add the service UUID
          Vol_valServ.addCharacteristic(VolumeChar); // add the battery level characteristic
          BLE.addService(Vol_valServ); // Add the battery service
          /* Start advertising BLE.  It will start continuously transmitting BLE
             advertising packets and will be visible to remote BLE central devices
             until it receives a new connection */

          // start advertising

          Serial.println("Bluetooth device active, waiting for connections...");


// the loop routine runs over and over again forever:

void loop() {

  // preallocate values for tach

  float hall_count = 0.0;

  float start = micros();

  bool on_state = false;

  // counting number of times the hall sensor is tripped

  // but without double counting during the same trip

  while (true) {

    if (digitalRead(hall_pin) == 0) {

      if (on_state == false) {

        on_state = true;

        hall_count += 1.0;


    } else {

      on_state = false;
      float Volume = (hall_count) * 5.0; // this is the liters per tip

      Serial.print( "hall_count");
      Serial.print( hall_count);
      Serial.println(" Volume");


        // wait for a BLE central
        BLEDevice central = BLE.central();

        // if a central is connected to the peripheral:
        if (central) {
          Serial.print("Connected to central: ");
          // print the central's BT address:
          // turn on the LED to indicate the connection:
          digitalWrite(LED_BUILTIN, HIGH);

          while (central.connected()) {

if (digitalRead(hall_pin)==0){

if (on_state==false){

on_state = true;



} else{

on_state = false;
float Volume = (hall_count)*5.0; // this is the liters per tip

Serial.println( Volume);


        // delay in between reads for stability


          digitalWrite(LED_BUILTIN, LOW);
          Serial.print("Disconnected from central: ");


          if (hall_count >= hall_thresh) {



        // print information about Time and RPM

        float end_time = micros();

        float time_passed = ((end_time - start) / 1000000.0);

        Serial.print("Time Passed: ");



        // delay in between reads for stability


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.