SMARTHOME !! Project IOT/ Internet of Things rumah pintar dengan Nodemcu ESP8266 by TOKOTRONIK

3 min read 2 months ago
Published on Oct 08, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through creating a smart home project using the NodeMCU ESP8266, a popular microcontroller for IoT applications. You will learn how to connect various sensors and actuators, and control them through the Blynk app on your Android device. This project combines elements of Internet of Things (IoT) technology with practical home automation.

Step 1: Gather Required Components

Before starting, make sure you have all the necessary components:

  • NodeMCU ESP8266
  • MQ-2 gas sensor
  • DHT11 temperature and humidity sensor
  • Magnetic sensor
  • Various actuators (e.g., relays for controlling appliances)
  • Jumper wires
  • Breadboard
  • Power supply
  • Android device with the Blynk app installed

Step 2: Set Up the NodeMCU

  1. Install the Arduino IDE if you haven't already.
  2. Add the ESP8266 Board to the Arduino IDE:
    • Go to File > Preferences and add the following URL to the "Additional Boards Manager URLs":
      http://arduino.esp8266.com/stable/package_esp8266com_index.json
      
    • Navigate to Tools > Board > Boards Manager, search for "ESP8266," and install it.
  3. Select the NodeMCU board from Tools > Board.

Step 3: Wiring the Components

  1. Connect the DHT11 Sensor:

    • VCC to NodeMCU 3.3V
    • GND to NodeMCU GND
    • Data pin to a digital pin (e.g., D4)
  2. Connect the MQ-2 Gas Sensor:

    • VCC to NodeMCU 5V
    • GND to NodeMCU GND
    • Signal pin to an analog pin (e.g., A0)
  3. Connect the Magnetic Sensor:

    • VCC to NodeMCU 3.3V
    • GND to NodeMCU GND
    • Output pin to a digital pin (e.g., D2)
  4. Connect Actuators:

    • Connect actuators (like relays) according to their specifications to control devices.

Step 4: Program the NodeMCU

  1. Install the Blynk Library:

    • In the Arduino IDE, go to Sketch > Include Library > Manage Libraries and search for "Blynk" to install it.
  2. Create a Blynk Project:

    • Open the Blynk app and create a new project.
    • Choose the NodeMCU ESP8266 as the device and set a connection type (Wi-Fi).
    • You will receive an Auth Token via email; keep this for the next steps.
  3. Write the Code:

    • Use the following code snippet as a starting point:
    #define BLYNK_PRINT Serial
    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    #include <DHT.h>
    
    char auth[] = "YOUR_AUTH_TOKEN"; // Replace with your Auth Token
    char ssid[] = "YOUR_SSID"; // Replace with your Wi-Fi SSID
    char pass[] = "YOUR_PASSWORD"; // Replace with your Wi-Fi Password
    
    DHT dht(D4, DHT11);
    
    void setup() {
        Serial.begin(115200);
        Blynk.begin(auth, ssid, pass);
        dht.begin();
    }
    
    void loop() {
        Blynk.run();
        // Your code for sensors and actuators goes here
    }
    
  4. Upload the Code to the NodeMCU.

Step 5: Configure Blynk App

  1. Add Widgets:

    • Add a value display for temperature and humidity.
    • Add buttons to control actuators.
  2. Link Widgets to Virtual Pins:

    • Assign virtual pins in the Blynk app that correspond to the pins in your code.

Step 6: Testing

  1. Power on the NodeMCU and make sure it connects to Wi-Fi.
  2. Open the Blynk app:
    • Check if the temperature and humidity readings appear.
    • Test the buttons to control the actuators.

Conclusion

You have successfully set up a smart home project using NodeMCU ESP8266 and various sensors. You can now monitor environmental conditions and control home appliances remotely using the Blynk app. For further enhancements, consider adding more sensors or features like notifications for gas leaks or temperature thresholds. Happy tinkering!