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

ESP8266 Solar-Powered Smart Light with IoT Monitoring

View and Edit Project In Cirkit DesignerImage of ESP8266 Solar-Powered Smart Light with IoT Monitoring

Energy Tracking System Documentation

Summary

This Energy Tracking System uses a solar panel to charge a battery during the day and powers an AC bulb at night. The system status, including charging state and battery life, is sent to an IoT application. The bulb is controlled based on the light level detected by a Light Dependent Resistor (LDR). The system is built around an ESP8266 NodeMCU microcontroller.

Component List

  1. ESP8266 NodeMCU

    • Description: A low-cost Wi-Fi microcontroller with GPIO, ADC, and PWM 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. TP4056 Battery Charging Protection Module (Type C)

    • Description: A module for charging and protecting LiPo batteries.
    • Pins: OUT +, B+, B-, OUT -, +, -
  3. Solar Panel

    • Description: A device that converts sunlight into electrical energy.
    • Pins: +, -
  4. 5V Relay

    • Description: An electromechanical switch used to control high voltage devices.
    • Pins: Normally Open, Common terminal, Normally Closed, In, GND, VCC
  5. AC Bulb

    • Description: A standard AC-powered light bulb.
    • Pins: P, N
  6. Photocell (LDR)

    • Description: A light-dependent resistor that changes resistance based on light levels.
    • Pins: pin 0, pin 1
  7. Resistor (10k Ohms)

    • Description: A resistor with a resistance of 10,000 Ohms.
    • Pins: pin1, pin2
  8. Resistor (20k Ohms)

    • Description: A resistor with a resistance of 20,000 Ohms.
    • Pins: pin1, pin2
  9. LiPo Battery

    • Description: A rechargeable lithium polymer battery.
    • Pins: VCC, GND

Wiring Details

ESP8266 NodeMCU

TP4056 Battery Charging Protection Module (Type C)

Solar Panel

5V Relay

AC Bulb

Photocell (LDR)

Resistor (10k Ohms)

Resistor (20k Ohms)

LiPo Battery

Code Documentation

/*
 * Energy Tracking System
 * This system uses a solar panel to charge a battery during the day and powers
 * an AC bulb at night. The system status, including charging state and battery
 * life, is sent to an IoT application. The bulb is controlled based on the
 * light level detected by an LDR.
 */

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const char* serverName = "http://your_server.com/update";

#define LDR_PIN D1
#define RELAY_PIN D0
#define BATTERY_PIN A0

void setup() {
  Serial.begin(115200);
  pinMode(LDR_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  int ldrValue = analogRead(LDR_PIN);
  int batteryValue = analogRead(BATTERY_PIN);
  bool isCharging = digitalRead(VIN) > 0;
  bool isNight = ldrValue < 500;
  digitalWrite(RELAY_PIN, isNight ? HIGH : LOW);
  sendDataToServer(isCharging, batteryValue, isNight);
  delay(60000); // Update every minute
}

void sendDataToServer(bool isCharging, int batteryValue, bool isNight) {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String serverPath = serverName + "?charging=" + (isCharging ? "1" : "0") +
                       "&battery=" + String(batteryValue) +
                       "&light=" + (isNight ? "1" : "0");
    http.begin(serverPath.c_str());
    int httpResponseCode = http.GET();
    if (httpResponseCode > 0) {
      String response = http.getString();
      Serial.println(httpResponseCode);
      Serial.println(response);
    } else {
      Serial.print("Error on sending GET: ");
      Serial.println(httpResponseCode);
    }
    http.end();
  } else {
    Serial.println("WiFi Disconnected");
  }
}

This code initializes the ESP8266 NodeMCU, connects it to a Wi-Fi network, and reads values from the LDR and battery. It controls the relay based on the light level and sends the system status to a server every minute.