Jazlyn Ortiz
Published

Automatic Dog Lightswitch

Create an automatic light switch when your dog enters the room at night and no other light is present.

IntermediateFull instructions provided38
Automatic Dog Lightswitch

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Photon 2
Particle Photon 2
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Story

Read more

Schematics

Circut

Code

Code

C/C++
Servo Servo; 

int motionSensorPin = D16; 

int servoPin = D1;

int ldrPin = A0;

int motion = LOW; 

void setup() {
    
    pinMode(motionSensorPin, INPUT);
    
    Servo.attach(servoPin);
    Servo.write(0);
    
    Serial.begin(9600);
    
    Time.zone(-6);
}

void loop() {
   
    motion = digitalRead(motionSensorPin);
    
    int ldrValue = analogRead(ldrPin);
    
    int currentHour = Time.hour();
    
    
    if (ldrValue < 450 && currentHour >= 16 && motion == HIGH)
    {
      Servo.write(180);  
      delay(50);  
    }
}

Credits

Jazlyn Ortiz
2 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.