loading

The following information is a single lesson in a larger project. Find more great projects here.

Project Overview:

In this project, you will create a lamp that changes its color depending on the room's lighting conditions. Shine red and blue light on a set of three light sensors, and the LED will turn purple! This project uses three analog inputs and you will watch data from the sensor in the "serial monitor."

Step 1: Project Description

In this project you will use a RGB LED and three photoresistors to create a lamp that smoothly changes colors to match the color of the external lighting conditions. Suppose you want your room lights to match the natural sunlight outside. This project will do it!

In the circuit schematic below, you can see that three photoresistors will be connected to analog input pins A0 through A2. These are set up as voltage dividers: when light shines on the photoresistor its resistance decreases, then its analog pin sees a higher voltage. You can also see that the RGB LED consists of three diodes that are connected to digital pins, which will act as outputs. You will be learning how to program the Arduino so that a change in the input pins results in a change in the LED color.

  1. Continue to the next step.

Step 2: Bill of Materials

You will need the following electrical components for this project:

1 RGB LED

3 220 ohm resistors

3 10 k-ohm resistors

3 photo resistors ...and of course your Arduino Uno and a breadboard!

If you are using the physical Arduino kit, you will also need three color filter gel strips and the wooden mounts that go with them.

  1. Can you match each component on the list to its location on the breadboard?

  2. Continue to the next step.

Step 3: RGB LED

In this project you will be mixing colored light together using an RGB (red-green-blue) LED. This component is simply three different colored LEDs packaged together. When you turn different LEDs on at the same time you can create custom color combinations.

red + blue = violet

red + green = yellow

green + blue = turquoise

red + blue + green = white

  1. The RGB LED has separate anodes (+ terminals) for each color and a shared cathode (- terminal). Typically the cathode is the longest pin.

  2. Continue to the next step.

Step 4: Photoresistor

For inputs in this project, you’ll be using photoresistors. These are sensors that change their resistance depending on the amount of light that hits them, also known as photocells or light-dependent resistors. If you connect one end of the resistor to your Arduino, you can measure the change in resistance by checking the voltage on an analog pin.

The photoresistor is also called an LDR.

  1. Look at the photoresistor in the Components + menu (All Components tab) to find more information about the photoresistor.
  2. Continue to the next step.

Step 5: Pulse Width Modulation (PWM)

In this project you will be fading different colored LEDs on and off to mix colors on an RGB LED together. You might expect that it’s just a matter of providing less voltage to an LED to get it to fade.

The Arduino can’t vary the output voltage on its pins -- it can only output 5V. Hence you’ll need to use a technique called Pulse Width Modulation (PWM) to fade LEDs. PWM rapidly turns the output pin high and low repeatedly. The change happens faster than the human eye can see so the light just appears dim. This is similar to the way movies work, quickly flashing a number of still images to create the illusion of motion. Below we define two terms that are associated with PWM.

  1. Period: the time it takes to complete one high-low transition or cycle.
  2. Duty Cycle: The percentage of time a pin is HIGH in a period is called duty cycle. When the pin is HIGH for half of the period and LOW for the other half, the duty cycle is 50%. A lower duty cycle gives you a dimmer LED than a higher duty cycle.
  3. The Arduino Uno has six pins set aside for PWM (digital pins 3, 5, 6, 9, 10, and 11), they can be identified by the ~ next to their number on the board, as shown in the picture above.
  4. Continue to the next lesson to learn how to build the circuit.

Next Lesson:Setting Up the Circuit

About This Instructable

303views

0favorites

License:

More by circuits:Introduction Arduino Project 15: Hacking Buttons Arduino Project 14: Tweak the Arduino Logo 
Add instructable to: