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

Arduino and ESP8266 Wi-Fi Controlled Smart Street Light with Motion Detection and LDR

View and Edit Project In Cirkit DesignerImage of Arduino and ESP8266 Wi-Fi Controlled Smart Street Light with Motion Detection and LDR

Smart Street Light Circuit Documentation

Summary

The Smart Street Light circuit is designed to control a street light automatically based on the time of day and ambient light conditions. The system uses an Arduino UNO as the main controller, interfaced with a DS3231 Real-Time Clock (RTC) for timekeeping, an LDR (Light Dependent Resistor) for ambient light sensing, an HC-SR501 Motion Sensor for detecting movement, a 12V Relay to control the light, an ESP8266 ESP-12E WiFi Module for network connectivity, and a Current Sensor to monitor the electrical current for fault detection. The circuit also includes a 16x2 LCD Display for user interface, a potentiometer for adjusting the display contrast, and an LED as an indicator. The system operates the street light at full brightness from 7 PM to 11 PM, at 50% brightness from 11 PM to 5 AM, and returns to full brightness if motion is detected during the reduced brightness period. Notifications are sent out if a fault is detected.

Component List

Arduino UNO

DS3231 RTC

LDR

HC-SR501 Motion Sensor

12V Relay

LCD Display 16x2

ESP8266 ESP-12E WiFi Module

Current Sensor 5A

12V Power Supply

Potentiometer

LED (Red)

Resistor (200 Ohms)

Wiring Details

Arduino UNO

DS3231 RTC

LDR

HC-SR501 Motion Sensor

12V Relay

LCD Display 16x2

ESP8266 ESP-12E WiFi Module

Current Sensor 5A

Potentiometer

LED (Red)

Resistor (200 Ohms)

Documented Code

/*
 * Smart Street Light with Arduino
 * This code controls a street light to automatically turn on at 7 PM or when
 * it is dark. The light operates at 100% brightness until 11 PM, then reduces
 * to 50% brightness until 5 AM. If motion is detected between 11 PM and 5 AM,
 * the light returns to 100% brightness. Notifications are sent if a fault is
 * detected, and the light can be controlled via a mobile app.
 */

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

#define LIGHT_PIN 8
#define MOTION_PIN 6
#define LDR_PIN A0
#define CURRENT_SENSOR_PIN A1

RTC_DS3231 rtc;

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

void setup() {
  pinMode(LIGHT_PIN, OUTPUT);
  pinMode(MOTION_PIN, INPUT);
  pinMode(LDR_PIN, INPUT);
  pinMode(CURRENT_SENSOR_PIN, INPUT);
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  DateTime now = rtc.now();
  int ldrValue = analogRead(LDR_PIN);
  int motionDetected = digitalRead(MOTION_PIN);
  int currentSensorValue = analogRead(CURRENT_SENSOR_PIN);

  if (now.hour() >= 19 || ldrValue < 500) {
    if (now.hour() >= 23 && now.hour() < 5) {
      if (motionDetected) {
        analogWrite(LIGHT_PIN, 255); // 100% brightness
      } else {
        analogWrite(LIGHT_PIN, 128); // 50% brightness
      }
    } else {
      analogWrite(LIGHT_PIN, 255); // 100% brightness
    }
  } else {
    analogWrite(LIGHT_PIN, 0); // Light off
  }

  if (currentSensorValue < 100) { // Fault detected
    sendNotification();
  }

  delay(1000);
}

void sendNotification() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin(serverName);
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    int httpResponseCode = http.POST("fault=detected");
    if (httpResponseCode > 0) {
      String response = http.getString();
      Serial.println(httpResponseCode);
      Serial.println(response);
    } else {
      Serial.print("Error on sending POST: ");
      Serial.println(httpResponseCode);
    }
    http.end();
  } else {
    Serial.println("WiFi Disconnected");
  }
}

This code is responsible for the logic that controls the street light based on the time and ambient conditions, as well as for sending notifications in case of a fault. It uses the Arduino UNO's built-in PWM capability to control the brightness of the light and the ESP8266 module for WiFi connectivity.