PIR Senesor / Motion Sensor using Arduino
Code
PIR SENSOR / MOTION SENSOR
https://electronicassist.blogspot.in/
ARJUN ARANGIL
9444868542
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int leda = 12; // choose the pin for the LED
int ledb = 11; // choose the pin for the LED
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(leda, OUTPUT); // declare LED as output
pinMode(ledb, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
}
void loop()
{
val = digitalRead(inputPin); // read input value
if (val == HIGH) // check if the input is HIGH
{
digitalWrite(ledPin, HIGH); // turn LED ON
delay(500); // .5sec delay
digitalWrite(leda, HIGH); // turn LED ON
delay(500); // .5sec delay
digitalWrite(ledb, HIGH); // turn LED ON
}
else
{
digitalWrite(ledPin, LOW); // turn LED OFF
digitalWrite(leda, LOW); // turn LED OFF
digitalWrite(ledb, LOW); // turn LED OFF
}
}
Comments
Post a Comment