May 14th, 2012

Pulse Width Modulation

After building a piece at Franconia Sculpture Park last year, I’ve been looking for ways to add more functionality to its electronic component.

The sculpture consists of an array of solar panels feeding 2 car batteries and these in turn feeding an array of LED tubes and a couple of power outlets (USB and 120 VAC). Since LEDs don’t really dim by themselves, you have to fool the eye by turning them on and off at rates faster than the human eye can notice, creating the effect of dimming. (More on that here and here.)

Picture of circuitUsing an Arduino UNO and the code below I managed to get the lights to oscillate, but it still needs more tweaking to get the movement to smooth out some more. I’m also running into the problem that the formula generating the output values for the oscillation doesn’t always reach the lowest values, so sometimes it seems like it never fully dims down. I could probably just “hack it” with an if statement, but I want to see if I can solve it with the delay or the sin() formula itself.


const int LED = 9; //For holding pin number
float i = 0;
void setup() {
pinMode(LED, OUTPUT); //Sets pin to Output(+)
void loop() {
float amp = 255 * sin(i * .75);
if(amp < 0) {
amp *= -1;
analogWrite(LED, amp);
i += .1;

This video shows the patern, but not too well. Probably because of frame-rate issues the oscillation looks even choppier on video (I used my phone).

Eventually this will be the oscillation pattern used in the night version of the Surya Ratha.

Picture of Surya Ratha

Me, Surya Ratha, 2011

Diagram for all components

Share to facebook Share to Twitter Share to Google+ Share to tumblr Share to Pinterest Share by email disabled

Leave a Reply