Motion Detection using Arduino:
int ledPin = 13; // for the LED
int inputPin = 2; // input pin
int pirState = LOW;
int val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
if (pirState == LOW) {
Serial.println("Motion detected");
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW);
if (pirState == HIGH){
Serial.println("Motion ended");
pirState = LOW;
}
}
}
0 comments:
Post a Comment
if you have any doubt please let me know