tech at work


Arduino moodlight

I needed to create a moodlight which fades between blue, green, cyan and white - a perfect job for an Arduino board I had leftover from another project 🙂

So I soldered the common anode RGB-Led to a little piece of PCB and added a 4-header.

After some research I found a really useful arduino library which is perfect for PWM-fading on any I/O pin.

Just look here:


The sourcecode is considerably short and easy to write:

#include <SoftPWM.h>

#define PIN_G 2
#define PIN_R 3
#define PIN_B 4
#define PIN_CA 5
#define T_WAIT 10000

void setup()
 // Setting the common anode

// Init Soft-PWM
 rgbPWMset(0,0,0); // black
 SoftPWMSetFadeTime(ALL, 4000, 4000);
 SoftPWMSetFadeTime(PIN_R, 4000, 3000); // because Red was too dominant when fading out

void loop()
 rgbPWMset(0,0,255); // blue

 rgbPWMset(0,255,255); // cyan

 rgbPWMset(0,255,0); // green

 rgbPWMset(255,255,255); // white

void rgbPWMset(int r, int g, int b)
 SoftPWMSet(PIN_G, g);
 SoftPWMSet(PIN_R, r);
 SoftPWMSet(PIN_B, b);

An example Implementation looks like this: (sorry but flickering is because of the camera...)

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.