This Arduino program integrates with PIR (Passive Infrared) motion sensors...
September 3, 2025 at 02:12 PM
This Arduino program integrates with PIR (Passive Infrared) motion sensors and two servo motors to monitor and respond to motion detection in four directions: North, East, South, and West. Here's what the code does:
-
Hardware Setup:
- PIR Sensors: Four PIR sensors are connected to digital pins
2
,3
,4
, and5
corresponding to North, East, South, and West directions. - Servos: Two servo motors (
camA
andcamB
) are controlled via pins9
and10
. These servos are responsible for moving towards detected motion.
- PIR Sensors: Four PIR sensors are connected to digital pins
-
Predefined Angles:
- The servos are set to move to specific angles depending on the motion direction (
angleNorth
,angleEast
,angleSouth
,angleWest
). - Default positions for the servos are specified (
defaultAngleA
anddefaultAngleB
, both set to 90 degrees).
- The servos are set to move to specific angles depending on the motion direction (
-
Motion Detection and Servo Response:
- In the
loop
function, the program continuously checks for motion signals from the PIR sensors. - When motion is detected in a specific direction:
- It prints a message to the
Serial
monitor about the motion direction. - The corresponding servo (
camA
orcamB
) is moved to the predefined angle for that direction. - The timestamp of detection is updated using
millis()
.
- It prints a message to the
- In the
-
Timeout for Reset:
- If no motion is detected for a specified timeout (
detectionTimeout
, set to 5 seconds), the servos return to their default positions.
- If no motion is detected for a specified timeout (
-
Behavior:
- Upon motion detection, a servo will point towards the respective direction.
- If no further motion occurs after the timeout duration, the cameras will reset to face their default positions.
Summary:
The code is a motion-tracking system using PIR sensors and servos. It detects motion from four directions, rotates servos to point towards the detected direction, and resets to a default position if no motion is detected for 5 seconds. It can be used for applications such as security cameras or motion-tracking systems.
Generate your own explanations
Download our vscode extension
Read other generated explanations
Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node