The HC-SR501 driver for motion detection is used in conjunction with the HC-SR501 sensor to detect motion in the sensor’s surroundings. The HC-SR501 detects motion via the use of a PIR motion sensor. The PIR sensor works by detecting changes in infrared radiation that passes through its sensing fields. When a warm body such as a human, animal, or vehicle pass from one side of its sensing field to another a high signal is produced in the PIR sensor signaling motion detection.
The HC-SR501 driver for the HC-SR501 motion sensor has one parameter that needs to be configured:
This is the pin that receives input from the HC-SR501 sensor.
The GP0 pin is connected to Data Pin on the PIR sensor, the 5V and GND pins on the Builder Base are then connected to the VCC and GND pins on the PIR sensor.
GP0 (can be any GP pin)
This pin receives data from the HC-SR501
This pin provides the power
This pin provides the GND
How to write an App
Navigate to the App Builder and create a new application. You can find the “Motion Sensor” code object under the “Hardware” Tab in the object drop down menu on the left, or you can also use the search bar.
Drag the “Motion Sensor” Object onto the canvas.
Next, locate the “Switch” Object under the Interface tab and drag it onto the canvas.
Finally, connect the “Motion Detected” port from the Motion Sensor Object to the “State” port on the Switch object and save your application.
How to create a firmware
Navigate to the Firmware Builder and create a new firmware file.
Click the “+ Add Hardware” button which will open a modal window. Scroll down in the list to find the “sensor” section and select “Motion Sensor”
Give your device a name, and click “Add Device”
Next, select the “HC-SR501” driver under the driver dropdown menu.
For this example we select:
You may now save your firmware file and upload it to one of your clients.