Introduction: Scanner Light and Arduino As an RGB Lamp

Picture of Scanner Light and Arduino As an RGB Lamp

Hi people!

This time I'm going to show you how to control the light from a old/broken scanner/printer. Maybe you will see, I like to get many things from junk and use in my projects.

Sometime ago I won a old printer from a teacher. Generally when I get something junky, I disassemble them and keep the things that maybe be used for something. From that printer I salvaged the motors, their mechanisms, the source, the scanner sensor and some other little things.

When i got the scanner sensor did not thought of something nice to do, but when scanning some things to study on another printer, I saw that that the scanner had his color changing (yeah, i know,i should leave the cover lowered), and remembered of an article on internet saying this sensors have a RGB led inside them.

Nice! I just had to find where I put the sensor, could be easy....

Step 1: Discovering How to Connect the RGB LED

Picture of Discovering How to Connect the RGB LED

With the sensor in hands, i had to know how to connect the LED inside. First I had to separate the pcb from the black plastic enclosure( be careful to not break it), then testing with a multimeter I was capable to see that the LED is directly connected to the header, no resistor or nothing, just each pin connected to an LED's terminal. I also discovered that the RGB LED is common anode, this means that its positive terminal is shared to each color and to make a color glow we have to connect the respective cathode(negative terminal) to ground.

Step 2: Connecting the Scanner Light and Arduino.

Picture of Connecting the Scanner Light and Arduino.

Since the RGB LED inside the sensor still is a LED, it was connected in the usual way to Arduino, the relative pins at each color must be connected to PWM pins, so we can select the amount of red, green and blue we want the lamp show, the only difference is that this LED is common anode and must have its common pin connected to the 5V instead of GND, and to light one of the colors the relative pin to that color should be put in LOW.

In the first attempt i used 330 ohm resistors in each cathode pin, but this, for an unknown reason didn't work, so I connected the Arduino Nano PWM pins 9, 10 and 11 directly to each LED cathode terminal, and the anode to 5V, this worked fine.

Step 3: The Code.

So, with the scanner light and the Arduino connected we only need a little piece of code to make it glow with nice colors. The code is below, it's well commented, but in next step I will speak a little about how it makes the colors shine.

//Written by Robson Couto
//December 2014
//www.dragaosemchama.com.br
//pins definitions 
#define blue 9
#define red 10
#define green 11
int bluevalue,greenvalue,redvalue,i,j,k; //variables to keep the values
// of the waves in each pin
 
void setup(){
  pinMode(blue,OUTPUT);//LED pins as output
  pinMode(red,OUTPUT);
  pinMode(green,OUTPUT);
  
  redvalue=128; //first color -> red+green=yellow
  greenvalue=128;
  bluevalue=0;
  i=-1;
  j=1;
  k=0;
}
void loop(){
  redvalue=redvalue+i;//changing the wave in each pin every loop cycle
  greenvalue=greenvalue+j;
  bluevalue=bluevalue+k;
  
  analogWrite(red,255-redvalue);//updating the PWM values 
  analogWrite(green,255-greenvalue);
  analogWrite(blue,255-bluevalue);
  
  delay(50);//this can be changed to make the colors change faster or slower 
   if(redvalue==255){ //test if an clor will be increased, decreased or turned off.
     i=-1;            //see the image in the instructable to understand better.
     j=1;
     k=0;
   }
   if(greenvalue==255){
     i=0;
     j=-1;
     k=1;
   }
   if(bluevalue==255){
     i=1;
     j=0;
     k=-1;
   }
}

Step 4: Understanding How This Code Works.

Picture of Understanding How This Code Works.

What the code does is change between the colors red, green and blue, mixing two colors most of the time, for example see the first image above, when the colors red and blue have the same amount the resulting color is magenta, then blue is decreased and red incread until its maximum resulting only the color red, after that red starts to decrease and green starts to increase while blue is turned off resulting in yellow.

See the second image above to know the resulting color when red, green and blue are mixed.

To change the amount of red, green and blue in the LED, the analogWrite() function is used. To use analogWrite() you need a PWM pin, so each pin of the LED, minus the anode(that is connected to +5V), needs to be conected in a PWM pin. On my Nano I used pins 9,10 e 11.

Another thing, as the LED is common anode, using analogWrite(255) on a pin will turn off that color instead of making it glow, this is because that there is no potential difference between the LED terminals, so to make a color glow in its max is necessary to use analogWrite(0).

Step 5: Make It Glow!

Well done!

Now your have an all-new RGB lamp!

Thanks for reading, see you on another instructable.

Comments

lifran (author)2017-09-23

Cool!

VladasV made it! (author)2016-03-15

nice!!

domints (author)2014-12-31

It's unsafe to directly connect LED to arduino :) You could use ULN2003 transistor array or just 3 simple NPN transistors to drive that leds without overloading Arduino pins :) And then you could use some small value resistors to secure LEDs from burning :)

goldenshuttle (author)domints2015-02-20

Hi Domints: I tested a scanner sensor and located the 4 pins (RGB and common Anode). I was very careful using a low volt battery with a reverse polarity protection diode and 470 ohm all in parallel, till i got them to glow safely...I find your comment very interesting. Can you please provide even a hand sketch how to use ULN2003, even for one LED color and I will take it from there..I just don t wanna kill my only one Arduino outputs, or the LEDs. Thanks.

domints (author)goldenshuttle2015-06-23

That's with transistors separately (because I don't have ULN2003 in my Eagle lib), but ULN2003 is just array of 7 transistors in one case - one next to each other with grounds connected internally, exposed collectors and bases of each transistor.

OhYeahThatGuy81 (author)domints2015-01-28

True. Arduino pins cannot source much current (I believe a maximum of 40mA, depending on the chip), therefore a transistor (or MOFSET, depending on the power requirements) is the safer way to go.

Robson Couto (author)domints2014-12-31

Yeah, you're right! ;)

Thanks for the tip.

OhYeahThatGuy81 (author)2015-01-28

From Step 1: "..then testing with a multimeter I was capable to see that the LED is
directly connected to the header, no resistor or nothing, just each pin
connected to an LED's terminal."

How did you determine this exactly?

OhYeahThatGuy81 (author)2015-01-28

Very nice!

brhino617 made it! (author)2015-01-05

Thanks for the instructable, think I might add some potentiometers with analog read to set color values and use as a sort of desk lamp double sided taped under a hutch or something; need to check on getting a couple arduino micros, for simple, fun things like this.

Robson Couto (author)brhino6172015-01-05

Cool! Thanks for posting!

Arduinos minis also are good for this, and they can be really cheap if compared to its big brothers.

goldenshuttle (author)2015-01-04

Wawoo wawoo wawooo...man I have a scanner sensor for few years waiting for something useful to do. It was to neat to be thrown away. You made my day today. many thanks..please keep posting, I am gonna follow ya.

You're welcome!

Don't forget to put an image here and hit " I made it!".

schabanow (author)2015-01-04

I think RGB LED string in scanner/copier sensor unit is desined for cycle-by-cycle operation that means having time enough to dissipate certain amount of heat between the cycles. Converting it to night luminaire you presume it to run constantly. What about overheat?

From the ather hand, the "prepared" sensor turns outside of the scanner/copier chassis, well this point may compensate possible overheating in a constant light source' mode...

Robson Couto (author)schabanow2015-01-04

Yeah, but i left it on all the morning when making this instructable and didn't see any signal of overheating, and it still works.

Anyway, this sensor would be on trash if I not had taken it, it i had burned it, at least I would learn something.

PavelT1 (author)2015-01-02

Cool idea, now you have to try to make a night light with this scanner idea.

Robson Couto (author)PavelT12015-01-03

Thanks! Yeah, you're right.

deba168 (author)2015-01-02

Wow its really cool idea :)

I always love reusing old stuffs.Thanks for sharing.

Robson Couto (author)deba1682015-01-03

Thank you ;)

You're welcome! Wait for more.

SpinnerDave (author)2015-01-02

Nice project.

I also wanted to reuse the LED strip from a scanner.

If you are careful, you can gently separate the LED bar and Scanner PCB from the plastic housing. You can then unsolder the white LED module from the Scanner PCB.

Just use sidecutters to crack the black housing, being extra careful around the 4 pin connector (the LEDs are in the section just above the pins).

I broke the first one I attempted, second one was easier.

Robson Couto (author)SpinnerDave2015-01-02

Thanks for the tip!

I did not mention that i separate the pcb from the plastic housing, now i fixed that, thank you.

What will you do with your LED strip?

cobourgdave (author)2015-01-01

Good instructable, nicely thought out. Usefull rework. With the use of a 555 for the pwm and a transistor for increased current it would make a nice adjustable under counter light!

Robson Couto (author)cobourgdave2015-01-01

Thanks for the kind words.

Nice idea about using 555!

ingostan (author)2014-12-31

How did you test with a multimeter?

Robson Couto (author)ingostan2015-01-01

I used the cotinuity test, i think that most multimeters have this, but i'm not sure.

So I was putting a test lead in one of the LED's terminals and the other test lead in every pin of the sensor's header until i heard the sound. When i heard the sound means the that pin on the header is connected to that LED terminal.

I hope this helps.

gravityisweak (author)2014-12-31

Interesting. I also have one of these, and I've found a few color combinations by experimentation with a 9v battery. Do you plan to make it into a stand alone lamp? Possibly one with color selection buttons?

Yes, but first I need an spare atmega, or better, an attiny to control the colors, becuase these chips are a lot chaeper than an complete Arduino board.

seamster (author)2014-12-31

Whoa, very cool!

Robson Couto (author)seamster2014-12-31

Thank you Seamster.

About This Instructable

25,818views

353favorites

License:

Bio: A eletrical engeneering student, video games lover and hardware aficionado. Starting my journey through the world of electronics. Microcontrollers?! I love them!
More by Robson Couto:Raspberry Pi - GPIOs, graphical interface, pyhton, math, and electronics.Scanner light and Arduino as an RGB lampDot Matrix Printer from a CD/DVD Reader with Arduino
Add instructable to: