Rainbow Flashlight – ElectroSchematics.com

This article describes a rainbow flashlight I designed for a personal project. The intended application compels a multimode, multicolor, compact flashlight/tent light to be driven by a small built-in rechargeable battery pack, preferably with a usb charging interface.

Design: The idea is developed around the following main components:

  • 10mm common-anode RGB LED
  • 10K potentiometer
  • 10mm x10mm momentary push button switch
  • Rechargeable 9V/500mAh USB battery
  • Arduino Uno (R3)

Features: This is the list of key features:

  • Multimode LED – White, Red, Green, Blue, Yellow (flashing)
  • Regulator Knob – 0 to 100% brightness regulation in all modes, and smooth rate control in yellow flasher mode
  • Mode Button – Single push-on button switch for mode selection (OFF-M1-M2-M3-M4-M5-OFF)
  • Transition Indicator – Winking pink color signal to indicate mode transition
  • Built-in Battery – Rechargeable USB Li-ion battery

I constructed the prototype apace using an Arduino Uno prototyping shield and tested it successfully in my lab. The intention of the microcontroller is to react to the mode switch and potentiometer inputs. I employed an Arduino Uno microcontroller to do this, the pretty cute Arduino Nano edition will fit into the puzzle, though.

Insights: Most of the components used in this theme do not need an explanation.

The RGB LED is basically an LED package that can make almost any color. To generate different kinds of colors, you need to set the intensity of three internal LEDs (RGB) and combine the three-color outputs. The three LEDs inside the RGB LED share either a common anode (CA) or a common cathode (CC) particularly in a through-hole package. In a common anode RGB LED (like the one used here), the anode of the internal LEDs is routed to the external anode lead. To switch each color, you need to apply a ‘Low’ signal or ‘Gnd’ to the RGB leads and wire the common anode lead to the positive terminal of the power supply.

I have acquired the following parameters of the LED I used (you should however examine the datasheet for a particular LED):

It’s interesting to see that a typical rechargeable USB 9V Li-ion battery holds a clever piece of electronic circuitry to handle all requisite tasks including lithium-ion battery charge and discharge control, and efficient DC-dc boost conversion. This is the partial inside view of such a battery (thanks to https://lygte-info.dk). You can also see one related note (do it yourself project documentation) here https://www.electroschemics.com/battery/

Hardware Setup: Schematic drawing of the rainbow flashlight/tent light is given below:

As you can see from the schematic, Arduino’s D9-D10-D11 pins are used to drive the RGB LEDs through three 330Ω series resistors R1-R2-R3. The push button switch (S1) is wired to D8 while the potentiometer (POT) is linked to A0 of Arduino. The slide/toggle switch (S2) is the master power control (on/off) switch wired among the 9V battery output of the circuit and external DC input (VIN header or DC jack) of the Arduino board.

Arduino Sketch: Now look at the ‘loopy’ Arduino sketch cooked basically for Uno and Nano editions!

[code]

/*

 * Rainbow Flashlight/Tent Light

 * An RGB LED Multi-Mode Flashlight/Tent Light

 * Using a Common Anode RGB LED & Arduino Uno R3/Nano v3

 * With Potentiometer & Button Switch Control

 * Author: T.K.Hareendran/2020

 * Publisher: www.electroschematics.com

 */




int red = 9; // LED(R) Drive O/P

int green = 10; // LED(G) Drive O/P

int blue = 11; // LED(B) Drive O/P

int button = 8; // Button Switch Input

int potpin = A0; // Potentiometer Input




// various variables




int potval = 0; // Light Level & Flash Rate

int mode = 0; // Flashlight Mode selection




void setup() {




// Initialize

pinMode(red, OUTPUT);

pinMode(green, OUTPUT);

pinMode(blue, OUTPUT);

pinMode(button,INPUT);

digitalWrite(button,HIGH);




analogWrite(red,255);

analogWrite(green,255);

analogWrite(blue,255);

}




void loop() {




// Read Button

int val;

val = digitalRead(button);




if(val==LOW){

mode = mode + 1;




analogWrite(blue,255);

analogWrite(green,255);

analogWrite(red,255);

delay(500);




// Indicate Mode transition (winking pink)

for(int i = 0; i<5; i++){

analogWrite(blue,125);

analogWrite(red,125);

delay(20);

analogWrite(blue,255);

analogWrite(red,255);

delay(40);

}




delay(500);




if (mode == 6){

mode = 0;

}

}




// For Debounce




while (val == LOW){

delay(100);

val = digitalRead(button);

}




potval = analogRead(potpin);




// OFF

if(mode==0){

analogWrite(red,255);

analogWrite(green,255);

analogWrite(blue,255);

}




// WHITE

if(mode==1){

analogWrite(red,255 - potval/4);

analogWrite(green,255 - potval/4);

analogWrite(blue,255 - potval/4);

}




// RED

if(mode==2){

analogWrite(red,255 - potval/4);

analogWrite(green,255);

analogWrite(blue,255);

}




// GREEN

if(mode==3){

analogWrite(red,255);

analogWrite(green,255 - potval/4);

analogWrite(blue,255);

}




// BLUE

if(mode==4){

analogWrite(red,255);

analogWrite(green,255);

analogWrite(blue,255 - potval/4);

}




// YELLOW FLASH-ADJUSTABLE

if(mode==5){

analogWrite(red,0);

analogWrite(green,125);

analogWrite(blue,255);

delay(10);

analogWrite(red,255);

analogWrite(green,255);

analogWrite(blue,255);

delay(1200-potval);

}




}

[/code]

Pictures: Here are a few random test snaps from my work bench, taken with a smart phone camera. Apologies for my terrible photographic skills!

A caveat: Of course, the employment of Arduino Uno in this scheme seems to go farther than would be necessary to do the entire task. Another little Arduino board might take the lead role in my final model. I also have a plan to try one Attiny85 chip at its core as it is more convenient and very economical when compared with a fully-fledged microcontroller development board.

Betterment: The design is OK to get me into business but let me know how to improve. What about substituting the 10mm RGB LED with a high-power 1W (or so) RGB LED?

I know that a 3-channel power LED driver circuitry between the 1W star RGB LED and the main controller (Arduino) is all-important, because such a power LED usually calls for around 350mA of maximum forward current (VF) per channel (Ta = 25℃).

Measurements of each of the LED channels showed that the current drawn ranges from 350 mA to 370 mA, which roughly demands a driver power of 1500mW (1.5W). Note that temperature fluctuations of a high-power LED affect its forward voltage, driving them with a constant current is important to avoid damage due to over voltage. A 3-channel constant-current (up to 500mA minimum per channel) LED driver circuitry is therefore an absolute requirement!

If you want to modify the basic theme with a 1W star RGB LED as the light source, then you need to rig up a 3-channel constant current LED driver. Remember to integrate an apt dc power supply source in lieu of the ‘weak’ 9V battery. Luckily, Arduino can be powered from an external 9-12VDC power source (DC jack/VIN header socket) or a well-regulated 5VDC (5V header socket). One could have obtained even more intensified version if somehow the basic design could have been modified, which I will showcase in another article. Meanwhile, see the outline given below. It should be sufficient to get the point across.

Arduino’s 8-bit PWM is a simple way of controlling most high-power LED drivers. Wiring the Arduino PWM pin and a GND pin to the LED driver circuit is all that is needed. The key to this simplicity is the current sinking and sourcing capabilities of the Arduino I/Os pins.

One more note, which I do not have a lab snap of. I am experimenting with two popular LED driver chips – the AMC7135 and CAT4101. I will document the experiment and post the outcome soon.

Leave a Comment