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

Solar-Powered Wi-Fi Current Sensing Relay Control System

View and Edit Project In Cirkit DesignerImage of Solar-Powered Wi-Fi Current Sensing Relay Control System

Circuit Documentation

Summary of the Circuit

This circuit is designed to harness solar power to charge a 2000mAh battery and provide a regulated 5V output to power an ESP8266 microcontroller and a relay module. The ESP8266 reads the output from an ACS712 current sensor and controls the relay based on the current detected. The system is capable of connecting to a WiFi network and sending signals to a server when the current threshold is exceeded.

Component List

Solar Panel

LM7805 Voltage Regulator

Charge Controller

ACS712 Current Sensor

2000mAh Battery

ESP8266 Microcontroller

Relay Module

Alligator Clip Cables (Blue, Red, Yellow)

Wiring Details

Solar Panel

LM7805 Voltage Regulator

Charge Controller

ACS712 Current Sensor

2000mAh Battery

ESP8266 Microcontroller

Relay Module

Documented Code

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

const int currentSensorPin = A0; // Analog pin connected to current sensor
const int relayPin = D1;         // Digital pin connected to relay module
const int threshold = 512;       // Threshold value for current detection

const char* ssid = "your_SSID";
const char* password = "12345678";
const char* serverUrl = "http://your_server/turn_off_switch";

void setup() {
  pinMode(currentSensorPin, INPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); // Ensure relay is off initially

  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  int sensorValue = analogRead(currentSensorPin);
  Serial.println(sensorValue);

  if (sensorValue > threshold) {
    // Current detected at the first naked wire
    digitalWrite(relayPin, HIGH); // Turn on the relay (or off, depending on your relay type)
    sendSignalToServer();
  } else {
    digitalWrite(relayPin, LOW); // Ensure relay is off
  }

  delay(1000); // Adjust delay as needed
}

void sendSignalToServer() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin(serverUrl);
    int httpCode = http.GET();

    if (httpCode > 0) {
      String payload = http.getString();
      Serial.println(payload);
    } else {
      Serial.println("Error in sending signal");
    }
    http.end();
  }
}

This code is designed to run on the ESP8266 microcontroller. It initializes the WiFi connection, reads the current sensor value, and controls the relay based on the current threshold. If the current exceeds the threshold, it sends a signal to a server.