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
 This code is available at
with over 100 lectures Free On  YouTube Watch it here
Get the code for the course: 

 * 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
    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 <>.
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
  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	
  int motion =digitalRead(pirPin);// read input pin signal
  if(motion == HIGH){
    Serial.println("Motion detected");
     Serial.println("===nothing moves");



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 and affiliated sites.

Right Side