The code to activate an LED using a motion sensor is relatively straightforward.
The circuitry for this project will be fairly simple, but you’ll learn how to add a motion sensor to any project in the future. You’ll also need a USB cable if you haven’t got one lying around. Place a resistor from your kit between the output pin and the LED. Most LEDs will burn out if you connect them directly to the 5V output of an Arduino. With that in mind, here are the parts you’ll need: Arduino Uno
To demonstrate how the sensor works, we’ll be using it to control a simple LED. Most of the components for this project can be found in starter electronics parts kits. However, we’ll be focusing on a straightforward PIR sensor to keep things simple for this project. Some more advanced PIR sensors like the HC-SR501 have extra modules that allow you to adjust the sensitivity and trigger modes of the sensor. There are no varying levels in between-the sensor can’t tell the difference between someone slowly walking by, versus a fast movement, for example-but it’s more than enough to work for most projects. When no motion is detected, it returns LOW (or 0). When the sensor detects movement, the signal pin returns HIGH (or 1). One ground, one power, and a third signal pin. Since this kind of infrared light is visible to the sensor even when it’s too dark for human eyes to see, they make excellent components for security or safety systems. This sensor works by detecting infrared light, like the kind human bodies give off in the form of heat. However, with an inexpensive motion sensor, you can build your own motion-activated light-or any other motion-activated device-with an Arduino.įor this project, we’ll be using a Passive InfraRed (or PIR) motion sensor. Hardware stores often sell motion-activated floodlights that you can mount outside your house to turn on whenever someone walks through your yard.