Motion sensing night light by SteveOst 3d model
3dmdb logo
Thingiverse
Motion sensing night light by SteveOst

Motion sensing night light by SteveOst

by Thingiverse
Last crawled date: 2 years, 11 months ago
Motion sensing night light to light of bathroom
Arduino code:
//basic night light
// A0 pin for LDR
// A1 pin for motion sensor
// LED1 led output on pin 9
// LED2 led output on pin 10
int LED1 = 9;
int LED2 = 10;
void setup () {
// set up I/O
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
// for serial monitor - watch LRD and motion sensor values
Serial.begin(9600);
}
void loop(){
// read sensors
int lightValue = analogRead(A0);
int motionValue = analogRead(A1);
// set lights to off,for start up and after lights are turned on
// with motion
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
Serial.println("light");
Serial.print(lightValue);
// if it is dark then look for motion
if(lightValue>50)
{
// look for motion
if(motionValue>100)
{
// if motion, then turn on lights
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
delay(120000);
}
else
{
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
}
Serial.println("motion");
Serial.print(motionValue);
}
else
{
delay(300);

Tags