- LED Blink with Button
- Motion Detection Alarm System
- Simple RGB LED Controller
- Blinking LED with WebSocket Control
- Control LED Brightness using PWM
- Web Page with HTML and CSS on ESP32
- Control Multiple LEDs
- ESP32 with Bluetooth Serial Communication
- EEPROM with ESP32
- ESP32 Push Button Input: Reading Digital States
- Interfacing DHT11 Sensor
- Interfacing Ultrasonic Sensor
- Interfacing Flame Sensor
- Interfacing Sound Sensor
- Interfacing Potentiometer
- Interfacing IR Sensor
- Interfacing Servo Motor
- Interfacing Cam Wireless
- Interfacing DC Motor
- Interfacing Shock Sensor
- Interfacing Color Recognition Sensor
- Interfacing RFID Module
- TTGO LoRa32 SX1276 OLED
- Interfacing Keypad
- Interfacing Solenoid Lock
- Interfacing 16x2 LCD
- Interfacing Soil Moisture
- Interfacing MQ-7 Gas Sensor
- Interfacing Light Sleep Mode
- Interfacing Smart Light Control
- Interfacing (IoT) Weather Station
- Interfacing Web Server for Temperature Data Display
- Interfacing Home Automation System with Relay Control
- Interfacing IoT Smart Garden
- Face Recognition-Based Door Unlock System
- Interfacing Wi-Fi Jammer Detector
- Interfacing Health Band with Pulse
- Interfacing Sound Level Logger for Classrooms
- Night Vision Surveillance Camera
- Solar Panel Monitoring System
- Smart Farming Robot for Crop Surveillance
- Smart Water Quality Monitoring System
- Industrial IoT Gateway for Real-Time Monitoring
- Agriculture System with Automated Drone Control
ESP32 Smart Light Control Using Bluetooth
What is Bluetooth on ESP32?
The ESP32 comes with built-in Bluetooth capabilities, including both Bluetooth Classic and Bluetooth Low Energy (BLE). For this project, we will be using Bluetooth Classic to establish communication between the ESP32 and a mobile app or Bluetooth device to control the light. Bluetooth allows us to send and receive data wirelessly, making it ideal for remote control applications.
How Bluetooth Controls the Smart Light
In this project, the mobile app sends commands to the ESP32 over Bluetooth to control the state of the connected light (LED). The ESP32 receives these commands and toggles the LED's state accordingly. Bluetooth communication enables the user to turn the light on or off from a distance, providing a wireless method of control.
- Set up the ESP32 development environment in Arduino IDE and install the necessary Bluetooth libraries.
- Configure a Bluetooth serial communication object using `BluetoothSerial` library for Bluetooth Classic support.
- Set up GPIO pin connected to the LED (or any light module) to control its state.
- Create a simple mobile app or use a Bluetooth terminal app to send commands to the ESP32.
- Test Bluetooth connectivity by pairing the mobile device with the ESP32.
- Control the light state from the app by sending commands such as 'ON' or 'OFF'.
Formula: Power Consumption of ESP32 + Power Consumption of LED = Total Power Consumption
Components Required
- 1 × ESP32 Development Board
- 1 × LED (or any suitable light module)
- 1 × 220Ω Resistor (for LED)
- 1 × Breadboard and Jumper Wires
- 1 × Bluetooth Terminal Mobile App (or custom app for control)
- 1 × Power Supply (e.g., 5V USB power adapter)
Pin Configuration
- GPIO 2 (LED Pin): GPIO pin connected to the LED for controlling its state.
Ensure that the GPIO pin is correctly configured for output and the LED is connected with an appropriate current-limiting resistor to avoid damage.
Wiring and Connections
- LED VCC -> 3.3V
- LED GND -> GND
- LED OUT -> GPIO 2
Code for ESP32 Bluetooth Smart Light Control
1#include <BluetoothSerial.h>
2
3BluetoothSerial SerialBT;
4#define LED_PIN 2
5
6void setup() {
7 Serial.begin(115200);
8 SerialBT.begin("ESP32_Smart_Light"); // Start Bluetooth with the name ESP32_Smart_Light
9 pinMode(LED_PIN, OUTPUT);
10 Serial.println("Bluetooth Smart Light Control");
11}
12
13void loop() {
14 if (SerialBT.available()) {
15 char receivedChar = SerialBT.read();
16 if (receivedChar == '1') {
17 digitalWrite(LED_PIN, HIGH); // Turn ON the light
18 Serial.println("Light ON");
19 } else if (receivedChar == '0') {
20 digitalWrite(LED_PIN, LOW); // Turn OFF the light
21 Serial.println("Light OFF");
22 }
23 }
24 delay(20);
25}
Code Explanation
- #include <BluetoothSerial.h>: Includes the BluetoothSerial library for Bluetooth communication on ESP32.
- BluetoothSerial SerialBT;: Creates a Bluetooth serial object for communication with Bluetooth-enabled devices.
- SerialBT.begin("ESP32_Smart_Light");: Initializes Bluetooth with the device name 'ESP32_Smart_Light'. This name will appear when searching for devices on your mobile app.
- if (receivedChar == '1') { digitalWrite(LED_PIN, HIGH); }: Turns ON the LED when the character '1' is received from the mobile app.
- else if (receivedChar == '0') { digitalWrite(LED_PIN, LOW); }: Turns OFF the LED when the character '0' is received from the mobile app.
Applications
- Home automation for controlling lights remotely
- Smart home projects with Bluetooth-based device control
- Bluetooth-enabled security systems
- Wireless control for industrial or outdoor lighting systems
- IoT applications where remote light control is required
Conclusion
The ESP32 Smart Light Control project demonstrates how to use Bluetooth communication to remotely control a light source. By utilizing the Bluetooth capabilities of the ESP32, you can create a simple yet effective smart lighting system that can be controlled via mobile apps or Bluetooth terminals. This project is a great starting point for building more advanced Bluetooth-based IoT applications.