You are on page 1of 1

/*

* This is the Arduino code for HC-SR501 Motions


Sensor
* to tetect motion of human or objects using Arduino
for robotic car and other applications
* Watch the video https://youtu.be/mZCJNOf69JI
* *
* Written by Ahmad Shamshiri for Robojax Video
* Date: Dec 27, 2017, in Ajax, Ontario, Canada
* Permission granted to share this code given that
this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational
purpose only.
*
*/

/void setup() {
Serial.begin(9600);// setup Serial Monitor to display
information
pinMode(2, INPUT);// Input from sensor
pinMode(8, OUTPUT);// OUTPUT to alarm or LED
}

void loop() {
int motion =digitalRead(2);
if(motion){
Serial.println("Motion detected");
digitalWrite(8,HIGH);
}else{
Serial.println("===nothing moves");
digitalWrite(8,LOW);
}
delay(500);

You might also like