HOW TO USE: HC-SR501
Are you a starter with Croduino? Or a newbie when it comes to electronics? You fancy a specific module, but you don’t know how to use it? Don’t worry, we have our How To Use series!
How to Use is a series of blog tutorials by e-radionica where you will find everything you need to begin working with your favorite modules. Tutorials include technical characteristics, operating principles, instructions on how to connect the module with Croduino and basic coding. Everything else is up to you and your imagination.
HC-SR501, aswell known as PIR (Passive Infrared), Pyroelectric or IR motion sensor, enables motion detection within the sensor’s range. It’s exactly that sensor you can find in lighting at your/ neighbours doorway. The basic part is a pyroelectric sensor that detects the amount of infrared radiation. Each being, objects radiate with a certain amount of radiation. Warmer something is, it radiates more. Therefore, this sensor is mainly used to detect the movements of living beings. Keep in mind that this sensor cannot give you information about the distance on which something is detected. If you need this particular option, check out a HC-SR04 module.
Voltage: DC 4,5 – 20V
Angle: < 120
Distance: 3m – max7m
Lens diameter: 23mm
Dimensions 32 x 24mm
BASIC WORKING PRINCIPLE
As already mentioned, the main part is the pyroelectric sensor that has two slits/halves. If one slit senses more radiation than the other, the sensor will automatically switch from HIGH to LOW, or vice versa. For example, the sensor is enclosed and reads the radiation of walls and other objects in its range. When a warm body passes (human or animal), it affects one half of the sensor that reads the change of radiation in the range. It is opposite when body leaves the range of the sensor. Exactly those changes are registered by the sensor. For more details, check out the datasheet.
Second most important part of the HC-SR501 sensor is its lens. It may vary depending on curvature, width, material, pattern, etc., so most of the magic of this sensor can happen with optics. Everything already mentioned greatly changes the final characteristics of the sensor which opens space for detailed adjustments.
Use the sensor without lens if you want to have a small detection angle(around 15 degrees)
HOW TO CONNECT MODULE WITH CRODUINO
Before you connect modules pins with Croduino, I would draw attention to two potentiometers which are mounted on the module. By adjusting them, the sensitivity (on the board marked “Sx”) and the time of a delay (“Tx”) are adjusted as follows: Turning clockwise to increase sensitivity and prolong the delay, while turning counter-clockwise to reduce sensitivity and to short the delay. This means that you can use the module even without a controller. Be careful, the module gives HIGH in the idle state and gives LOW when movement is detected. For the purpose of this tutorial, the module is tested inside a closed environment and sensitivity potentiometer is set to medium and delay to shortest.
We connect pins as follows:
Vcc – +5V
OUT – digital PIN8
GND – gnd
CODE FOR MODULE
As always, we provide a basic code that puts this module in operation. The output results are read via the Serial Monitor and the Digital PIN 13 (orange led embedded in the Croduino), or if we merged an extra LED as shown in the picture. The following code can be written by you as well. From the tutorials, we know that the sensor has a LOW value at the output pin during reading. Everything else is left to the imagination.
inPin = 9;
// signal from the HC-SR501 on the pin 9
led = 13;
// LED on the pin 13
// when the HC-SR501 is active, it sends LOW signal,
// since HIGH signal will turn one LED on, we will change its value
// the reading is opposite from the state of pin 9
// finally, the led pin's state, we set it according to the reading