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



