Automatic
Light using IR Sensor
Things
Required:
·
IR (Infrared) Sensor
·
5V Relay Module
·
Arduino (Uno or Nano)
·
Jumper Wires
Connections:
Code
for Arduino:
int pbutton=8;
int led=3;
int val=0;
int ledon=0;
int pushed=0;
void setup()
{
Serial.begin(9600);
pinMode(pbutton, INPUT_PULLUP);
pinMode(led, OUTPUT);
}
void loop()
{
val=digitalRead(pbutton);
if(val==HIGH && ledon==LOW)
{
pushed=1-pushed;
delay(100);
}
ledon=val;
if(pushed==HIGH)
{
Serial.println("led on");
digitalWrite(led, LOW);
}
else
{
Serial.println("led off");
digitalWrite(led, HIGH);
}
}
If you are facing a problem
making this, contact me at rizwanmahad606@gmail.com
Stay tuned.
Bye.
No comments:
Post a Comment