LIMPINGLIM
Published © GPL3+

Sensor-Controlled Guard Lights

Customised solar-powered & sensor-controlled guard lights to brighten up my apartment balcony that somehow does not have any lights fitted.

BeginnerShowcase (no instructions)5,378
Sensor-Controlled Guard Lights

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
RobotGeek Light Sensor
RobotGeek Light Sensor
×1
Grove - mini PIR motion sensor
Seeed Studio Grove - mini PIR motion sensor
×1
5V LED strip (Warm White)
×1
Portable USB battery pack
×2
Solar Panel - 145x145mm (with USB outlet)
×10
MOSFET module
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Portable drill and bits

Story

Read more

Schematics

Proof-of-Concept setup

Code

Final version of code

Arduino
Code was developed with a UNO board and ported over to a NANO for final setup. Serial monitor communication has been left in the code to guide understanding of the code and for anyone who wishes to refine it for your own projects.
int Light = 5;            // pin for LED
int PIRpower = 13;        // power to PIR sensor
int PIR = 12;             // input from PIR sensor
int PIRState = LOW;       // status of PIR
int LDR = 2;              // input from LDR
int LDRpower = 3;         // power to LDR sensor
int LDRState = LOW;       // status of LDR

void Night()
{
  digitalWrite(PIRpower, HIGH);   // power ON PIR sensor
  delay(2000);
  Serial.println("A. PIR sensor ON, detecting motion");
  delay(3000);                    // wait
  PIRState = digitalRead(PIR);    // read PIR sensor
  delay(500);
  Serial.println("B. Motion sensor read, switching PIR OFF");
  digitalWrite(PIRpower, LOW);
  delay(500);
  if (PIRState == HIGH){
    Serial.println(">>>>>>>>>> MOTION DETECTED");
    delay(500);
    Serial.println("I. switching Light ON");
    delay(500);
    digitalWrite(Light, HIGH);
    Serial.println("II. Light 100%");
    delay(15000);                                  //wait 15sec
    analogWrite(Light, 175);
    Serial.println("II. Light 70%");
    delay(15000);                                  //wait 15sec
    analogWrite(Light, 100);
    Serial.println("II. Light 40%");
    delay(15000);                                  //wait 15sec
    analogWrite(Light, 50);
    Serial.println("II. Light 20%");
    delay(500);                                 
    Serial.println(".......... Wait 5 seconds..........");
    delay(1000);                                  
    }else {
      Serial.println(">>>>>>>>>> MOTION NOT DETECTED"); // We only want to print on the output change, not state
      delay(500);
      Serial.println(".......... Wait 10 seconds..........");
      delay(10000);                                  //wait 10sec
      }
}

void setup() {
  pinMode(Light, OUTPUT);         // declare LED as output
  pinMode(PIRpower, OUTPUT);      // declare PIRpower as output
  pinMode(LDRpower, OUTPUT);      // declare LDRpower as output
  pinMode(LDR, INPUT);            // declare LDR sensor as input
  pinMode(PIR, INPUT);            // declare PIR sensor as input
  digitalWrite(PIRpower, LOW);
  digitalWrite(LDRpower, LOW);
  Serial.begin(9600);
}
 
void loop(){
  Serial.println(".......... START..........");              
  digitalWrite(LDRpower, HIGH);
  Serial.println("1. LDRpower ON, reading LDR sensor");
  delay(3000);
  LDRState = digitalRead(LDR);
  delay(500);
  Serial.println("2. LDR status read, turning LDRpower OFF");
  delay(500);
  Serial.println("3. LDRpower OFF");
  digitalWrite(LDRpower, LOW);
  delay(500);
  if (LDRState == HIGH){                // read status of LDR (Day or Night)
    Serial.println(">>>>>>>>>> DARKNESS DETECTED");
    delay(500);
    Serial.println("Switch ON Light 20%");
    analogWrite(Light, 50);
    Night();
    Serial.println(".......... Restarting..........");
    } else{
    Serial.println(">>>>>>>>>> BRIGHTNESS DETECTED");
    delay(500);
    digitalWrite(Light, LOW);
    Serial.println(".......... Waiting 5mins..........");
    delay(60000);                                             //wait 1 minute
    Serial.println(".......... Waiting 4mins..........");
    delay(60000);                                             //wait 1 minute
    Serial.println(".......... Waiting 3mins..........");
    delay(60000);                                             //wait 1 minute
    Serial.println(".......... Waiting 2mins..........");
    delay(60000);                                             //wait 1 minute
    Serial.println(".......... Waiting 1mins..........");
    delay(60000);                                             //wait 1 minute
    Serial.println(".......... Restarting..........");
    }
}

Credits

LIMPINGLIM

LIMPINGLIM

2 projects • 28 followers

Comments