Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The HC-SR505 is a passive infrared (PIR) motion sensor that detects motion in its field of view. Here's an example code in Arduino that reads the motion detection status from the sensor:
- Note: This code assumes that the HC-SR505 PIR motion sensor is connected to pin 2 of the Arduino board. If you're using a different pin, you'll need to modify the SENSOR_PIN definition accordingly. Also, note that the HC-SR505 is a digital sensor that outputs a high signal when motion is detected and a low signal when no motion is detected, so it can be read directly using the digitalRead() function. Finally, note that the HC-SR505 has a limited detection range and may not detect motion outside of its field of view.
- */
- const int SENSOR_PIN = 2; // the pin connected to the sensor
- int motion_detected = 0; // 1 if motion detected, 0 otherwise
- void setup() {
- Serial.begin(9600);
- pinMode(SENSOR_PIN, INPUT);
- }
- void loop() {
- // read the motion detection status from the sensor
- motion_detected = digitalRead(SENSOR_PIN);
- // print the motion detection status
- if (motion_detected) {
- Serial.println("Motion Detected");
- } else {
- Serial.println("No Motion Detected");
- }
- // delay before reading from the sensor again
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement