ble-capteur.ino
S3 BLE with ArduinoBLE: the board advertises a 181A service with a measurement characteristic any phone can read or listen to (notify). The analog level is pushed every second to the connected central, no polling on the app side.
Hardware
An Arduino Nano ESP32 (dual-core ESP32-S3, 2.4 GHz Wi-Fi + Bluetooth Low Energy, Nano-compatible physical pinout, native USB, 3.3 V pins only). Nano ESP32, phone with nRF Connect (or other BLE scanner), sensor on A0.
Wiring
Nothing to wire to test with a floating pin; 0-3.3 V sensor on A0 in real use.
How it works
BLE.advertise broadcasts name and service; central.connected() holds the session. writeValue on a BLENotify characteristic pushes an ATT notification to the phone.
Running it
Install the Arduino ESP32 Boards package (or follow the official Nano ESP32 guide), select Arduino Nano ESP32, upload. Pins are 3.3 V: never feed 5 V into an input. The serial monitor uses native USB.
Variants
Add pairing/bonding to encrypt the link, or emulate the standard Battery profile (0x180F) to be visible to OSes without a dedicated app.
ble-capteur.ino
// Service BLE personnalise sur le Nano ESP32 (ArduinoBLE).
// Une caracteristique "mesure" notifie le niveau analogique.
#include <ArduinoBLE.h>
BLEService service("181A"); // service capteur environnemental
BLEUnsignedCharCharacteristic mesure("2A6E", BLERead | BLENotify);
void setup() {
Serial.begin(115200);
if (!BLE.begin()) {
Serial.println(F("BLE KO"));
while (true);
}
BLE.setLocalName("NanoESP32-Capteur");
BLE.setAdvertisedService(service);
service.addCharacteristic(mesure);
BLE.addService(service);
mesure.writeValue(0);
BLE.advertise();
Serial.println(F("BLE pret, en attente de connexion"));
}
void loop() {
BLEDevice central = BLE.central();
if (central) {
Serial.print(F("Connecte : "));
Serial.println(central.address());
while (central.connected()) {
int brut = analogRead(A0);
uint8_t niveau = map(brut, 0, 4095, 0, 255); // ADC 12 bits
mesure.writeValue(niveau); // BLENotify : pousse vers le central
delay(1000);
}
Serial.println(F("Central deconnecte"));
}
}