Arduino UNO R4 - Motion Sensor - LED
Discover how to control an LED with the Arduino UNO R4 using the HC-SR501 motion sensor in this beginner-friendly Arduino tutorial. We’ll show you how to light up an LED when motion is detected and switch it off when there’s no movement. Perfect for mastering Arduino programming, motion detection, and simple LED projects!
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of LED and Motion Sensor
Learn about LEDs and motion sensors (pinout, functionality, programming) in these tutorials:
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
Initial Setting
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 UNO R4 Code
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Wire the components according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Copy the code and open it in the Arduino IDE
- Click the Upload button in the Arduino IDE to send the code to the Arduino UNO R4

- Wave your hand over the sensor
- Watch the LED's response
Code Explanation
Check the explanations in the comments within the source code!