Friday 18 October 2013

Arduino Starter Kit - Chapter 04 Color Mixing Lamp






New day new race, today I will talk about the fourth chapter of the manual of Arduino Starter Kit:
04 COLOR MIXING LAMP produce any color with a lamp that uses light as an input

In this chapter they present a technique called Pulse Width Modulation (PWM): Since Arduino can't vary the output voltage on its pins, it can only output 5V. Hence you'll need to use the PWM to fade LEDs. PWM rapidly turns the output pin high and low over a fixed periods of time.
When you're rapidly turning the pin high and low, it's as if you were changing the voltage.
The percentage of time a pin is high is called Duty-Cycle.

The Arduino Uno has six pin aside for the PWM (Digital pin 3,5,6,9,10,11) they can identified by the ~ next to their number on the board.

The Circuit:


The function to change the LED's brightness via PWM is called analogWrite()
Syntax: analogWrite(pin,rangeOut)
Where pin is the number of the PWM pin used, and rangeOut is a value between 0 and 255.
NB: analogRead function, as we see in the previous post, return a value between 0-1023, so to use this value you need to convert it into a value between 0-255 dividing it by 4.

As ever if you want the full code, open the IDE and search in the example, is included in the starter kit section.

The result of this project is the top photo, I'm lazy so I don't turn off the light in my room, and the LED is almost ever on. If you cover one or more sensor the light of the RGB change color.

Variant:
In some non official kit there is no RGB LED inside but this project is still present inside the manual.
You can do it anyway, just change the RGB LED with 3 normal color led (1 redLEd, 1 greenLED, 1 blueLED), as described in the following schema:




The result of this little variation is this:




Next post Monday.
See ya.
Ygy Freezone

6 comments:

  1. yup, unfortunately I have a red, a green and a motherfucking yellow led.

    and today I was too busy to get another one... D:

    ReplyDelete
    Replies
    1. well since the color of the output led is only an aesthetic things if you you want you can simply change the green led with one yellow led :)

      Delete
    2. ok but I still miss the blue :P I want a RGB one! :D

      Delete
    3. lol wrong led, if you have a white led you can use this instead of the blue one... however you can also use the yellow one or one in other color , it's only aesthetic. The sensor do not read the LEDs, in fact the sensor write on the LEDs :)

      Delete
  2. Hello, may I use the image above as an example of something you can do using the arduino starter kit? I'm doing a presentation on introductory robotics. Thanks

    ReplyDelete
    Replies
    1. Use freely every image on my blog without problem.
      Maybe, if you can, cite my page in the bibliography

      Delete