First attempt: Controlling the LED driver brightness via PWM/arduino

This video shows an example sketch that controls the dimming on each channel (blue and white) independently.  You’ll see it go from 100% to 50% to low on each channel, and then slowly fade from 0 to 100% and then back down again, then repeat:

I now have pwm dimming set up and working on my tank via Arduino.  The whole system is operated by a regular programmable timer.  The timer turns the whole system on at 10:00 and off at 22:00.  The Arduino turns on with the timer (5v power is fed to the arduino via the Steve’s LEDs controller), and ramps from 0 to 100% on both channels over the course of six hours, and back down to 0% during the next six hours.  This, of course, is the first draft of the Arduino sketch and has one major shortcoming (outside of lack of on-the-fly programmability and user-feedback): if the power goes out, it starts back over at 0% output and begins ramping up again.  This isn’t a big deal if you rarely experience power outages, but could really mess up your tank’s usual light cycle if there are any power interruptions.

Here’s the Arduino code:

// This skectch brings LEDs from off to full brightness over a period of 6 hrs
// Then it dims down to off over a period of 6 hrs allowing for a full 12 hour
// cycle when controlled via an external timer.
int BluePin = 9; //this is the pwm output for the blue channel
int WhitePin = 10; //this is the pwm output for the white channel
void setup()
{
 pinMode(BluePin, OUTPUT);
 pinMode(WhitePin, OUTPUT);
}
void loop()
{
 for (int i = 0; i<255; i++)
 {
 analogWrite(BluePin, i);
 analogWrite(WhitePin, i);
 //delay for 84.375 seconds.
 delay(30000);
 delay(30000);
 delay(24375);
 }

 for (int i = 255; i>0; i--)
 {
 analogWrite(BluePin, i);
 analogWrite(WhitePin, i);
 //delay for 84.375 seconds
 delay(30000);
 delay(30000);
 delay(24375);
 }

}

In case you are wondering, the ‘84.375 seconds’ value in the sketch corresponds to 256 slices of six hours.  The analogWrite method accepts values from 0 to 255.

Schematic:

9 thoughts on “First attempt: Controlling the LED driver brightness via PWM/arduino”

  1. Thats awesome. Is the code working? I have stevesleds drivers on my tank too and i am trying to build an arduino controller for it. I have no electronics or coding knowledge though i have the basics on getting to controller together. Do you have a step by step somewhere that i could follow?
    Thanks
    BJ

    1. Hey BJ,
      Yeah the code is working great. The StevesLeds driver is really easy to control via arduino. There is very little to do other than hooking up the specified driver pins to a pwm output on the arduino, +5v, and GND. I actually created a board with screw terminals on it for this project to get everything off of the arduino and onto something smaller/easier to manage. You should be able to just copy the code from the site into the arduino IDE and have it all working. You can adjust the values in the code to suit your needs. Anyway, if you need help or get stuck, just holler.
      -shane

        1. The Steves Leds driver actually has a 5v output that is meant for supplying power to the Arduino. I currently use a board with an atmega328, but an uno will work great.

  2. I am trying to wire this up, but I must be missing something. In your diagram the From Controller +5v refers to the #4 pin on the Steve’s driver? And the PWM Output goto the #2 pin on the driver?

    I can’t get my board to power up from the driver.

    Thanks

  3. I have the arduino uno r3 using the very same code method of dimming in this article but not having much luck, getting very odd results such as LED flickering at times and no real visible dimming. Using PWM input on the driver pin2 and have tried powering stand alone as well as powering off driver pin4 (with ground off uno going to power supply ground). I have a email out to StevesLED hopefully to get some pointers on what i might be missing, ill post here when i hear back.

    /*
    Fade

    This example shows how to fade an LED on pin 9
    using the analogWrite() function.

    This example code is in the public domain.
    */

    int led = 9; // the pin that the LED is attached to
    int brightness = 0; // how bright the LED is
    int fadeAmount = 5; // how many points to fade the LED by

    // the setup routine runs once when you press reset:
    void setup() {
    // declare pin 9 to be an output:
    pinMode(led, OUTPUT);
    }

    // the loop routine runs over and over again forever:
    void loop() {
    // set the brightness of pin 9:
    analogWrite(led, brightness);

    // change the brightness for next time through the loop:
    brightness = brightness + fadeAmount;

    // reverse the direction of the fading at the ends of the fade:
    if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
    }

    delay(1000);
    }

  4. I don’t see any problem with your code, but what happens when you just run a sketch that has this:

    // the setup routine runs once when you press reset:
    void setup() {

    pinMode(9, OUTPUT);
    }
    void loop() {
    analogWrite(9, 255);
    }

    ************************

    If that doesn’t work, I’d try a different pwm pin.

    1. Turned out that I didn’t have the arduino on a common ground with the driver, at least it wasnt a good ground. Works like a champ now.

Leave a Reply to Jeff Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>