{"id":19883350,"url":"https://github.com/anandrawat138/smarthomeautomation","last_synced_at":"2026-04-27T11:31:05.048Z","repository":{"id":258303421,"uuid":"873659882","full_name":"AnandRawat138/SmartHomeAutomation","owner":"AnandRawat138","description":"The project involves an ESP8266 microcontroller controlling four appliances (Fan, AC, TV, and Room Light) via a 4-channel relay module. The system also includes fan speed control based on room temperature and AC status. The goal is to enable both local and remote control of these appliances","archived":false,"fork":false,"pushed_at":"2024-10-16T14:39:43.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T21:25:55.911Z","etag":null,"topics":["esp8266","esp8266-projects","iot","relay","smart-home","smarthome"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AnandRawat138.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-16T14:21:56.000Z","updated_at":"2024-10-18T11:43:17.000Z","dependencies_parsed_at":"2024-10-18T11:27:16.864Z","dependency_job_id":null,"html_url":"https://github.com/AnandRawat138/SmartHomeAutomation","commit_stats":null,"previous_names":["anandrawat138/smarthomeautomation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AnandRawat138/SmartHomeAutomation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandRawat138%2FSmartHomeAutomation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandRawat138%2FSmartHomeAutomation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandRawat138%2FSmartHomeAutomation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandRawat138%2FSmartHomeAutomation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AnandRawat138","download_url":"https://codeload.github.com/AnandRawat138/SmartHomeAutomation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AnandRawat138%2FSmartHomeAutomation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32335295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp8266","esp8266-projects","iot","relay","smart-home","smarthome"],"created_at":"2024-11-12T17:20:01.113Z","updated_at":"2026-04-27T11:31:05.032Z","avatar_url":"https://github.com/AnandRawat138.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SmartHomeAutomation\n\n1. Introduction\nThe project involves an ESP8266 microcontroller controlling four appliances (Fan, AC, TV, and Room Light) via a 4-channel relay module. The system also includes fan speed control based on room temperature and AC status. The goal is to enable both local and remote control of these appliances using Blynk, while extending voice control functionalities through Alexa and Google Assistant using IFTTT.\n\nThis report covers:\n\n1 The hardware setup.\n2 Code implementation for ESP8266 using Blynk for remote control.\n3 Integration of voice control with Alexa and Google Assistant using IFTTT.\n\n2. Hardware Setup\nThe hardware comprises:\n\n1 ESP8266 microcontroller: The main component to control the relays and handle internet connectivity.\n2 4-Channel Relay Module: Connected to the ESP8266 to switch the appliances (Fan, AC, TV, and Room Light).\n3 DHT11 Temperature Sensor: Measures the room temperature to automate fan control.\n4 Each appliance is connected to a specific GPIO pin of the ESP8266 as follows:\n\nFan: GPIO 5\nAC: GPIO 4\nTV: GPIO 0\nRoom Light: GPIO 2\n\n3. Code Implementation\nThe ESP8266 is programmed to control the four appliances through relays, adjusting the fan speed automatically based on the room temperature and the state of the AC. For remote control, the Blynk platform is utilized, providing a user interface accessible from anywhere via a smartphone or web application.\n\nKey Features:\n\n1 Relay Control: Each relay is associated with an appliance, turning the appliance on/off based on commands from Blynk or IFTTT.\n2 Temperature-Based Fan Speed: The fan speed is adjusted dynamically based on the temperature measured by the DHT11 sensor:\n   1 Fan turns on at speed 3 when the temperature drops below 24°C and the AC is on.\n   2 Fan runs at maximum speed if the temperature exceeds 26°C.\n3 Blynk Control: The Blynk app allows remote control of all four appliances using virtual pins to issue on/off commands for each device.\n\n4. Integration with Alexa and Google Assistant using IFTTT\nTo allow voice control of the appliances through Alexa and Google Assistant, we employ IFTTT. IFTTT can trigger Blynk commands using Webhooks, enabling a seamless integration between these voice assistants and the ESP8266.\n\nStep-by-Step Process:\n\nCreate an IFTTT account:\n\nLog into IFTTT and link your Google Assistant and Alexa accounts.\nSet up Blynk Webhooks:\n\nBlynk’s HTTP API allows control of devices via simple URLs. For example, turning on the fan can be done by sending an HTTP request:\nhttp\nCopy code\nhttp://blynk-cloud.com/YourBlynkAuthToken/update/D5?value=0\nThis sends a command to the ESP8266 to activate the relay connected to the fan.\n\nCreate IFTTT Applets:\n\nFor Alexa: You can create an applet that listens for a voice command like \"Turn on the fan\" and then triggers a Blynk Webhook to turn on the relay controlling the fan.\nFor Google Assistant: Similarly, you can create voice commands for each appliance (fan, AC, TV, and light) and map them to Blynk Webhooks.\nExample Applet:\n\nTrigger (Google Assistant): \"Turn on the fan\"\nAction (Webhook): Send an HTTP request to http://blynk-cloud.com/YourBlynkAuthToken/update/D5?value=0 to turn on the fan.\nThis process is repeated for turning on/off each appliance, enabling full control using voice assistants.\n\n5. Conclusion\nThis project demonstrates how the ESP8266 microcontroller can be effectively used to control multiple household appliances (Fan, AC, TV, Room Light) with both automated features and remote control via Blynk. Furthermore, by integrating IFTTT, Alexa, and Google Assistant, it adds a layer of convenience, allowing users to manage their appliances through voice commands.\n\nThe combination of Blynk for remote control and IFTTT for voice assistant integration provides a versatile and user-friendly solution for smart home automation.\n\n\n\n\ncode\n\n// Required Libraries\n#include \u003cESP8266WiFi.h\u003e\n#include \u003cBlynkSimpleEsp8266.h\u003e\n#include \u003cDHT.h\u003e\n\n// Pin Definitions\n#define DHTPIN 2            // DHT sensor connected to GPIO2 (D4 on some boards)\n#define DHTTYPE DHT11       // DHT 11 temperature and humidity sensor\n\n// Relay pins for 4-channel relay module\n#define RELAY_FAN 5         // Fan relay (GPIO5)\n#define RELAY_AC 4          // AC relay (GPIO4)\n#define RELAY_TV 0          // TV relay (GPIO0)\n#define RELAY_LIGHT 2       // Room light relay (GPIO2)\n\n// Initialize DHT sensor\nDHT dht(DHTPIN, DHTTYPE);\n\n// Blynk authentication token\nchar auth[] = \"YourBlynkAuthToken\";  // Replace with your Blynk Auth Token\n\n// Wi-Fi credentials\nchar ssid[] = \"YourWiFiSSID\";        // Replace with your WiFi SSID\nchar pass[] = \"YourWiFiPassword\";    // Replace with your WiFi Password\n\n// Variables to store the states\nbool acState = false;  // Store AC state (on/off)\n\n// Timer to schedule periodic tasks\nBlynkTimer timer;\n\n// Setup function - runs once at the beginning\nvoid setup() {\n  // Initialize serial communication\n  Serial.begin(115200);\n  \n  // Start Blynk with WiFi credentials\n  Blynk.begin(auth, ssid, pass);\n  \n  // Initialize relay pins\n  pinMode(RELAY_FAN, OUTPUT);\n  pinMode(RELAY_AC, OUTPUT);\n  pinMode(RELAY_TV, OUTPUT);\n  pinMode(RELAY_LIGHT, OUTPUT);\n  \n  // Set all relays to OFF initially (high state for inactive)\n  digitalWrite(RELAY_FAN, HIGH);  // Fan OFF\n  digitalWrite(RELAY_AC, HIGH);   // AC OFF\n  digitalWrite(RELAY_TV, HIGH);   // TV OFF\n  digitalWrite(RELAY_LIGHT, HIGH); // Light OFF\n  \n  // Start the DHT sensor\n  dht.begin();\n  \n  // Schedule temperature check every 2 seconds\n  timer.setInterval(2000L, checkConditions);\n}\n\n// Function to control fan speed based on temperature and AC state\nvoid controlFan(float temperature) {\n  // Check if the AC is on\n  if (acState) {\n    // Adjust fan speed based on temperature\n    if (temperature \u003c 24) {\n      Serial.println(\"AC on, temperature below 24°C. Setting fan speed to 3.\");\n      setFanSpeed(3);  // Speed 3\n    } else if (temperature \u003e 26) {\n      Serial.println(\"Temperature above 26°C. Setting fan speed to maximum.\");\n      setFanSpeed(5);  // Maximum speed\n    } else {\n      Serial.println(\"Temperature between 24°C and 26°C. Setting fan to medium.\");\n      setFanSpeed(2);  // Medium speed\n    }\n  } else {\n    Serial.println(\"AC off, turning fan off.\");\n    setFanSpeed(0);  // Turn off fan if AC is off\n  }\n}\n\n// Function to set fan speed based on relay\nvoid setFanSpeed(int speed) {\n  switch (speed) {\n    case 0:  // Fan off\n      digitalWrite(RELAY_FAN, HIGH);  // Deactivate relay\n      break;\n    case 2:  // Medium speed\n    case 3:  // High speed\n    case 5:  // Max speed\n      digitalWrite(RELAY_FAN, LOW);   // Activate relay to turn fan on\n      break;\n  }\n}\n\n// Function to check temperature and adjust fan speed\nvoid checkConditions() {\n  // Read temperature from DHT sensor\n  float temperature = dht.readTemperature();\n  \n  // Check if the temperature reading is valid\n  if (isnan(temperature)) {\n    Serial.println(\"Failed to read temperature from sensor.\");\n    return;\n  }\n  \n  // Print the current temperature\n  Serial.print(\"Current Temperature: \");\n  Serial.println(temperature);\n  \n  // Control fan speed based on the temperature\n  controlFan(temperature);\n}\n\n// Blynk virtual pin handler to control AC (V1)\nBLYNK_WRITE(V1) {\n  acState = param.asInt();  // Read AC state from Blynk app (1 = ON, 0 = OFF)\n  \n  // Turn AC relay on/off\n  digitalWrite(RELAY_AC, acState ? LOW : HIGH);\n  Serial.println(acState ? \"AC turned ON\" : \"AC turned OFF\");\n}\n\n// Blynk virtual pin handler to control TV (V2)\nBLYNK_WRITE(V2) {\n  int tvState = param.asInt();  // Read TV state from Blynk app\n  \n  // Turn TV relay on/off\n  digitalWrite(RELAY_TV, tvState ? LOW : HIGH);\n  Serial.println(tvState ? \"TV turned ON\" : \"TV turned OFF\");\n}\n\n// Blynk virtual pin handler to control Room Light (V3)\nBLYNK_WRITE(V3) {\n  int lightState = param.asInt();  // Read Room Light state from Blynk app\n  \n  // Turn Room Light relay on/off\n  digitalWrite(RELAY_LIGHT, lightState ? LOW : HIGH);\n  Serial.println(lightState ? \"Room Light turned ON\" : \"Room Light turned OFF\");\n}\n\n// Main loop function - runs continuously\nvoid loop() {\n  Blynk.run();  // Run Blynk\n  timer.run();  // Run the timer to check conditions regularly\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandrawat138%2Fsmarthomeautomation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanandrawat138%2Fsmarthomeautomation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanandrawat138%2Fsmarthomeautomation/lists"}