Infrared Motion Detector
This week in the Construction of a prototype course we studied different sensors and how they work. My partner and I got an infrared motion detector sensor. The motion detector uses infrared lights to detect movement, when it detects something moving it would return a HIGH value. We used a led with the sensor to indicate when the sensor gave that value.
The sensor had three connectors: GND, V+ and Output. We connected the GND to ground, V+ to a pin which supplied +5v and the output connector to pin 12. After the sensor was ready, we added a led to pin 8, so we could see if the sensor picked up anything.
After the connections were ok we moved on to the code. First we created three variables: int sensor, int ledPin and int movement. The movement variables purpose is to store the values that the sensor gives. After that we moved on to setup. We set the led as OUTPUT and the sensor as INPUT. Then it was time for the last part of the code, creating the loop. The movement variable was set to read the data that the sensor on pin 12 provided and then movement was set as value to digitalwrite with the ledPin variable. Now we could read the sensor and forward the information to the led.
Now it was time to test if everything worked. After the code was inserted to arduino we had to calibrate the sensor. We did this by covering the sensor for 60 seconds so it wouldn’t sense any movement. After the calibration was completed we removed the cover and the sensor started working. Everytime it sensed movement the led would blink. The blinkin changed whether the sensors jumper was set on Normal mode or Retrigger mode. Normal mode give continuously HIGH and LOW pulse which would make the led blink. The Retrigger mode would remain as HIGH value when sensing movement, which means the led would be on the time when sensor picked up movement. In both settings the output would be low when idle.
The code used in project
int sensor = 12;
int ledPin = 8;
int movement = 0;
movement = digitalRead(sensor);
Short video clip showing how the sensor works.