Action: Motion sensor
Next to the output of the moisture sensor, we also need another sensor that recognizes movement in the room. We use the motion sensor for this.
Usage
- The motion sensor is a passive infrared sensor that detects differences in heat radiation within its detection range.
- It responds to anything that moves and emits heat, including your pets 🦖.
Technical Specifications
- Operating Voltage: 4.5 … 20 V
- Output Voltage: 3.3 V high / 0 V low
- Delay Time: 8 s (± 30%)
- Induction Angle: < 100 degrees cone angle
- Detection Range: approximately 3.0 m
Wiring
The motion sensor has 3 pins:
- Negative terminal (represented by a minus sign on the sensor)
- Positive terminal (represented by a plus sign on the sensor)
- Digital Signal (labeled “out” on the sensor)
To connect the pins to your microcontroller, follow these steps:
- Make sure your microcontroller is disconnected from the USB power source before making changes to the circuit
- Connect a cable between the negative pin of the sensor and the G (Ground) pin on the microcontroller.
- Connect a cable between the positive pin of the sensor and the VV pin on the microcontroller.
- Connect a cable between the digital signal pin of the sensor and the D1 pin on the microcontroller.
Programming
Note: If you still have any code in the editor from a previous exercise, feel free to delete it
Here is the corresponding code to display the sensor data in the serial monitor:
void setup()
{
pinMode(D1, INPUT);
Serial.begin(115200);
}
void loop()
{
bool digitalValue = digitalRead(D1);
Serial.println(digitalValue);
delay(1000);
}
The values you see in the serial monitor are 0 or 1. The value 0 means no motion detected, and the value 1 means motion detected. You may also notice a delay in the transition from 1 to 0. It takes approximately seven seconds for the sensor to return to 0 after detecting motion.