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

Arduino UNO-Based Smart Lighting System with Motion Detection and Energy Monitoring

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Smart Lighting System with Motion Detection and Energy Monitoring

Circuit Documentation

Summary

This circuit is designed to monitor environmental parameters such as light intensity and motion, and control lighting based on these parameters. It uses an Arduino UNO as the central microcontroller to process sensor data and manage the connected devices. The circuit includes a light-dependent resistor (LDR) for light sensing, two HC-SR501 motion sensors for motion detection, a 2-channel relay module for controlling external loads, an LCD display for outputting sensor readings and system status, a current sensor, and a voltage sensor for monitoring electrical parameters. The system is also capable of interfacing with the Blynk platform for remote monitoring and control.

Component List

Wiring Details

Arduino UNO

12v Power Supply

HC-SR501 Motion Sensor

LDR

2-Channel Relay Module

LCD Display 20x4

Current Sensor

Voltage Sensor

Documented Code

#include <LiquidCrystal.h>
#include <BlynkSimpleEsp8266.h>

#define LDR_PIN A0
#define PIR1_PIN 2
#define PIR2_PIN 3
#define LIGHT_PIN1 4
#define LIGHT_PIN2 5
#define CURRENT_SENSOR_PIN A1
#define VOLTAGE_SENSOR_PIN A2

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
char auth[] = "YourBlynkAuthToken";
char ssid[] = "YourWiFiSSID";
char pass[] = "YourWiFiPassword";

bool lightOn = false;
unsigned long lastMotionTime = 0;
unsigned long lightOnTime = 0;
const int threshold = 500; // Adjust this threshold based on your LDR readings

void setup() {
  pinMode(LDR_PIN, INPUT);
  pinMode(PIR1_PIN, INPUT);
  pinMode(PIR2_PIN, INPUT);
  pinMode(LIGHT_PIN1, OUTPUT);
  pinMode(LIGHT_PIN2, OUTPUT);
  lcd.begin(16, 2);
  Blynk.begin(auth, ssid, pass);
  Serial.begin(9600);
}

void loop() {
  Blynk.run();
  int ldrValue = analogRead(LDR_PIN);
  int current = analogRead(CURRENT_SENSOR_PIN);
  int voltage = analogRead(VOLTAGE_SENSOR_PIN);
  
  lcd.setCursor(0, 0);
  lcd.print("V: ");
  lcd.print(voltage);
  lcd.print(" I: ");
  lcd.print(current);
  
  if (ldrValue < threshold) {
    if (!lightOn) {
      analogWrite(LIGHT_PIN1, 255); // 100% brightness
      analogWrite(LIGHT_PIN2, 255); // 100% brightness
      lightOn = true;
      lightOnTime = millis();
    }
  } else {
    if (lightOn) {
      analogWrite(LIGHT_PIN1, 0); // Turn off
      analogWrite(LIGHT_PIN2, 0); // Turn off
      lightOn = false;
    }
  }
  
  if (lightOn && millis() - lightOnTime > 300000) { // After 5 minutes
    analogWrite(LIGHT_PIN1, 128); // 50% brightness
    analogWrite(LIGHT_PIN2, 128); // 50% brightness
  }
  
  if (digitalRead(PIR1_PIN) == HIGH || digitalRead(PIR2_PIN) == HIGH) {
    analogWrite(LIGHT_PIN1, 255); // 100% brightness
    analogWrite(LIGHT_PIN2, 255); // 100% brightness
    lastMotionTime = millis();
  }
  
  if (millis() - lastMotionTime > 20000 && lightOn && millis() - lightOnTime > 300000) { // After 20 seconds and 5 minutes
    analogWrite(LIGHT_PIN1, 128); // 50% brightness
    analogWrite(LIGHT_PIN2, 128); // 50% brightness
  }
  
  Blynk.virtualWrite(V1, voltage);
  Blynk.virtualWrite(V2, current);
}

BLYNK_WRITE(V0) {
  int pinValue = param.asInt();
  if (pinValue == 1) {
    analogWrite(LIGHT_PIN1, 255); // 100% brightness
    analogWrite(LIGHT_PIN2, 255); // 100% brightness
  } else {
    analogWrite(LIGHT_PIN1, 0); // Turn off
    analogWrite(LIGHT_PIN2, 0); // Turn off
  }
}

This code is designed to run on the Arduino UNO microcontroller. It initializes the connected sensors and LCD display, then enters a loop where it reads sensor values, updates the display, and controls the relay module based on the sensor inputs. It also includes Blynk library calls for remote monitoring and control.