Categories
TUTORIALS

Changing RGB LED Display In Accordance with PIR Sensor

This tutorial tells about how to light an RGB LED in accordance with a PIR motion sensor. The RGB LED can display a vast array of colors. By following this tutorial, you can realize the scenario that if the PIR detects nobody around, the LED will be on in a smooth and colorful pattern. When movement is reported by the PIR, the LED will change into a lively pattern. This is part of the project our group are working on, which is to convert a passive and invisible-at-night trash bin into a responsive one.

To begin with, you need

  1. Arduino Kit
  2. Breadboard
  3. Jumper Wires
  4. 3 * 330 Ohm Resistors
  5. 1 * RGB LED (or more)
  6. 1 * PIR Motion Sensor (or more)

Then make sure you have assembled them correctly.

Note that the pins of an RGB LED are ordered RED, COMMON (the longest), GREEN, BLUE. In the circuit, connect COMMON pin to GND. Connect each of the RED, GREEN and BLUE to a 330 Ohm resistor. Connect the other end of each resistor to Arduino digital pin 9, 10, and 11 respectively.

The PIR has three pins: UCC, OUT, and GND. Connect UCC to 5V, GND to GND, and OUT to a digital pin. Here we use pin 2.

 

Now let’s look at the code:

Here I use the “pausetime” to distinguish those who approach the trash bin intentionally from other passers-by. Only if the movement has been detected for a while, which means the person has been staying around for a while, that the movement will be reported, and the light pattern be changed.

Below are the two functions we called in “loop()”. Each of the functions instruct the RGB LED to display colors in a specific way.

 

When it is dark in the street, the LED will be on. Without anyone approaching the bin to throw trash, the LED smoothly displays a rainbow of colors. When somebody is approaching, it will change into blinking.

 

2 replies on “Changing RGB LED Display In Accordance with PIR Sensor”

Hello!

I am an artist working on a project with a colleague of mine and we are interested in using this Arduino/LED/PIR combo in an installation. However, we are complete novices in this field and thus are having trouble getting the code to work.

Basically, we don’t know how to combine the main piece of code with the two functions that follow it. When we copy and paste them all into the Arduino program we get an error saying “SBhere (); was not declared in this scope.” Is there something we are missing? Would you be able to help us with our project?

Thank you for taking the time to read this email!

Sutton

Hi!
I’m a student new to coding and trying out in this project as I’m planning to make a small artwork with it. But I’m also having issues with the SBhere() and NBhere(); not declared error, even though I followed the instructions. I hope you would be able to help!
Thanks!!

Leave a Reply

Your email address will not be published. Required fields are marked *