Arduino UNO R4 - Automated Light Control with Motion Sensor and LED Strip

In this Arduino UNO R4 tutorial, We will learn how to build an automated light control system using an HC-SR501 motion sensor and LED strip. This DIY Arduino project guides you through wiring, programming, and setup to activate the LED strip when motion is detected. Perfect for beginners, this project is ideal for:

With the Arduino UNO R4, HC-SR501 sensor, and LED strip, you can create a smart lighting system that’s energy-efficient. Follow this step-by-step Arduino programming guide to master your DIY smart home automation project.

Hardware Preparation

1×Arduino UNO R4 WiFi or Arduino UNO R4 Minima
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×HC-SR501 Motion Sensor
1×Relay
1×12V LED Strip
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino UNO R4
1×Recommended: Breadboard Shield for Arduino UNO R4
1×Recommended: Enclosure for Arduino UNO R4
1×Recommended: Power Splitter for Arduino UNO R4
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of LED Strip and Motion Sensor

To learn about LED strips and motion sensors (their pinouts, how they works, and how to program Arduino Uno R4 to interact with them), please refer to these tutorials:

Wiring Diagram

The wiring diagram between Arduino UNO R4 Motion Sensor LED strip

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 AdjusterScrew it in anti-clockwise direction fully.
Detection Range AdjusterScrew it in clockwise direction fully.
Repeat Trigger SelectorPut jumper as shown on the image.
arduino motion sensor initial setting

Arduino UNO R4 Code - Motion Sensor Controls LED strip

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-automated-light-control-with-motion-sensor-and-led-strip */ #define MOTION_SENSOR_PIN 10 // The Arduino Uno R4 pin connected to the OUTPUT pin of motion sensor #define RELAY_PIN 3 // The Arduino Uno R4 pin connected to the IN pin of relay, which controls LED Strip int motion_state = LOW; // current state of motion sensor's pin int prev_motion_state = LOW; // previous state of motion sensor's pin void setup() { Serial.begin(9600); // initialize serial pinMode(MOTION_SENSOR_PIN, INPUT); // set arduino pin to input mode pinMode(RELAY_PIN, OUTPUT); // set arduino pin to output mode } void loop() { prev_motion_state = motion_state; // store old state motion_state = digitalRead(MOTION_SENSOR_PIN); // read new state if (prev_motion_state == LOW && motion_state == HIGH) { // pin state change: LOW -> HIGH Serial.println("Motion detected!"); digitalWrite(RELAY_PIN, HIGH); // turn on LED strip } else if (prev_motion_state == HIGH && motion_state == LOW) { // pin state change: HIGH -> LOW Serial.println("Motion stopped!"); digitalWrite(RELAY_PIN, LOW); // turn off LED strip } }

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 motion sensor, LED strip to Arduino Uno R4 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 provided code and open it with Arduino IDE
  • Press the Upload button in Arduino IDE to send the code to Arduino UNO R4
  • Wave your hand near the sensor
  • Look at the LED strip

Video Tutorial

Summary

In this Arduino UNO R4 tutorial, you’ve learned how to create a smart automated light control system using an HC-SR501 motion sensor and an LED strip. By following the step-by-step guide, you mastered Arduino programming, wiring, and setup to activate lights when motion is detected. This DIY Arduino project is perfect for applications like automatic stair lighting, under-bed lighting, or Christmas tree lights, offering an energy-efficient smart home automation solution. With the skills gained, you can now adapt this Arduino UNO R4 project to other creative lighting ideas, enhancing your home with responsive, motion-activated illumination.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!