This project demonstrates how to establish Bluetooth Low Energy (BLE) communication between an ESP32 microcontroller and a client device (e.g., smartphone). The ESP32 microcontroller transmits sensor data to the client device and receives control commands from the client.
- ESP32 Development Board
- Sensor (e.g., analog sensor connected to pin 32)
- LED (for demonstration purposes)
- PlatformIO IDE
- Install the PlatformIO IDE by following the instructions on the official website.
- Create a new project in PlatformIO IDE.
- Copy the provided code into the
src
directory of your PlatformIO project. - Open the
platformio.ini
file and add the necessary dependencies for ESP32 BLE communication. - Build and upload the project to your ESP32 development board.
Connect the sensor to pin 32 on the ESP32 development board. Optionally, connect an LED to pin 2 for visual feedback.
- Open the serial monitor in the PlatformIO IDE to view debug messages (baud rate: 115200).
- Scan for Bluetooth devices on your client device (e.g., smartphone).
- Connect to the Bluetooth device named "esp32BTTest".
- You should now be able to receive sensor data from the ESP32 and send control commands to it.
- The ESP32 periodically reads sensor data and transmits it to the client device via BLE.
- The ESP32 can receive control commands (e.g., to turn on/off an LED) from the client device and act accordingly.