Arduino - Motion Sensor - LED Strip
In this tutorial, we'll explore the implementation of an Arduino, an HC-SR501 motion sensor, and an LED strip to craft a seamless lighting automation system. Specifically designed to activate the LED strip upon detecting human presence, this system is versatile and ideal for various applications, such as:
- Installing the system on stairs to enable automatic lighting as humans approach.
- Placing the system under your bed, where the light will be triggered as you step down from the bed to the floor.
- Creating automatic illumination for a Christmas tree when humans are present.
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
About LED Strip and Motion Sensor
If you do not know about LED strip and motion sensor (pinout, how it works, how to program ...), learn about them in the following tutorials:
You have the flexibility to use either NeoPixel, WS2812B, or DotStar LED Strips. For the sake of simplicity in wiring, this tutorial specifically uses the DotStar LED Strip. Adapting the code for other LED strip types is straightforward, simply refer to the tutorials above for guidance.
This image is created using Fritzing. Click to enlarge image
|Time Delay Adjuster
|Screw it in anti-clockwise direction fully.
|Detection Range Adjuster
|Screw it in clockwise direction fully.
|Repeat Trigger Selector
|Put jumper as shown on the image.
Arduino Code - Motion Sensor Controls LED strip
- Connect Arduino to PC via USB cable
- Open Arduino IDE, select the right board and port
- Navigate to the Libraries icon on the left bar of the Arduino IDE.
- Search “Adafruit DotStar”, then find the DotStar library by Adafruit
- Click Install button to install DotStar library.
- You will be asked to install the dependency. Click Install All button.
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- Move your hand in front of sensor
- Check out the LED strip
You can modify the code to add a lighting effect.
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.