Introduction: All the Colours of the RainboW But No RBG LED in Sight . . .

This project came about when i wanted to create a pulsing night/mood light that randomly decides on a colour and then gently lights up and then down again. The problem was that i had no RGB LED and the one i had ordered from China had not turned up and got lost in the post :(.
After some time I remembered the old television pixels and thought maybe i can do this with 3 normal LED's in stead. So off i when to scavenge for LEDs . . .

The project consists of 3 normal LED's, a micro controller (the awesome ATMega328p) on a breadboard, some batteries, a pingpong ball as a diffuser and in order to control the luminosity 3 variable resistors. This togheter with the code enabled me to create a very nice night light for bed time. The difference with this one is that its not very bright, which is what i wanted as most of them are quite bright and in my opinion way to bright for night lights.

Step 1: B.O.M

For this project you will need to be able to:

Create a Bareduino and program it, (you could use a nano, mini, uno or the like but the battery will run out too fast) fortunately there is an instructable about that here: How to make a Bareduino. I used an ATMega328p here but you could probably shrinkify this and use an ATTiny85 or the like instead, the reason i didn't is that that the 328 costs almost half of what the smaller ATTiny costs (go figure)???

  • 1 * ATMega328P
  • 1 * Red LED.
  • 1 * Blue LED.
  • 1 * Green LED.
  • Some Jumper cables.
  • A BreadBoard.
  • 1 * White PingPong ball for diffusing the light. You can use anything you prefer as a diffuser.
  • and of course power, in my case 4 rechargeable batteries.

Optional:
3 * Variable resistors 1-10K (http://www.ebay.co.uk/itm/10Pcs-3362P-103-3362-P-1...)

The reason for the variable resistors is that when you scavenge LED's like i did then they will be different in luminosity and so in order for me to be able to create white light i had to make sure that the luminosity of the LED's was calibrated at maximum duty cycle. This was accomplished by turning on the 3 LED's at max cycle and turning the resistors up and down till i got a white light in the ping pong ball.

Step 2: Wire It Up . . .

Wire it up as show above. It is really simple so i wont go into details here, if you have trouble ping me in the comment section below. I chose PIN9, PIN10, and PIN11 as they are PWN pins next to each other.

Step 3: Code . . .

This was what took a lot of time for me as i didn't want to steal something already made and i wanted a challenge to resolve it myself.

Here is how i upload the code to the BareDuino (ATMega328p) through a FTDI board using the above schematic: (https://www.instructables.com/id/BareDuino-How-to-P...)

Here is the code, i'm sure it can be made much better, simpler and prettier but i am just starting out and a bit of a noob :).

#include "LowPower.h"
int MyX;int CheckW;int Rvalrnd; int Gvalrnd; int Bvalrnd; int Rval;int Gval;int Bval;int IncUP;int N; /////////////////////////////////////////////////////////////////////////////////// void setup() { // Serial.begin(9600); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); randomSeed(analogRead(0));

Rval = 0; Gval = 0; Bval = 0; CheckW = 0; MyX = 0; } /////////////////////////////////////////////////////////////////////////////////// void loop() { MyX++;

if(MyX < 100){ CheckW = 0; Rval = 0; Gval = 0; Bval = 0;
rgbrand(); //Assign randon numbers to the RBG val between 0-25 LightUp(); // increases the luminosity of the LED's to the Rnd Val LightDown(); //Decrease Luminosity of LED's from up value to 0 } else{ analogWrite(9, 0); analogWrite(10, 0); analogWrite(11, 0); LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); }

} /////////////////////////////////////////////////////////////////////////////////// void LightDown(){ // N = 100; while(N>=0){ N--; if (Rval>=3){Rval = Rval - 1; if(Rval<=0){CheckW = CheckW - 1;}} if (Gval>=3){Gval = Gval - 1; if(Gval<=0){CheckW = CheckW - 2;}} if (Bval>=3){Bval = Bval - 1; if(Bval<=0){CheckW = CheckW - 3;}} analogWrite(9, Rval); analogWrite(10, Gval); analogWrite(11, Bval); delay(100); if (CheckW <= 0){break;} } } void LightUp(){ N = 0; while(N<100){ N++; if (Rval<=Rvalrnd){Rval = Rval + 1; if(Rval>=Rvalrnd){CheckW = CheckW + 1;}} if (Gval<=Gvalrnd){Gval = Gval + 1; if(Gval>=Gvalrnd){CheckW = CheckW + 2;}} if (Bval<=Bvalrnd){Bval = Bval + 1; if(Bval>=Bvalrnd){CheckW = CheckW + 3;}} analogWrite(9, Rval); analogWrite(10, Gval); analogWrite(11, Bval); delay(100); if (CheckW >= 6){break;} } } void rgbrand(){ ////// Set Random Values for R,G,B Rvalrnd = random(255); Gvalrnd = random(255); Bvalrnd = random(255); }

LED Contest

Participated in the
LED Contest