DIY Home Automation: Control LED with Android App and ESP32 over Bluetooth! ESP32 Tutorial

DIY Home Automation: Control LED with Android App and ESP32 over Bluetooth! ESP32 Tutorial

ESP32 IoT Projects ESP32 Tutorials Home Automation

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

  1. Set up ESP32 Bluetooth communication
  2. Create a simple Android app (via MIT App Inventor / Blynk / custom)
  3. Control LED ON/OFF remotely
  4. Display status feedback in the app
  5. 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

ComponentQuantityDescription
ESP32 Dev Board1Microcontroller with Bluetooth
LED1Output indicator
220Ω Resistor1Current limiting for LED
Breadboard & Jumper WiresAs neededCircuit setup
USB Cable1ESP32 programming
Android Phone1App to control LED
Arduino IDE1Development 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

  1. ESP32 starts a Bluetooth server using Serial Bluetooth
  2. Android app connects to ESP32 via Bluetooth
  3. Commands from the app (ON or OFF) are received by ESP32
  4. ESP32 toggles the LED accordingly
  5. Feedback can be sent back to the app to indicate current LED status

🔹 Step 1: Arduino IDE Setup for ESP32

  1. Install the latest Arduino IDE from https://www.arduino.cc/en/software
  2. 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
  3. 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:

  1. Open Bluetooth on your phone
  2. Scan for devices → connect to ESP32_LED_Control
  3. Send commands: 1 or 0
  4. LED should turn ON/OFF, and feedback will appear in the app

🔹 Step 4: Optional Enhancements

  1. Multiple LEDs
    • Add additional GPIO pins and commands (2 for LED2, 3 for LED3, etc.)
  2. Visual feedback on ESP32
    • Use onboard LED (GPIO 2) to show device activity
  3. 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 (1 or 0) to avoid issues
  • Ensure LED + resistor is connected properly

🔹 1. Tools for Creating the Android App

You can use:

  1. MIT App Inventor (Free, web-based) → drag-and-drop interface
  2. Blynk App (Optional) → IoT app for controlling devices

For simplicity, we’ll use MIT App Inventor.


🔹 2. Design Your App

App Components:

ComponentPurpose
ListPickerSelect Bluetooth device
Button ONSend command to turn LED ON
Button OFFSend command to turn LED OFF
LabelDisplay LED status feedback
BluetoothClientESP32 communication

Steps:

  1. Drag ListPicker → Rename to SelectDevice
  2. Drag Two Buttons → Rename LED_ON and LED_OFF
  3. Drag Label → Rename StatusLabel
  4. Add BluetoothClient from Connectivity palette

🔹 3. Blocks Logic in MIT App Inventor

Step 1: Connect to ESP32

  • When SelectDevice clicked → 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

  1. Multiple LEDs / Devices
    • Add more buttons → send 2, 3, etc.
  2. RGB LED Control
    • Use commands like R255,G0,B0 for color control
  3. Smart Automation
    • Schedule LED ON/OFF from the app
  4. 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-6 to 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

  1. RGB LED Control: Control color with 3 PWM channels
  2. Scene Management: Turn on multiple LEDs in patterns
  3. Energy Saving Automation: Auto OFF if no activity detected
  4. Voice Assistant Integration: Use Bluetooth + Google Assistant / Alexa

🔹 6. Testing & Deployment

  1. Test LED commands on single and multiple devices
  2. Verify feedback on the app
  3. Test timers and PWM sliders
  4. Expand app UI to control more devices
  5. Ensure Bluetooth connectivity is stable for continuous operation

🔹 Conclusion

By completing this tutorial, you have learned to:

  1. Build an ESP32 Bluetooth server
  2. Control LEDs remotely using an Android app
  3. Add multiple devices and PWM brightness control
  4. Automate devices using timers
  5. 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.inResponse: 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 NowCall 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/YaranaIotGuru50+ 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

📸 Instagram

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

PlatformLinkPurpose
Telegram Channelt.me/YaranaIoTGuruProject files, PDFs, updates
Telegram Groupt.me/YaranaIoTCommunityPeer support, doubts
Discord Serverdiscord.gg/yarana-iotLive voice help, coding rooms
WhatsApp CommunityJoin HereAnnouncements & 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

Leave a Reply

Your email address will not be published. Required fields are marked *