Motion-activated light with PIR sensor and RGB LED

FunduinoLast updated on

Licht, das bei Bewegung von selbst angeht

Ein PIR-Sensor erkennt Bewegungen über Veränderungen der Wärmestrahlung in seiner Umgebung. Sobald eine Bewegung erkannt wird, schaltet der Arduino die RGB-LED für fünf Sekunden ein und danach automatisch wieder aus.

So baust du dir mit wenigen Bauteilen ein automatisches Licht, zum Beispiel für den Flur oder als smarte Weihnachtsdeko.

You need this

SR602 motion detector - PIR sensor, 0-5 m, 3.3-15 V SR602 motion detector - PIR sensor, 0-5 m, 3.3-15 V 2,27 € *Item no. F23107467About the product — SR602 motion detector - PIR sensor, 0-5 m, 3.3-15 V
RGB LED 10 mm - common cathode, 4 pins RGB LED 10 mm - common cathode, 4 pins 0,55 € *Item no. F25110734About the product — RGB LED 10 mm - common cathode, 4 pins
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 13,90 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W 1,72 € *Item no. F23107216About the product — Resistor Assortment 100 Pieces - 5 Values 100 Ω to 10 kΩ, 0.5 W
830-point Breadboard - solderless breadboard for Arduino 830-point Breadboard - solderless breadboard for Arduino 2,90 € *Item no. FUN-1010553About the product — 830-point Breadboard - solderless breadboard for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm

All 6 parts together 23,08 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

How the Motion Light Works

The SR602 provides a digital signal: when motion is detected, its output goes HIGH. The Arduino reads this state and switches on the RGB LED. This creates a simple automatic motion light with just two additional components.

Connect components

In addition to the components on the list, you need a USB data cable for your Arduino.

SR602 motion sensor

  • Connect VCC (+) to 5 V on the Arduino
  • Connect GND (−) to GND on the Arduino
  • Connect OUT to digital pin D2 on the Arduino

RGB LED

  • Connect the common cathode of the RGB LED to GND
  • Connect red through 220 Ω to D9
  • Connect green through 220 Ω to D10
  • Connect blue through 220 Ω to D11

The longest leg of the RGB LED is the common cathode. If you don't have a 220 Ω resistor on hand, you can also use a 200 Ω or 330 Ω resistor from the resistor assortment. With 330 Ω, the LED will glow a little dimmer.

Motion light wiring diagram: Arduino UNO with SR602 motion sensor and RGB LED with three resistors
Wiring diagram: SR602 to D2, RGB LED via 220 Ω to D9, D10, and D11

Upload sketch

When motion is detected, the RGB LED lights up white for five seconds. Open the Arduino IDE, copy the sketch, and upload it to your Arduino.

Motion sensor light
const int pir = 2;
const int red = 9;
const int green = 10;
const int blue = 11;

void setup() {
  pinMode(pir, INPUT);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
}

void loop() {
  if (digitalRead(pir) == HIGH) {
    analogWrite(red, 255);
    analogWrite(green, 255);
    analogWrite(blue, 255);
    delay(5000);
  }

  analogWrite(red, 0);
  analogWrite(green, 0);
  analogWrite(blue, 0);
}

Test the project

  1. Check the wiring and upload the sketch to the Arduino.
  2. After powering on, wait briefly for the PIR sensor to stabilize.
  3. Move a hand or person in front of the sensor. The RGB LED lights up for five seconds and then turns off again.

The RGB LED is a common-cathode LED, so the common cathode is connected to GND. Connect each color channel through a 220 Ω resistor. Do not point the PIR directly at heaters, warm air currents, or strong sunlight.

Troubleshooting and extending the lighting

The LED does not light up: Check that the LED's longest leg is connected to GND and the color channels to D9, D10 and D11.

Only one color lights up: Check the resistor and cable for the missing color channel.

The LED does not turn off: The sensor constantly detects movement or a heat source. Point it in a different direction.

Expand the lighting: Use the values in analogWrite to mix your own colors. For warm white light, for example, use red 255, green 120 and blue 20. Use delay to set how long the light stays on.

Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.