Bluetooth Communication With ESP32
Bluetooth Communication With ESP32
The app will allow the user to control the ESP32’s built-in LED and display real-time environmental
sensor data collected from the ESP32.
Bluetooth Connection:
Connect Button: Establishes a Bluetooth connection between the app and the ESP32.
Disconnect Button: Ends the Bluetooth connection.
LED Control:
The app should receive and display real-time sensor data from the ESP32, including:
temperature, humidity, luminescence
The ESP32 code is designed to handle Bluetooth commands and sensor readings:
LED Control:
The ESP32 will receive Bluetooth commands from the mobile app to turn the LED on or off.
Sensor Data:
The ESP32 will read data from the DHT11 sensor (for temperature and humidity) and a light
sensor (for luminescence). It will send this data back to the app, which will display it in real
time.
Bluetooth application - MIT App Inventor
Bluetooth application
ESP32 Code
#include <BluetoothSerial.h>
#include <DHT.h>
BluetoothSerial SerialBT;
#define LED_PIN 2
#define DHTPIN 14
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32_Test");
pinMode(LED_PIN, OUTPUT);
dht.begin();
void loop() {
if (SerialBT.available()) {
if (command.indexOf("LED_ON") != -1) {
digitalWrite(LED_PIN, HIGH);
Serial.println("LED is ON");
if (command.indexOf("LED_OFF") != -1) {
digitalWrite(LED_PIN, LOW);
Serial.println("LED is OFF");
if (command.indexOf("GET_SENSOR_DATA") != -1) {
SerialBT.println(sensorData);
delay(100);
ESP32 Circuit