Jump to content

Simple Arduino PWM LED Dimmer


Recommended Posts

Recently I bought the ReapidLED 90g dimmable kit. It's working great and a DIY build thread is coming soon. But in order to dim them, I needed a PWM controller. The Arduino platform has examples of how to do analog input to PWM output where you can control PWM via a PET... but I wanted something that would be hands off and automatically dim the lights based on the time of day.


Eventually I will be building a more complex Arduino control from code that other saltwater geeks already have out there... but until I can get an LCD screen and the time to build it I needed something quick! 


This is just that.


You should be able to build this for about $30 bucks, and without any soldering...


Required Parts:


1 - Arduino board (doesnt really matter which one) the diagram uses a nano.. Amazon for $12.00

1 - I2C Realtime Clock ... Amazon for $3.00 shipped

2 - Pentonometers ... Amazon for $6 bucks each (these are optional and only required if you want to take manual control of the lights)

1 - Breadboard ... Amazon $2.25


total = about $30


Alternatively if you want to make it even more professional looking you could sub out the breadboard for a Nano IO Shield and a plug in RTC.. this will add about 12 bucks to the total cost.


Here is the layout:



So basically with my Rapid LED kit i can plug wires from the LDD drivers to the PWM out pins on the arduino and then when i fire up the arduino it will calculate what the white and the blue channels need to be and set the correct PWM frequency.


To start out I created a spreadsheet with a roughed out schedule... this will probably change... but i needed to start somewhere. The values in this table were then plugged into the arduio sketch and it is what runs the dimming when in Automatic mode.




Manual mode is simply controlled by the two PET sensors.


Code is attached as im sure it wont copy in to the post well.


Here is what the Serial output looks like right now:



As you can see each minute a new PWM value is calculated for both the blue and white channels.


It does this by taking the value you specified at hour 1 and the value you specified at hour 2 and figuring out what the gap is... then it spreads that gap evenly over the hour.


So if at 8AM you want 10% brightness on blues and at 9AM you want 20% ... there is a 10 percent gap.. which is about 25 PWM levels so if we spread that change over 60 minutes we need to increase the PWM level by 1 point about ever 2 minutes ... 


This gives a pretty smooth ramp up and down... at least smooth enough that you probably wont notice unless you are stairing into the lights....


Overall its working well so far... Ill post any updates to the code here so that if you decide you need something quick and simple you will have the latest version.


RTC_Lights.zip Version 1.0 - 12/11/2015

Link to comment
Share on other sites

v1.1 - I fixed some little bugs as well as added an LCD output too the code. 


It shows current time as well as blue channel percentage followed by the actual PWM value (0-255) and then on the bottom line the same thing but for the white channel.


(didnt wanted to leave it plugged into my computer to see where things were at as far as percentages)


as for wiring the LCD, mine was an I2C module. so it plugs in to the same ports as the RTC


Screenshot of the LCD output



Link to comment
Share on other sites

Nice work. You'll want to add a 10k resistor between your ldd (+) and (-) feed pins ... Vin on the ldd driver in your diagram. This is. "Pull down" resistor which is necesary to allow all your grounds to be connected, allow the driver to operate when connected and called for by the controller ... And shut off if the contoller loses power. In most setups, the arduino is powered seperately from the LDD drivers (arduino at 6-10v DC, LDDs 12+ V DC depending on your driver and LED load. Without the pulldown, the LEDs fail on if the controller loses power.

Link to comment
Share on other sites

Another Code update. 


Release notes:

Fixed some LCD display weird-ness

Adjusted rate at which the lights rev up and down to fit my schedule.


I should also note that the LCD displayed the time as well as the two channels. And there is two numbers for each channel. The first number on each chanel (before the '%' sign) is the percentage, the second number is the actual PWM level (so 0-255) I added that so that when it hits "0%" but is still on, i know that its only at level 1 or level 2 etc.


Link to comment
Share on other sites

  • 1 month later...

absolutely, I started tweaking your code for my own schedule and learning how you wrote this. (excellent walk through btw)
parts are ordered and I'm excited to try this and more in the future.

ideally working out a personalized version of the code to run all kinds of equipment

this makes me wish I had just built my own light setup (maybe a future project!) 

Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...
  • 5 months later...

Hi can you help me. I connect LDD see image. And I have problem with switch off led. When Is on controller PWM 0, led faintly light. When I disconnect pwm wire from arduino, there is same fault. On image not drawings  Button on pin A0,A1,A2 with pull rezistor 10k, and Relay on pin 8 for fan. Sorry for my English. It is not my mother language. Thank you, Filip.zapojeni.thumb.png.7a1379e011d1551e4f182a4b296f5a97.png

Link to comment
Share on other sites

First welcome to the forum and your English is better than my (insert any language on the planet here!). The original poster has not been around here for quite some time unfortunately. Do the colors on your drawing signify the actual colors coming off the driver?  If so the black is supposed to be for the negative voltage in not the blue. If they don’t mean anything can you tell us what you have hooked where so we can possibly help troubleshoot further?  Red should connect to positive on power supply, black should go to minus. White is the pwm signal. Yellow is LED plus and blue is led minus. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...