What is this sensor? It is a PIR Motion Sensor.
PIR =Pyroelectric IR (infrared). Pyroelectrics make voltage when heated or cooled. IR light is really good at changing something's temperature. The white dome is actually a lens that helps focus light coming from all directions in front of it to an IR pyroelectric crystal in the center. The circuit board detects if incoming IR light is rapidly changing at the same wavelengths that people emit by just being warm.
Yes, you emit light, even in the dark! This sensor detects changes in that light. Here is a picture from an IR camera. |
IR light goes through plastics
|
Person in a rain coat IR camera image at night.
The Code and Wiring
Code with comments explaining each part.
Save your code, verify it, and upload to the board.
Test if it is working. Set the sensor down and don't move. Try moving by it and see if your light comes on. Also, open up the Serial Monitor and see if the "motion detected" prints out ever time you move.
Image sources:
https://nitrocdn.com/FamnJWKPilluExxZNRhJjJibvSMjKfnK/assets/static/optimized/rev-7714f53/wp-content/uploads/2017/02/26192329/Best-Thermal-Imaging-IR-Cameras-for-Ghost-Hunting.jpg
https://media.wired.com/photos/5932644eb8eb31692072f207/master/w_2560%2Cc_limit/irimage1.jpg
https://nitrocdn.com/FamnJWKPilluExxZNRhJjJibvSMjKfnK/assets/static/optimized/rev-7714f53/wp-content/uploads/2017/02/26192329/Best-Thermal-Imaging-IR-Cameras-for-Ghost-Hunting.jpg
https://media.wired.com/photos/5932644eb8eb31692072f207/master/w_2560%2Cc_limit/irimage1.jpg