0% found this document useful (0 votes)
36 views5 pages

Bluetooth Communication With ESP32

Uploaded by

sampreeti sahana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views5 pages

Bluetooth Communication With ESP32

Uploaded by

sampreeti sahana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

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:

 On Button: Sends a command to the ESP32 to turn on the built-in LED.


 Off Button: Sends a command to turn off the LED.

Sensor Data Display:

 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

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {

Serial.begin(115200);

SerialBT.begin("ESP32_Test");

pinMode(LED_PIN, OUTPUT);

dht.begin();

void loop() {

if (SerialBT.available()) {

String command = SerialBT.readStringUntil('\n');

Serial.println("Command Received: " + command);

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) {

float temp = dht.readTemperature();

float hum = dht.readHumidity();

int lum = analogRead(34);

String sensorData = String(temp) + "," + String(hum) + "," + String(lum);

SerialBT.println(sensorData);

Serial.println("Sensor data sent: " + sensorData);

delay(100);

ESP32 Circuit

You might also like