Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP8266 IoT Fan Controller with Power Monitoring

View and Edit Project In Cirkit DesignerImage of ESP8266 IoT Fan Controller with Power Monitoring

IoT Fan Project Documentation

Summary

This project involves an IoT-enabled fan control system using an ESP8266 NodeMCU microcontroller. The system controls a fan through a relay module and monitors power consumption using a PZEM004T power meter. The fan can be turned on or off via the relay, and power consumption data is read from the PZEM004T and can be sent to a server or displayed.

Component List

  1. ESP8266 NodeMCU

    • Description: A low-cost Wi-Fi microcontroller with GPIO, ADC, and UART capabilities.
    • Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN
  2. Fan

    • Description: A simple DC fan.
    • Pins: GND, 5V
  3. PZEM004T

    • Description: A power meter module for measuring voltage, current, power, and energy.
    • Pins: VCC, RX, TX, GND, IN, OUT
  4. Power Supply

    • Description: Provides power to the circuit.
    • Pins: +, -
  5. 5V Relay

    • Description: A relay module for switching the fan on and off.
    • Pins: Normally Open, Common terminal, Normally Closed, In, GND, VCC

Wiring Details

ESP8266 NodeMCU

Fan

PZEM004T

Power Supply

5V Relay

Code Documentation

ESP8266 NodeMCU Code

/*
 * IoT Fan Project
 * This Arduino sketch is for an ESP8266 microcontroller. It controls a fan
 * through a relay module and monitors power consumption using a PZEM004T
 * power meter. The fan can be turned on or off via the relay, and power
 * consumption data is read from the PZEM004T and can be sent to a server
 * or displayed.
 */

#include <SoftwareSerial.h>

// Pin definitions
const int relayPin = D7; // Relay trigger pin
const int rxPin = RX;    // RX pin for PZEM004T
const int txPin = TX;    // TX pin for PZEM004T

// Create a SoftwareSerial object for PZEM004T communication
SoftwareSerial pzemSerial(rxPin, txPin);

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
  pzemSerial.begin(9600);

  // Initialize relay pin
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); // Ensure the relay is off initially

  // Print a startup message
  Serial.println("IoT Fan Project Initialized");
}

void loop() {
  // Example: Turn the fan on for 5 seconds, then off for 5 seconds
  digitalWrite(relayPin, HIGH); // Turn the relay on (fan on)
  delay(5000);                  // Wait for 5 seconds
  digitalWrite(relayPin, LOW);  // Turn the relay off (fan off)
  delay(5000);                  // Wait for 5 seconds

  // Read power consumption data from PZEM004T
  if (pzemSerial.available()) {
    String pzemData = pzemSerial.readStringUntil('\n');
    Serial.println("Power Data: " + pzemData);
  }
}

Fan Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

This documentation provides a comprehensive overview of the IoT Fan Project, including a summary, detailed component list, wiring details, and documented code.