I connected a 0-5V output sensor to Arduino Nano 33 BLE Sense and uploaded the following code to record the sensor measurement signal via Bluetooth communication on the iPhone using the LightBlue app. The upload process went smoothly without any issues. However, the device is not being detected on the phone (and not on other laptops either). What could be the reason for this?
I have resolved the issue mentioned above. There was a problem with the sketch code. I have made overall modifications to the code as follows and successfully paired and verified data using the nRF Connect app instead of LightBlue on the iPhone. For those who might be facing similar issues, I am leaving the final code below:
#include <ArduinoBLE.h>
// Define Bluetooth service and characteristic UUIDs
#define SERVICE_UUID "your own UUID"
#define CHARACTERISTIC_UUID "your own UUID"
const int analogPin = A0;
unsigned long previousMillis = 0;
const long interval = 100; // Sampling and Bluetooth transmission interval (0.1 seconds - 100ms)
BLEService dataService(SERVICE_UUID);
BLEFloatCharacteristic dataCharacteristic(CHARACTERISTIC_UUID, BLERead | BLENotify);
void setup() {
Serial.begin(9600);
pinMode(analogPin, INPUT);
// Initialize Bluetooth
if (!BLE.begin()) {
Serial.println("Failed to initialize Bluetooth!");
while (1);
}
// Register Bluetooth characteristics
BLE.setLocalName("FSRNano33BLE"); // Bluetooth device name visible during search
BLE.setAdvertisedService(dataService);
dataService.addCharacteristic(dataCharacteristic);
BLE.addService(dataService);
// Start Bluetooth
BLE.advertise();
Serial.println("Bluetooth started! Check data on your smartphone.");
}
void loop() {
// Calculate current time
unsigned long currentMillis = millis();
// Read analog sensor value and transmit it via Bluetooth at regular intervals
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Read analog sensor value and convert 0~5V range to 0.0~1.0
float sensorValue = analogRead(analogPin);
float voltage = sensorValue * (5.0 / 1023.0);
// Transmit sensor value via Bluetooth
dataCharacteristic.writeValue(voltage);
// Output to Serial Monitor as well
Serial.print("Voltage(V): ");
Serial.println(voltage);
}
// Handle Bluetooth events
BLE.poll();
}