scanner light and arduino as an rgb lamp

by:EME LIGHTING     2020-03-27
Hi people!
This time I will show you how to control the light from the old/bad scanner/printer.
Maybe you will see that I like to get a lot of stuff from trash and use it in my project.
Not long ago, I won an old printer from a teacher.
In general, when I get something junk, I take them apart and keep something that might be used for something.
From that printer, I rescued the motors, their mechanisms, sources, scanner sensors, and a few other small things.
When I got the scanner sensor, I didn\'t think of anything good to do, but when I scanned something to study on another printer, I saw a change in the color of the scanner (
Yes, I know. I should put the lid down.
, Remember an article on the Internet saying that there is an RGB led inside this sensor. Nice!
I just need to find out where I put the sensor. . . .
With the sensor I have to know how to connect the LED inside.
First, I have to separate the pcb from the black plastic case (
Be careful not to break it)
And then tested with a multimeter, I was able to see the LED connected directly to the plug with no resistance or no resistance, just each pin connected to the terminal of the LED.
I also found out that the RGB LED is co-anode, which means that its positive terminals are shared to each color and we have to connect the corresponding cathode (
Negative end)to ground.
Since the rgb led inside the sensor is still an LED, it is connected to the Arduino in the usual way, the relative pins of each color must be connected to the PWM pins, so we can choose the number of red, green and blue lights show that we want, the only difference is that this LED is public anode and has to connect its public pin to 5 v, instead of GND, in order to light one of the colors, the relative pins of that color should be placed at a low level.
In my first attempt, I used a 330 ohm resistor in each cathode pin, but it didn\'t work for unknown reasons, so I connected the Arduino Nano PWM pin 9, each LED cathode terminal has 10 and 11 directly and the anode is 5 v, which is good.
So, when the emergency light is connected with the Arduino, we only need a small piece of code to make it shine in a beautiful color.
The code is as follows and the comments are good, but in the next steps I\'ll talk a little bit about how it makes the color glow.
What the code does is make changes between red, green, and blue, most of the time mixing two colors, for example, see the first picture above, when the number of red and blue is the same, the resulting color is magenta, then the blue decreases and the Red increases until its maximum value only produces red, after which the Red begins to decrease and the green begins to increase, while the blue turns off, resulting in yellow.
See the second picture above for the resulting color when red, green and blue are mixed.
In order to change the number of red, green and blue in the LED, the analogy ()
Function is used.
Using analogWrite ()
You need a PWM pin, so subtract the anode from each pin of the LED (
Connected to 5 v)
, Need to be connected in the PWM pin.
On my Nano I used 9, 10 e 11 pins.
Another thing, due to the use of analogWrite (255)
The color will be turned off on the PIN instead of making it glow because there is no potential difference between the LED terminals, and the maximum need for such a color to glow in the dark is to use analogWrite (0). Well done!
Now you have one. new RGB lamp!
Thank you for reading, see you in another manual.
Custom message
Chat Online 编辑模式下无法使用
Leave Your Message inputting...