If motion is detected (pirPin = HIGH), do the following:ĭigitalWrite(ledPin, HIGH) // Turn on the on-board LED. Begin serial communication at a baud rate of 9600: Configure the pins as input or output: More info: */īool motionState = false // We start with no motion detected. * Example code for HC-SR501 PIR motion sensor with Arduino. is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on. The main difference is that these cheaper sensors have a smaller detection range and don’t have a potentiometer to adjust the sensitivity and time delay. ![]() This tutorial focuses on the HC-SR501 sensor, but you can also use the provided code for similar sensors like the HC-SR505 or AM312. Next, we will connect it to an Arduino UNO and I will show you how to use it as a simple alarm system. After each example, I break down and explain how the code works, so you should have no problems modifying it to suit your needs.įirst I will show you how you can use the HC-SR501 as a standalone unit. In this article, I have included a wiring diagram and example codes so you can start experimenting with your sensor. ![]() You can find Passive Infrared (PIR) sensors all around you, they are not only used for security purposes, but also in most automatically-activated lighting systems. In this tutorial, you will learn how the HC-SR501 PIR motion sensor works and how you can use it with Arduino.
0 Comments
Leave a Reply. |