A comprehensive IoT-based smart home automation system built with Flutter mobile app, ESP8266 microcontrollers, and MQTT communication protocol. Control your home devices, monitor security, track energy consumption, and automate your living space.
- Smart Lighting: Control multiple lights (Living Room, Kitchen, Bathroom) remotely
- Appliances: Smart TV, Music System, and Coffee Maker control
- Climate Control: Real-time temperature and humidity monitoring
- Air Quality: MQ135 sensor for air quality index (AQI) monitoring
- Motion Detection: Dual PIR sensors for motion monitoring
- Door/Window Sensors: Magnetic sensors for entry point monitoring
- Servo Door Control: Automated front door control with SG90 servo motor
- Security Alarms: Buzzer alerts for unauthorized access
- Camera Status: Real-time camera online/offline status
- Real-time Consumption: Track power usage with dynamic updates
- AI Predictions: LSTM-based energy consumption forecasting
- Visual Analytics: Interactive charts for hourly, daily, and monthly data
- Dashboard Metrics: Today's consumption and monthly totals
- Rule-based Automation: Create custom automation rules
- Trigger Actions: Motion, time, and sensor-based triggers
- Smart Scheduling: Automated device control based on conditions
- Modern UI: Beautiful Material Design interface
- Real-time Updates: Instant synchronization via MQTT
- Multi-screen Navigation: Dashboard, Devices, Security, Energy, and Automation screens
- Cross-platform: Android and iOS support
- Framework: Flutter 3.9.2+
- State Management: Provider
- MQTT Client: mqtt_client
- ML/AI: TensorFlow Lite (TFLite)
- Charts: Custom Flutter charts
- Microcontrollers: ESP8266 NodeMCU (3 boards)
- Sensors: DHT22 (Temp/Humidity), MQ135 (Air Quality), PIR (Motion), Magnetic (Door/Window)
- Actuators: Relay modules, SG90 Servo motor, LEDs, Buzzers
- Communication: WiFi + MQTT protocol
- MQTT Broker: Mosquitto / HiveMQ / EMQX
- Protocol: MQTT (Message Queuing Telemetry Transport)
- Optional Backend: Node.js + Express.js (for additional features)
- Arduino IDE: ESP8266 firmware development
- Flutter SDK: Mobile app development
- Python: ML model training (optional)
smart-home-automation/
βββ mobile_app_flutter/
β βββ smart_home_app/ # Flutter mobile application
β βββ lib/
β β βββ config/ # App configuration (MQTT, etc.)
β β βββ models/ # Data models
β β βββ screens/ # UI screens
β β β βββ dashboard_screen.dart
β β β βββ devices_screen.dart
β β β βββ security_screen.dart
β β β βββ energy_screen.dart
β β β βββ automation_screen.dart
β β βββ services/ # MQTT, LSTM prediction services
β βββ assets/
β β βββ models/
β β βββ energy_lstm.tflite # ML model
β βββ android/ # Android-specific files
β
βββ hardware/
β βββ arduino_code/ # ESP8266 firmware
β βββ esp8266_01_living_room.ino # Living room controller
β βββ esp8266_02_bedroom_security.ino # Security controller
β βββ esp8266_03_energy_monitoring.ino # Energy & appliances
β
βββ backend/ # Optional Node.js backend
β βββ server.js
β βββ routes/
β βββ models/
β
βββ frontend/ # Optional React web dashboard
β βββ src/
β
βββ Read me files/ # Detailed documentation
β βββ PROJECT_SETUP_GUIDE.md # Complete setup instructions
β
βββ README.md # This file
-
Arduino IDE (1.8.19+ or 2.x)
- Install ESP8266 board support
- Install required libraries (PubSubClient, DHT sensor library, etc.)
-
Flutter SDK (3.9.2+)
- Download from flutter.dev
- Add to PATH
-
MQTT Broker
- Local: Install Mosquitto
- Cloud: Use HiveMQ public broker (
broker.hivemq.com:1883)
-
Hardware
- 3x ESP8266 NodeMCU boards
- Sensors (DHT22, MQ135, PIR, Magnetic)
- Actuators (Relays, Servo, LEDs, Buzzers)
git clone <repository-url>
cd smart-home-automationEdit WiFi and MQTT settings in each Arduino file:
hardware/arduino_code/esp8266_01_living_room.ino
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* mqtt_broker = "YOUR_PC_IP_ADDRESS"; // e.g., "192.168.1.100"
const int mqtt_port = 1883;Repeat for esp8266_02_bedroom_security.ino and esp8266_03_energy_monitoring.ino.
Edit mobile_app_flutter/smart_home_app/lib/config/app_config.dart:
// Set your MQTT broker IP address
static const String homeMqttHost = 'YOUR_PC_IP_ADDRESS';
static const String collegeMqttHost = 'YOUR_PC_IP_ADDRESS';
// Or use public broker for testing
static const Environment currentEnvironment = Environment.test;- Connect ESP8266 #1 via USB
- Open
esp8266_01_living_room.inoin Arduino IDE - Select board:
Tools β Board β NodeMCU 1.0 (ESP-12E Module) - Select port:
Tools β Port β COMx - Upload code (
Ctrl+U) - Repeat for ESP8266 #2 and #3
Local Mosquitto:
# Windows
net start mosquitto
# macOS/Linux
sudo systemctl start mosquitto
# or
mosquitto -vOr use public broker (for testing):
- No setup needed, app connects to
broker.hivemq.com
cd mobile_app_flutter/smart_home_app
flutter pub get
flutter run- Real-time sensor data (Temperature, Humidity, Air Quality)
- Power consumption metrics (Today & Monthly)
- Quick device status overview
- Dynamic power values starting at 3.8 kWh
- Lights: Living Room, Kitchen, Bathroom control
- Appliances:
- Smart TV (LED + Buzzer)
- Music System (Dedicated buzzer with song selection)
- Coffee Maker (Buzzer)
- Real-time toggle switches with feedback prevention
- Motion Sensors: Dual PIR sensor monitoring
- Doors: Front door (Servo control) & Back door (Status only)
- Windows: Living, Bedroom, Kitchen monitoring
- Cameras: Always online status display
- Alarm System: Arm/Disarm functionality
- Consumption Charts: Visual representation of energy usage
- AI Predictions: LSTM model-based forecasting
- Time Periods: Hourly, Daily, Monthly views
- Comparison Graphs: Actual vs Predicted data
- Create custom automation rules
- Define triggers (motion, time, sensors)
- Set actions (lights, appliances, alarms)
- Enable/disable automation rules
The system uses the following MQTT topic structure:
# Sensor Data
home/temperature # Temperature readings
home/humidity # Humidity readings
home/air_quality # Air quality index
# Device Control
home/lights/living_room/set # Living room light control
home/lights/kitchen/set # Kitchen light control
home/lights/bathroom/set # Bathroom light control
# Security
security/motion/pir1 # PIR sensor 1 motion
security/motion/pir2 # PIR sensor 2 motion
security/door/front/control # Front door servo control (OPEN/CLOSE)
security/door/front/status # Front door status (LOCKED/UNLOCKED)
# Appliances
appliances/tv/set # Smart TV control
appliances/music/set # Music system control
appliances/music/song # Music system song selection
appliances/coffee/set # Coffee maker control
# Energy
energy/consumption/today # Today's energy consumption
energy/consumption/monthly # Monthly energy consumption
energy/power/current # Current power usage
The app supports multiple environments:
enum Environment {
home, // Home network
college, // College network
test, // Public test broker
}Switch environments in app_config.dart:
static const Environment currentEnvironment = Environment.test;- DHT22: Temperature/Humidity sensor (D4)
- MQ135: Air quality sensor (A0)
- 4-Channel Relay: Light control (D1, D2, D5, D6)
- PIR Sensors: Motion detection (D5, D6)
- Magnetic Sensors: Doors (D7, D8) & Windows (D0, D3, D4)
- SG90 Servo: Front door control (D1)
- Buzzer: Security alarm (D2)
- LED: Smart TV indicator (D7)
- Buzzers: TV/Coffee (D8), Music System (D4)
π For detailed wiring diagrams, see Read me files/PROJECT_SETUP_GUIDE.md
- ESP8266 Serial Monitor: Check for WiFi and MQTT connection messages
- MQTT Client: Use
mosquitto_subto monitor all topics:mosquitto_sub -h YOUR_IP -t "#" -v - Device Control: Test via Flutter app or MQTT commands:
mosquitto_pub -h YOUR_IP -t "home/lights/living_room/set" -m "ON"
- β Dashboard shows real-time sensor data
- β Devices screen controls all lights and appliances
- β Security screen monitors sensors and controls door
- β Energy screen displays consumption charts
- β Automation rules execute correctly
- Verify SSID and password are correct
- Ensure WiFi is 2.4GHz (ESP8266 doesn't support 5GHz)
- Check Serial Monitor for error messages
- Verify MQTT broker is running:
netstat -an | grep 1883 - Check firewall settings (port 1883)
- Ensure ESP8266 and Flutter app use the same broker IP
flutter clean
flutter pub get
cd android && ./gradlew clean && cd ..
flutter run --android-skip-build-dependency-validation- Check power supply (servo needs adequate current)
- Verify wiring: Redβ5V, BrownβGND, OrangeβD1
- Test with simple servo sweep code first
- Ensure
energy_lstm.tfliteis inassets/models/ - Check
pubspec.yamlincludes the asset - Verify Android dependency:
tensorflow-lite-select-tf-ops:2.14.0
- Complete Setup Guide: Detailed installation and configuration instructions
- Hardware Overview: Component specifications
- Architecture Summary: System architecture details
- Wiring Reference: Quick pin connection guide
- Turns on LED indicator when activated
- Plays buzzer sound for feedback
- Real-time status updates
- Dedicated buzzer for music playback
- Song selection dropdown (Happy Birthday, Jingle Bells, etc.)
- Non-blocking playback (doesn't interfere with other operations)
- Buzzer activation when turned on
- Shared buzzer with Smart TV
- SG90 servo motor for automated door movement
- Open/Close buttons in Security screen
- Dynamic status updates (Locked/Unlocked)
- Smooth servo movement with proper delays
- Dynamic power values (starts at 3.8 kWh)
- Real-time consumption tracking
- LSTM-based predictions
- Visual charts and graphs
- Motion Detection: Dual PIR sensors for comprehensive coverage
- Entry Point Monitoring: Doors and windows with magnetic sensors
- Automated Door Control: Servo-based front door mechanism
- Alarm System: Buzzer alerts for security breaches
- Real-time Status: Instant updates on all security sensors
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- ESP8266 Community for excellent documentation
- Flutter Team for the amazing framework
- MQTT.org for the lightweight protocol
- TensorFlow Team for TFLite support
For issues, questions, or contributions:
- Check the Troubleshooting section
- Review Serial Monitor output for hardware issues
- Check MQTT broker logs for communication problems
- Refer to PROJECT_SETUP_GUIDE.md for detailed instructions
π Happy Smart Home Automation! π