Welcome to YaranaIoT Guru’s ESP32 tutorial! In this guide, we’ll show you how to control an LED remotely using an Android app via Bluetooth.
ESP32 is a powerful microcontroller that comes with built-in Bluetooth and Wi-Fi. By using its Bluetooth capabilities, we can create a DIY home automation system to control devices such as LEDs, relays, or small appliances without any internet connection.
🔹 Why Bluetooth Control?
- Works offline, no Wi-Fi required
- Ideal for home automation in apartments or remote locations
- Simple to implement and perfect for learning Bluetooth communication
- Can be extended to control multiple devices like fans, motors, and relays
🔹 Project Goals
- Set up ESP32 Bluetooth communication
- Create a simple Android app (via MIT App Inventor / Blynk / custom)
- Control LED ON/OFF remotely
- Display status feedback in the app
- Lay the foundation for smart home automation projects
🔹 Applications
- Control LEDs, relays, and small appliances
- Smart lighting in homes or offices
- DIY home automation and IoT workshops
- Educational Bluetooth communication projects
🔹 Required Components
| Component | Quantity | Description |
|---|---|---|
| ESP32 Dev Board | 1 | Microcontroller with Bluetooth |
| LED | 1 | Output indicator |
| 220Ω Resistor | 1 | Current limiting for LED |
| Breadboard & Jumper Wires | As needed | Circuit setup |
| USB Cable | 1 | ESP32 programming |
| Android Phone | 1 | App to control LED |
| Arduino IDE | 1 | Development environment |
🔹 Circuit Overview
Connections:
- LED → GPIO2
- 220Ω Resistor in series → GND
- ESP32 powered via USB
This simple hardware setup is enough to test Bluetooth control, and additional LEDs or relays can be added later.
🔹 How It Works
- ESP32 starts a Bluetooth server using Serial Bluetooth
- Android app connects to ESP32 via Bluetooth
- Commands from the app (
ONorOFF) are received by ESP32 - ESP32 toggles the LED accordingly
- Feedback can be sent back to the app to indicate current LED status
🔹 Step 1: Arduino IDE Setup for ESP32
- Install the latest Arduino IDE from https://www.arduino.cc/en/software
- Add ESP32 board support:
- Go to File → Preferences → Additional Board Manager URLs
- Add:
https://dl.espressif.com/dl/package_esp32_index.json - Go to Tools → Board → Board Manager, search ESP32, and install
- Select your ESP32 board:
- Tools → Board → ESP32 Dev Module
- Select the correct COM port
🔹 Step 2: Initialize Bluetooth Serial on ESP32
ESP32 has built-in Bluetooth. We can use BluetoothSerial library to create a Bluetooth server:
#include "BluetoothSerial.h"
BluetoothSerial SerialBT; // Create Bluetooth Serial object
const int ledPin = 2; // LED GPIO pin
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
// Start Bluetooth with device name
SerialBT.begin("ESP32_LED_Control");
Serial.println("Bluetooth device started, connect from your Android phone");
}
void loop() {
if (SerialBT.available()) { // Check if data received
char command = SerialBT.read(); // Read command
if (command == '1') { // Turn LED ON
digitalWrite(ledPin, HIGH);
SerialBT.println("LED ON"); // Send feedback
} else if (command == '0') { // Turn LED OFF
digitalWrite(ledPin, LOW);
SerialBT.println("LED OFF"); // Send feedback
}
}
}
✅ This code allows LED control using Bluetooth commands:
- Send
1→ LED ON - Send
0→ LED OFF - Feedback sent back to the Android app
🔹 Step 3: Connect Android App to ESP32
You can use any Bluetooth terminal app (like Serial Bluetooth Terminal) or custom Android app:
- Open Bluetooth on your phone
- Scan for devices → connect to ESP32_LED_Control
- Send commands:
1or0 - LED should turn ON/OFF, and feedback will appear in the app
🔹 Step 4: Optional Enhancements
- Multiple LEDs
- Add additional GPIO pins and commands (
2for LED2,3for LED3, etc.)
- Add additional GPIO pins and commands (
- Visual feedback on ESP32
- Use onboard LED (GPIO 2) to show device activity
- Serial Monitor Debug
- Monitor commands received and feedback sent
🔹 Step 5: Testing & Troubleshooting
- Ensure Bluetooth on ESP32 is started before connecting
- Check correct COM port in Arduino IDE
- Use simple commands (
1or0) to avoid issues - Ensure LED + resistor is connected properly
🔹 1. Tools for Creating the Android App
You can use:
- MIT App Inventor (Free, web-based) → drag-and-drop interface
- Blynk App (Optional) → IoT app for controlling devices
For simplicity, we’ll use MIT App Inventor.
🔹 2. Design Your App
App Components:
| Component | Purpose |
|---|---|
| ListPicker | Select Bluetooth device |
| Button ON | Send command to turn LED ON |
| Button OFF | Send command to turn LED OFF |
| Label | Display LED status feedback |
| BluetoothClient | ESP32 communication |
Steps:
- Drag ListPicker → Rename to
SelectDevice - Drag Two Buttons → Rename
LED_ONandLED_OFF - Drag Label → Rename
StatusLabel - Add BluetoothClient from Connectivity palette
🔹 3. Blocks Logic in MIT App Inventor
Step 1: Connect to ESP32
- When
SelectDeviceclicked → show list of Bluetooth devices - On selection → call
BluetoothClient.Connect
Step 2: Send Commands
When LED_ON.Click
call BluetoothClient.SendText("1")
set StatusLabel.Text to "LED ON"
When LED_OFF.Click
call BluetoothClient.SendText("0")
set StatusLabel.Text to "LED OFF"
- Command
"1"→ LED ON - Command
"0"→ LED OFF
Step 3: Receive Feedback (Optional)
- ESP32 sends
"LED ON"or"LED OFF"over Bluetooth - Display feedback in StatusLabel
When BluetoothClient.BytesReceived
set StatusLabel.Text to BluetoothClient.ReceiveText()
🔹 4. Real-Time Control
- Buttons in the app send immediate commands
- Feedback from ESP32 shows current LED status
- Works offline, no internet needed
🔹 5. Optional Enhancements
- Multiple LEDs / Devices
- Add more buttons → send
2,3, etc.
- Add more buttons → send
- RGB LED Control
- Use commands like
R255,G0,B0for color control
- Use commands like
- Smart Automation
- Schedule LED ON/OFF from the app
- Use a Slider
- Control brightness via PWM
🔹 6. Testing & Troubleshooting
- Ensure ESP32 Bluetooth is ON and visible
- Check app connects to the correct device
- Use Serial Monitor to debug commands received
- Verify LED pin and resistor connections
🔹 1. Multiple LED Control
You can control several LEDs using unique commands from your Android app.
ESP32 Example Code:
const int led1 = 2;
const int led2 = 4;
const int led3 = 5;
void loop() {
if (SerialBT.available()) {
char command = SerialBT.read();
switch(command) {
case '1': digitalWrite(led1, HIGH); SerialBT.println("LED1 ON"); break;
case '2': digitalWrite(led1, LOW); SerialBT.println("LED1 OFF"); break;
case '3': digitalWrite(led2, HIGH); SerialBT.println("LED2 ON"); break;
case '4': digitalWrite(led2, LOW); SerialBT.println("LED2 OFF"); break;
case '5': digitalWrite(led3, HIGH); SerialBT.println("LED3 ON"); break;
case '6': digitalWrite(led3, LOW); SerialBT.println("LED3 OFF"); break;
}
}
}
- App sends
1-6to control 3 LEDs - Feedback confirms LED status in real-time
🔹 2. PWM LED Brightness Control
Control LED brightness using PWM:
const int ledPin = 2;
int brightness = 0;
void loop() {
if(SerialBT.available()){
brightness = SerialBT.read(); // Expect 0-255
analogWrite(ledPin, brightness);
SerialBT.print("Brightness: ");
SerialBT.println(brightness);
}
}
- App can use a slider to send 0–255 values
- LED brightness changes dynamically
🔹 3. Timer-Based Automation
You can automate LED control with timers:
unsigned long previousMillis = 0;
const long interval = 5000; // 5 seconds
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
digitalWrite(led1, !digitalRead(led1)); // Toggle LED every 5 seconds
}
}
- Perfect for scheduled lighting or night lamps
- Can integrate multiple devices
🔹 4. Expand to Full Smart Home Automation
- Add Relays to control AC devices
- Integrate Sensors: Motion, temperature, humidity
- Group multiple ESP32 devices controlled via Bluetooth app
- Offline home automation: works without internet
🔹 5. Optional Advanced Features
- RGB LED Control: Control color with 3 PWM channels
- Scene Management: Turn on multiple LEDs in patterns
- Energy Saving Automation: Auto OFF if no activity detected
- Voice Assistant Integration: Use Bluetooth + Google Assistant / Alexa
🔹 6. Testing & Deployment
- Test LED commands on single and multiple devices
- Verify feedback on the app
- Test timers and PWM sliders
- Expand app UI to control more devices
- Ensure Bluetooth connectivity is stable for continuous operation
🔹 Conclusion
By completing this tutorial, you have learned to:
- Build an ESP32 Bluetooth server
- Control LEDs remotely using an Android app
- Add multiple devices and PWM brightness control
- Automate devices using timers
- Lay the foundation for advanced smart home automation projects
“With ESP32 and Bluetooth, you can create a full-featured DIY home automation system that’s offline, secure, and highly customizable.”
— YaranaIoT Guru
📞 Contact YaranaIoT Guru Empowering IoT Innovation | ESP32 | Home Automation | Smart Solutions | 50K+ Community
We’d love to hear from you! Whether it’s IoT project queries, collaborations, tech support, custom PCB design, bulk orders, corporate training, college workshops, or freelance development — we’re just one message away.
✉️ Email (Official)
For detailed inquiries, project support, business collaboration, sponsorships, or documentation: 📩 contact@yaranaiotguru.in 📧 Alternate: support@yaranaiotguru.in ⏳ Response: Within 24 hours (Mon–Sat) 💡 Best for attachments (code, schematics, logs, etc.)
📱 Phone / WhatsApp (24×7 Support)
Instant live help, troubleshooting, project consultation, or order updates: 📞 +91 70527 22734 💬 WhatsApp: Chat Now ⏰ Call Hours: Mon–Sat, 10 AM – 7 PM IST 🚀 Emergency? WhatsApp anytime — reply within 1 hour
🌐 Official Website
Tutorials, code, PDFs, schematics, blogs, free tools & online store: 🔗 www.yaranaiotguru.in 🛒 Shop: yaranaiotguru.in/shop (ESP32 DevKits, Sensors, Relays, Custom PCBs, Project Kits)
▶️ YouTube Channel
Step-by-step IoT builds, live coding, ESP32, Blynk, Node-RED, MQTT, Home Assistant & more: 🔗 Yarana IoT Guru 📺 1,200+ Videos | 52K+ Subs | 5.5M+ Views | 4.8★ Rating 🎥 New Video Every Week — 🔔 Subscribe & Turn On Notifications
🛠 GitHub (100% Open Source)
All codes, Arduino sketches, PlatformIO projects, Node-RED flows, MQTT configs & docs: 🔗 github.com/YaranaIotGuru ⭐ 50+ Repos | 10K+ Stars & Forks
🔥 Top Projects:
- ESP32 WebSocket Real-Time Dashboard
- Smart Home with Blynk & Alexa
- IoT Irrigation System with Soil Moisture
- MQTT + Node-RED + MySQL Logging
- OLED Weather Station with API
Daily reels, quick tips, live builds, student showcases & giveaways: 🔗 @YaranaIoTGuru 📱 10K+ Followers | Reels | Stories | Live Sessions
💼 LinkedIn (Professional Network)
B2B, IoT consulting, training, hiring & partnerships: 🔗 Yarana IoT Guru
🤝 Services Offered:
- Custom IoT Product Development
- Embedded Systems Training
- College Workshops & FDPs
- PCB Design & Prototyping
🐦 Twitter / X
Real-time updates, polls, project launches & community Q&A: 🔗 @YaranaIoTGuru 📢 Follow for instant alerts
🛠 Hackster.io (Project Showcases)
In-depth write-ups, circuits, BOM, code & ratings: 🔗 hackster.io/yaranaiotguru 🏆 50+ Projects | 100K+ Views | Top 5% Creator
📝 Instructables (DIY Guides)
Beginner-friendly step-by-step guides with templates & troubleshooting: 🔗 instructables.com/member/YaranaIoTGuru
🛠 Featured Guides:
- Automatic Plant Watering System
- Voice-Controlled Home Appliances
- WiFi-enabled Temperature Monitor
📚 Medium Blog
Deep-dive articles, trends, tutorials & career tips in embedded systems: 🔗 medium.com/@yaranaiotguru ✍️ 50+ Articles | 15K+ Readers
🛒 Online Store & Kits
Ready-to-use IoT kits, custom PCBs, sensors & merch: 🔗 yaranaiotguru.in/shop 📦 Free Shipping in India above ₹999 💳 Payment: UPI, Card, Wallet, COD
🌟 Community Platforms
| Platform | Link | Purpose |
|---|---|---|
| Telegram Channel | t.me/YaranaIoTGuru | Project files, PDFs, updates |
| Telegram Group | t.me/YaranaIoTCommunity | Peer support, doubts |
| Discord Server | discord.gg/yarana-iot | Live voice help, coding rooms |
| WhatsApp Community | Join Here | Announcements & polls |
🏢 Office & Studio Address
Yarana Studio & Software (Yarana IoT Guru HQ) 📍 Near Rookh Baba Mandir, Umariya Badal Urf Gainda, Allahabad (Prayagraj), Uttar Pradesh – 212507, India ⭐ Google Rating: 5.0 ★ (100+ Reviews)
🕒 Opening Hours: Mon–Sat: 10:00 AM – 5:00 PM Sunday: Closed
🌐 Associated Website: yaranawebtech.in 🗺️ View on Google Maps: Search “Yarana Studio & Software” 📌 Walk-ins welcome | Appointment recommended for project discussions