Welcome to YaranaIoT Guru, where innovation meets the Internet of Things!
In this exciting post, we’ll dive deep into one of the most advanced and feature-packed DIY electronics projects — My Biggest Home Automation Project Using ESP32.
This project brings together multiple smart home functionalities — controlling home appliances, monitoring environmental data, and visualizing everything on the Ubidots IoT cloud platform — all powered by the ESP32 Wi-Fi module.
The goal of this system is to make your home intelligent, efficient, and remotely accessible. Whether you’re turning on lights, monitoring room temperature, or checking device statuses from your phone or laptop, this project shows how to do it all.
🔹 Why ESP32 for Home Automation?
The ESP32 is an incredibly powerful microcontroller that combines Wi-Fi, Bluetooth, and dual-core processing in one chip. It’s affordable, power-efficient, and fully compatible with IoT platforms like Ubidots, Blynk, and Firebase.
In this project, we’ll connect sensors and relays to the ESP32, upload data to Ubidots, and control devices remotely from the cloud dashboard — making it a perfect example of real-world IoT integration.
🔹 Key Features
✅ Control home appliances (lights, fans, and more) remotely via Ubidots
✅ Real-time monitoring of temperature, humidity, and motion
✅ Two-way communication between cloud and device
✅ Secure data logging and visualization
✅ Supports both manual and automatic operation modes
✅ Compact and low-cost setup using ESP32 + Relays + Sensors
🔹 Use Cases
- Smart home or office automation
- IoT learning and demonstration model
- Cloud-based control system
- Energy-efficient smart house project
🔹 Required Components
| Component | Description |
|---|---|
| ESP32 Development Board | Main controller with Wi-Fi & Bluetooth |
| 4-Channel Relay Module | Controls AC home appliances |
| DHT11 / DHT22 Sensor | Measures temperature & humidity |
| PIR Motion Sensor | Detects human presence |
| LDR Sensor | Measures ambient light level |
| Power Supply (5V–12V) | For ESP32 and relays |
| Jumper Wires / PCB | Circuit connections |
| Ubidots Account | For IoT dashboard and cloud control |
💡 Concept Summary
The ESP32 collects sensor data and sends it to Ubidots Cloud via Wi-Fi. On Ubidots, a customizable dashboard shows live readings and buttons to control relays (lights, fans, etc.).
When a command is triggered on Ubidots, the ESP32 receives it instantly and switches the respective device — just like a professional-grade IoT home automation system.
🎥 Watch Full Tutorial on YouTube — YaranaIoT Guru for a complete walkthrough with circuit setup and live demo.
🔹 Circuit Design Overview
The circuit design is simple but powerful. The ESP32 acts as the main controller, reading sensor values and controlling appliances through the relay module. The key components — DHT11 sensor, PIR motion sensor, and LDR — provide environmental data that’s uploaded to Ubidots every few seconds.
Here’s how everything connects:
| Component | ESP32 Pin | Description |
|---|---|---|
| DHT11 Sensor | D4 | Temperature & humidity input |
| PIR Sensor | D5 | Motion detection |
| LDR Sensor | A0 | Light intensity reading |
| Relay 1 (Light) | D12 | Controls home light |
| Relay 2 (Fan) | D13 | Controls fan |
| Relay 3 (AC) | D14 | Controls air conditioner |
| Relay 4 (Socket/Other) | D27 | Controls other load |
| 5V & GND | — | Common power & ground lines |
💡 Tip: Use a 5V adapter (2A) to power both ESP32 and relays for stable operation.
🔹 How the Circuit Works
- The ESP32 constantly reads data from DHT11 (temperature & humidity), LDR (light intensity), and PIR sensor (motion).
- These readings are sent to the Ubidots IoT Cloud through Wi-Fi using MQTT or HTTP protocol.
- On the Ubidots dashboard, the data is displayed in widgets such as graphs, gauges, and indicators.
- At the same time, the relay module receives commands from Ubidots to turn ON or OFF the connected devices.
- You can also add automation logic — for example, turning on the fan when the temperature exceeds 30°C or switching on lights automatically when motion is detected at night.
🌐 Ubidots Account Setup
Ubidots is a powerful and user-friendly IoT cloud platform. Follow these steps to set it up:
- Visit https://ubidots.com and sign up for a free account.
- Go to “Devices” → “Add New Device” → “Blank Device.”
- Name your device something like “ESP32_Home_Automation.”
- Inside the device, click “Add Variable” to create:
temperaturehumiditylightmotionrelay1,relay2,relay3,relay4(for appliances)
- Each variable has a unique API variable label, which will be used in the ESP32 code.
- Go to your API Credentials page and copy your Ubidots Token — you’ll need this to connect ESP32 to your Ubidots account.
🖥️ Creating the IoT Dashboard
After adding all variables:
- Go to the “Dashboard” tab.
- Click “Add Widget” and select “Switch” for controlling each relay.
- Add “Gauge” or “Chart” widgets for displaying sensor data like temperature, humidity, and light.
- Link each widget to the appropriate variable created earlier.
- Save your dashboard — it’s now ready to control your devices in real-time.
⚡ Power Supply and Safety Tips
- Always use optocoupler-based relay modules for isolation.
- Ensure the AC load wiring is done carefully — ideally through a relay board rated for 250V/10A.
- Use female headers or a custom PCB to make connections reliable and safe.
- If possible, add a fuse and surge protection circuit for long-term operation.
🧠 Working Logic Summary
The ESP32 acts as a bridge between your physical home appliances and the virtual IoT dashboard.
Whenever a button is pressed on the Ubidots dashboard, the ESP32 receives the command and toggles the corresponding GPIO pin to activate or deactivate the relay.
Simultaneously, the ESP32 continues to publish real-time sensor readings, allowing you to monitor your home environment and control devices simultaneously.
🎥 Watch Full Circuit Demo & Ubidots Dashboard Setup on YaranaIoT Guru YouTube Channel to see live data updating in real time!
🔹 Installing Required Libraries
Before uploading the code, make sure you’ve installed the following libraries in your Arduino IDE:
- WiFi.h — for connecting the ESP32 to your Wi-Fi network.
- HTTPClient.h — for making HTTP requests to the Ubidots API.
- DHT.h — for reading temperature and humidity data from the DHT11 sensor.
To install them:
Go to Sketch → Include Library → Manage Libraries, search for each library, and click Install.
🔹 Ubidots Device Token
Log in to your Ubidots account, go to your profile → API credentials, and copy the Token (something like BBFF-abc123xyz456).
This token allows the ESP32 to send and receive data securely from Ubidots.
🧠 ESP32 Home Automation Code
Here’s the complete Arduino code — copy it into your Arduino IDE and replace the Wi-Fi name, password, and Ubidots token with your own:
/***************************************************
My Biggest Home Automation Project Using ESP32
Developed by YaranaIoT Guru
****************************************************/
#include <WiFi.h>
#include <HTTPClient.h>
#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = "Your_WiFi_Name";
const char* password = "Your_WiFi_Password";
String ubidotsToken = "Your_Ubidots_Token";
String deviceLabel = "esp32_home_automation";
int relay1 = 12;
int relay2 = 13;
int relay3 = 14;
int relay4 = 27;
int pirPin = 5;
int ldrPin = 34;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(ldrPin, INPUT);
dht.begin();
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to Wi-Fi!");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
int motion = digitalRead(pirPin);
int lightValue = analogRead(ldrPin);
sendDataToUbidots(temp, hum, lightValue, motion);
getRelayCommands();
} else {
Serial.println("Wi-Fi Disconnected!");
}
delay(5000); // Update every 5 seconds
}
void sendDataToUbidots(float temp, float hum, int light, int motion) {
HTTPClient http;
String payload = "{\"temperature\": " + String(temp) +
", \"humidity\": " + String(hum) +
", \"light\": " + String(light) +
", \"motion\": " + String(motion) + "}";
String url = "http://industrial.api.ubidots.com/api/v1.6/devices/" + deviceLabel + "/";
http.begin(url);
http.addHeader("Content-Type", "application/json");
http.addHeader("X-Auth-Token", ubidotsToken);
int httpResponseCode = http.POST(payload);
http.end();
Serial.print("Data Sent: ");
Serial.println(payload);
}
void getRelayCommands() {
HTTPClient http;
String url = "http://industrial.api.ubidots.com/api/v1.6/devices/" + deviceLabel + "/";
http.begin(url);
http.addHeader("X-Auth-Token", ubidotsToken);
int httpCode = http.GET();
if (httpCode == 200) {
String response = http.getString();
if (response.indexOf("\"relay1\":1") > 0) digitalWrite(relay1, HIGH); else digitalWrite(relay1, LOW);
if (response.indexOf("\"relay2\":1") > 0) digitalWrite(relay2, HIGH); else digitalWrite(relay2, LOW);
if (response.indexOf("\"relay3\":1") > 0) digitalWrite(relay3, HIGH); else digitalWrite(relay3, LOW);
if (response.indexOf("\"relay4\":1") > 0) digitalWrite(relay4, HIGH); else digitalWrite(relay4, LOW);
}
http.end();
}
⚡ Code Explanation
Let’s understand what’s happening step by step:
- The ESP32 connects to your Wi-Fi network using the SSID and password provided.
- It continuously reads:
- Temperature and humidity from the DHT11 sensor
- Light intensity from the LDR
- Motion status from the PIR sensor
- The function
sendDataToUbidots()uploads these readings to your Ubidots device. - The function
getRelayCommands()checks for updates from Ubidots and turns ON/OFF relays accordingly. - The ESP32 repeats this process every 5 seconds, creating a fully synchronized two-way IoT communication system.
🌍 Testing the Project
After uploading the code:
- Open the Serial Monitor at 115200 baud to see the connection and data logs.
- Visit your Ubidots Dashboard — you’ll start seeing live sensor data appear in your widgets.
- Press the switch widgets (relay buttons) to control your appliances remotely.
- Check the ESP32 board — you’ll see the corresponding relays activate instantly.
🎯 If everything works, you’ve successfully built a real-time, cloud-connected home automation system powered by ESP32 and Ubidots.
🎥 Watch the Complete Code Setup and Live Testing Video on YaranaIoT Guru YouTube Channel for step-by-step guidance and results demonstration.
🎯 Final Testing and Output
Once you’ve uploaded the code and set up the Ubidots dashboard, power up your ESP32 board. Within seconds, it connects to your Wi-Fi and starts communicating with the Ubidots cloud.
You’ll notice the following behavior:
- Real-Time Sensor Data:
The temperature, humidity, motion, and light readings start appearing live on your dashboard widgets. Each value updates every few seconds, ensuring you always have the most recent information. - Remote Appliance Control:
Toggle the switch widgets on your Ubidots dashboard to turn your devices ON or OFF. The ESP32 receives these commands instantly and activates or deactivates the relays — switching your lights, fan, or any connected appliance. - Automatic Alerts & Monitoring:
You can also configure Ubidots to send email or SMS alerts whenever certain conditions are met — for example, when motion is detected at night or the temperature exceeds 35°C. - Continuous Logging:
Ubidots automatically stores historical data, allowing you to analyze temperature trends, power usage, or light patterns over time.
⚙️ Working Logic in Real Life
The ESP32 serves as both a sensor hub and command center.
Here’s what happens under the hood:
- The ESP32 reads sensor values and uploads them to Ubidots using an HTTP POST request.
- Ubidots stores and visualizes the data in real time.
- When you toggle a control widget, Ubidots sends a response that the ESP32 receives in the
getRelayCommands()function. - Based on this, the corresponding relay is switched ON or OFF.
This creates a bi-directional IoT communication loop, ensuring your devices respond to both automatic triggers and manual control commands.
🌍 Applications of This Project
This project is not just a demo — it’s a fully scalable prototype of how modern IoT home systems function. Below are some powerful real-world applications:
- Smart Home Control:
Operate lights, fans, and air conditioners from anywhere using your Ubidots dashboard or even your smartphone browser. - Office Automation System:
Automate office lighting, AC systems, or security monitoring using motion sensors and cloud data visualization. - Smart Energy Management:
Monitor light usage and automate turning off unnecessary appliances to reduce power consumption. - IoT Learning & Education:
Ideal for students and engineers learning how to integrate microcontrollers, sensors, and cloud services. - Security Monitoring:
The PIR sensor helps detect movement when you’re away, triggering notifications or alarms instantly through Ubidots events. - Environmental Monitoring:
Log data for temperature, humidity, and light intensity to understand your room or lab conditions better.
⚡ Advantages of Using ESP32 + Ubidots
- Wi-Fi + Bluetooth Dual Connectivity: ESP32 offers high performance and multiple communication options.
- Low Cost & Power Efficient: Ideal for continuous 24/7 monitoring and control.
- Cloud-Based System: You can access and control your setup from any part of the world.
- Easy Visualization: Ubidots dashboards are simple to create and visually powerful.
- Expandability: Add more sensors, relays, or smart logic without changing the entire code structure.
🧠 Troubleshooting Tips
If something doesn’t work as expected, check these points:
- Wi-Fi Connection: Make sure your SSID and password are correct.
- Token Issues: Double-check that you’re using your Ubidots Token and device label correctly.
- Relay Power: Ensure your relays have a stable 5V power supply.
- Dashboard Setup: Verify that variable labels in Ubidots match the names used in your code.
- Serial Monitor Debugging: Use Serial output to check if data is being sent and received properly.
🚀 Future Upgrades
This system is just the beginning! Once you’ve mastered the basics, you can take your project to the next level with these upgrades:
- Voice Control Integration:
Add Google Assistant or Alexa using MQTT or IFTTT to control your appliances using voice commands. - Mobile App Dashboard:
Use the Ubidots mobile app or build your own custom Android app using MIT App Inventor for an enhanced experience. - Energy Monitoring:
Connect an energy sensor (like PZEM-004T) to track power consumption of each appliance. - Security Features:
Integrate a GSM module or camera to send motion alerts with images or SMS notifications. - Automation Rules:
Configure Ubidots to automate triggers — like turning ON a fan if temperature > 30°C, or activating lights when motion is detected at night. - Switch to ESP32 + MQTT:
MQTT protocol provides faster, lightweight communication — perfect for scaling your smart home system.
🧾 Final Summary
This ESP32 IoT Home Automation Project demonstrates how an affordable microcontroller, when paired with a cloud platform like Ubidots, can transform ordinary electrical systems into intelligent, connected smart devices.
From sensor monitoring to remote appliance control, the system handles every task smoothly and efficiently. It’s flexible enough to integrate into any home or industrial setup and simple enough for students and hobbyists to replicate.
With features like real-time feedback, two-way control, and cloud data visualization, this project marks a strong step toward modern smart living.
🎥 Watch the Full Home Automation Project Video on the YaranaIoT Guru YouTube Channel
Learn step-by-step how to wire, program, and deploy this ESP32 IoT project in your own home or lab!
💡 In Conclusion:
Your journey to a smarter home begins with a single ESP32 board.
Experiment, modify, and expand — because with IoT, the only limit is your imagination.
📞 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