Back to Step by Step Course by Robojax

Lesson 16, Robojax Arduino Step by Step Course: Motion Sensor

This is the Arduino code this code when motion is detected, will send signal to pin 8 which can be a buzzer or relay


 /*
 * Robojax Arduino Step By Step Course
 * Lesson 16 HC-SR501 Motion Sensor
 * Arduino code for HC-SR501 PIR Motion Sensor
 this code when motion is detected, will send signal to pin 8 which can be a buzzer or relay

  Please watch video instruction here https://youtu.be/piuUfGVafC0
 This code is available at http://robojax.com/course1/?vid=lecture11
 
with over 100 lectures Free On  YouTube Watch it here http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339 

 * on January 16, 2019 at 20:23 in Ajax, Ontario, Canada

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
int pirPin = 2;// input pin from PIR sensor
int alarmPin = 8;// Alarm pin to turn alarm ON
 
void setup() {
	
	//Robojax Arduino Step By Step Course http://robojax.com/L/?id=338
  Serial.begin(9600);// setup Serial Monitor to display information
  pinMode(pirPin, INPUT);// Input from sensor
  pinMode(alarmPin, OUTPUT);// OUTPUT to alarm or LED
}

void loop() {
	//Robojax Arduino Step By Step Course http://robojax.com/L/?id=338	
  int motion =digitalRead(pirPin);// read input pin signal
  if(motion == HIGH){
    Serial.println("Motion detected");
    digitalWrite(alarmPin,HIGH);
  }else{
     Serial.println("===nothing moves");
     digitalWrite(alarmPin,LOW);
  }
  delay(500);

}


   

The least I expect from you is to give the video a thumbs up and subscribe to my channel. I appreciate it. I have spent hundreds of hours making these lectures and writing code. You don't lose anything by subscribing to my channel. Your subscription is a stamp of approval for my videos, helping more people find them and, in turn, helping me. Thank you!

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal

**** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.

Right Side
footer