Robojax

Arduino code and video for HC-SR505 Motion Sensor Module with relay

دروس آردوینو به فارسی

This is the Arduino code for HC-SR505 Motion Sensor (small) with Relay

This video shows you how to use HC-SR505 Sensor for arduino with Relay and AC bulb. http://robojax.com/learn/arduino/
  1. HC-SR501 Motion Sensor Manual

 /*
 * This is the Arduino code for  HC-SR501 Motions Sensor
 * to tetect motion of human or objects using arduino for robotoic car and other applications
 * Watch HC-SR505 video https://youtu.be/qhThpxiXubI
 *  * 
// Writeen by Ahmad S. for Robojax.com on 
// on Freb 10, 2018 at 11:41 at city of 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.
 * 
 */


#define PIR 2 // define pint 2 for sensor
#define BUZZER 8 // define pin 8 as for buzzer
#define RELAY 9 // define pin 9 as for relay

void setup() {
  // HC-SR505 Motion Sensor Code by Robojax.com 20180210
  Serial.begin(9600);// setup Serial Monitor to display information
  pinMode(PIR, INPUT_PULLUP);// define pin as Input  sensor
  pinMode(BUZZER, OUTPUT);// define pin as OUTPUT for buzzer or LED
  pinMode(RELAY, OUTPUT);// define pin as OUTPUT for relay
}

void loop() {
  // HC-SR505 Motion Sensor Code by Robojax.com 20180210
  int motion =digitalRead(PIR);// read the sensor 
  if(motion){
    Serial.println("Motion detected");
    digitalWrite(BUZZER,HIGH);// turn the buzzer ON
    digitalWrite(RELAY,LOW);// turn the relay ON
  }else{
     Serial.println("===nothing moves");
     digitalWrite(BUZZER,LOW);// keep the buzzer OFF
     digitalWrite(RELAY,HIGH);// turn the relay OFF
  }
  delay(500);
 // HC-SR505 Motion Sensor Code by Robojax.com 20180210
}