Instructables
Picture of RGB Flashlight
101_0744.JPG
101_0993.JPG
This flashlight can produce hundreds of different colors based on the rotation of a potentiometer. It uses one three watt RGB led to create bright colors.

Parts list:
1x Arduino UNO
1x Atmega328 with arduino bootloader
     If you need help buring the boot loader chech out this site http://arduino.cc/en/Tutorial/ArduinoToBreadboard
1x 16 Mhz crystal
2x 19-22 picofarad capacitors
1x 28 pin dip socket
1x 3 watt RGB LED
3x b337 npn transistor
1x lm7805 5 volt regulator
3x 470 ohm 1/8th watt resistor
4x 10 ohm 1/2 watt resistor
2x 22 ohm 1/2 watt resistor
1x Flashlight case, I used a flashlight that took d-cell batteries.
1x Toggel switch, Unless you want to use the switch that is built into the case
1x 9 volt battery
1x 9 volt battery clip
1x 3x3 perfboard
1x 5k ohm potentiomotor
Extra wire 
Hot-glue
Solder

Tools:
Soldering iron
Hot-glue gun
Wire cutter
Wire stripper

 
Remove these adsRemove these ads by Signing Up

Step 1: The RGB Sketch

This step explains how the arduino program works, you can skip to the next page if you want.

Basically the code allows you to control the RGB led's Color with one variable instead of three.
Most of the code is dedicated to following the graph I included,it shows what color is generated by mixing different amounts red, green, and blue light.

Program steps:  
1. Read the potentiometer's value
2. Convert the potentiometer's value to a more usable number range
3. Using if statements generate the red, green, and blue analog values for each color.

You can copy and paste the code or download the included zip file.
int rpin = 6;//can be any PWM pin
int bpin = 3;//can be any PWM pin
int gpin = 5;//can be any PWM pin
int rcolor = 255;// holds the coresponding brightness for each color
int gcolor = 255;
int bcolor = 255;
int start = 100;// used for the option startup code
int potv = 0;// Potentiometer voltage
int color =0;//mapped pot value

void setup(){
  
  
  pinMode(rpin, OUTPUT);
  pinMode(gpin, OUTPUT);
  pinMode(bpin, OUTPUT);
  
  // color check leave this commented out unless you want to
  // have the flashligth cycle through the colors at the beging
//  //red
//  analogWrite(rpin, 0);
//  analogWrite(gpin, 255);
//  analogWrite(bpin, 255); 
//  delay(start);
//  //yellow
// analogWrite(rpin, 0);
// analogWrite(gpin, 0);
// analogWrite(bpin, 255); 
//  delay(start);
//  //green
// analogWrite(rpin, 255);
// analogWrite(gpin, 0);
// analogWrite(bpin, 255);  
//  delay(start);
//  //cyan
// analogWrite(rpin, 255);
// analogWrite(gpin, 0);
// analogWrite(bpin, 0);
//  delay(start);
//  //blue
// analogWrite(rpin, 255);
// analogWrite(gpin, 255);
// analogWrite(bpin, 0);  
//  delay(start);
//  //magenta
// analogWrite(rpin, 0);
// analogWrite(gpin, 255);
// analogWrite(bpin, 0);
}
void loop(){
potv = analogRead(A0); //read Potentiometer position
color=map(potv,0,1023,0,1530);// change input number range



if(color>= 0 && color <=255){
  //red to yellow
  gcolor = map(color,0,255,255,0);
  analogWrite(rpin, 0);
  analogWrite(gpin, gcolor);
  analogWrite(bpin, 255); 
  
}
if(color>= 255 && color <=510){
  //yellow to green
 rcolor = (color - 255);
 analogWrite(rpin, rcolor);
 analogWrite(gpin, 0);
 analogWrite(bpin, 255); 
 
}
if(color>= 510 && color <=765){
    //green to cyan
    bcolor = (color - 510);
    bcolor = map(bcolor,0,255,255,0);
 analogWrite(rpin, 255);
 analogWrite(gpin, 0);
 analogWrite(bpin, bcolor);  
  
}
if(color>= 765 && color <=1020){
    //cyan to blue
    gcolor = (color - 765);
 analogWrite(rpin, 255);
 analogWrite(gpin, gcolor);
 analogWrite(bpin, 0);
}
if(color>= 1020 && color <=1275){
  //blue to magenta
  rcolor = (color - 1020);
  rcolor = map(rcolor,0,255,255,0);
   analogWrite(rpin, rcolor);
 analogWrite(gpin, 255);
 analogWrite(bpin, 0); 
}
if(color>= 1275 && color <=1530){
  //magenta to red
  bcolor = (color - 1275);
   analogWrite(rpin, 0);
 analogWrite(gpin, 255);
 analogWrite(bpin, bcolor);
}

}
  

rgb.zip956 bytes
chickychan2 days ago

This is amazing! I wish I knew wtf was going on so I could make one!

marios85434 months ago
Why not an arduino, the resistors, a potentiometer and an rgb led. You dont have to solder the pieces together.
Jgniklu (author)  marios85434 months ago
I soldered it together because I wanted a more permanent project and because my arduino uno wasn't going to fit into the flashlight case.
I understand. Anyway great ible
jhopkins910 months ago
Why the AtMega and not a AtTiny? Seems like a little overkill...
Jgniklu (author)  jhopkins910 months ago
An AtTiny should work great for this project but I only had an Atmega.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!