ESP8266 WiFi LED dimmer Part 1 of X: The setup

For a while now I’ve been working on building my own network controlled LED dimmer. I have sampeled some commercially available remotely controllable LED dimmers (DX.com models, AppLamp, Fibaro Z-wave, etc.) but all either lacked some fuctions or where WAY too expensive to rollout house wide. So, I decided to construct my own version! In the next few posts I will detail my efforts and explain in detail how to build the latest version! Read on!

This series has been rebooted

Please take a look at the following post to visit the new rebooted series and index of all posts: https://blog.quindorian.org/2016/07/esp8266-lighting-revisit-and-history-of-quinled.html/


Here is a short video of the completed setup:
 

Open on YouTube and select 1080p


My first try at building a network controlled LED dimmer started a few months ago. I’ve been toying with LED strips for several years now using (mostly Chinese) LED controllers. RGB is ok, but nice lighting in my house I focus on the softer and warmer Warm White LED’ s. So RGB will not be a part of these articles, I might make a separate set about them at some point!


PWM Based dimming

To explain the technique we are using a little bit better I will explain PWM dimming in short. Since the advent of digital LED lighting dimming as we have known it by lowering voltage no longer works. The LED has a whole different nature then an analogue lamp and just sending it a lower voltage will make it flicker or turn off completely.
 
To still make LED’s dimmable we are using a technique called PWM dimming. PWM stands for Pulse Width Modulation and the name sums it up quite nicely. Instead of sending a continues stream of a certain voltage (12v in our case) we are very quickly sending pulses of the correct (12v) voltage to the LED. Because of how our eyes work depending on the duration or load/duty of the pulse we will see a certain intensity of light.
 
So basically we are blinking the LED on and off, doesn’t that mean it would be visible? Well, yes and no. If you where to blink the LED’s on and off at say 15Hz yes, you would clearly see them flicker. If you where to raise that to 50Hz it would become less noticeable but still visible to some (Old CRT TV’s would use 50Hz or 60Hz). In our case the ESP8266 supports up to 1000Hz of PWM signals. That means that 1000 times a second the signal will switch on and off again. 
 
When I was younger I always wanted my CRT monitor at 85Hz or above, because at that rate, the flickering became invisible to me and gave me a nice and steady image. Even when not directly looking at the screen and seeing it from the corner of my eye (It seems flickering shows more easily that way). So doing the same at 1000Hz will be impossible to see for anyone! Don’t believe me? Every screen you are currently looking at (TV, Monitor, etc.) has a LED backlight now a days and uses the exact same technique. Not counting cheap monitors with bad backlights, have you ever seen an LCD monitor flicker? No, or rather, you should physically not be able to.
 
(Some cheap monitor have a bad PWM implementation with a too low Hz, when you lower their backlight to the lowest setting flickering could start to occur. These PWM implementations are often around 125Hz or so making a very low duty cycle visible to the human eye and it can cause eye strain, etc. Using the 1000Hz value we are using this cannot occur)
 
To illustrate this a bit here are some pictures which explain it:
As soon on http://www.ni.com/


As seen on http://www.hho4free.com/
 
What these pictures show is that each pulse is for the same amount of time, the amount of on or off time during the pulse varies. This way the average light produced during that pulse can be controlled and varied in intensity!
 
An important part of this PWM process is selecting the correct MOSFET to use. We will be turning the signal on and off within 1 millisecond, the MOSFET has to be fast enough to react to that! More about the MOSFET in the Hardware post.

Version v1.0 Arduino + RM04 based

What I will be describing in these articles will be QuinLED v2.1. QuinLED v1.0 was finished several months ago and has been working flawlessly since that time. It was based on using a (Chinese version) Arduino Nano v3 combined with a RM04 WiFi-to-serial module. I was about ready to ‘mass’ produce this version but then the ESP8266 suddenly popped up on the internet. It had some big promises on what it could do but mostly importantly, it’s price.

The whole setup. A 12v power supply, Arduino Nano v3, Voltage converter and the RM04 module tucked away behind the power supply. This version never left the breadboard stage


The RM04 module


LED strip inside of a handy store aluminium strip

 

 

Cost saving potential!

The v1.0 version costed around 23$ to assemble. That means custom PCB, voltage converter, Arduino Nano, RM04 WiFi module, block terminals, 2 mosfets and some wiring. The v2.1 version shares much of these components just the Arduino Nano and the RM04 WiFi module are replaced with the ESP8266 ESP-01 module. A Chinese Arduino Nano v3 costs around 4$ and the RM04 can be found for around 12$. Making the total for just those two components cost around 16$. The shocker, the ESP8266 cost around 3$ and should be able to do the same functions! That would make a total module cost me around 10$ total! That might not seem huge, but it still allows you to make almost 2,5 v2.1 module for the price of 1 of the v1.0 version!

That was too good to pass up so I bought some of the modules and started working on getting the same functionality working. In a nutshell that functionality is basically building a LED PWM dimmer controllable with Domoticz (My Domotica software of choice). Everything else (how this is accomplished) was not as much important, although I have a preference for it working over my existing WiFi network and not some other protocol or RF, etc.


Version v2.1 ESP8266 ESP-01 based soldered!

Since a few days I have finished my ‘solid’ prototype of this v2.1 version and I have sent my custom PCB to http://dirtypcbs.com/ to get them made for me. I should have those in a few weeks. If those work out, I will post the schematics so you can have them made yourself if you so desire!

Connections layed out on a breadboard



Finished soldering and testing my v2.1 module!


Other side of the board


My horrible and blotchy solder work, it works like a charm though! 😛


The completed setup, controlling the LED strips from Domoticz


V2.1 uses the NodeMCU firmware on an ESP8266 chip in specific the ESP-01 module. The NodeMCU firmware makes the module programmable with LUA, a high-level ‘easy’  programming language. Within this I make it join my wireless network and open a TCP port. Over this TCP port I send some recognizable text which the module reacts to and automatically dims to that light intensity. A special desire I had was to always have the LEDs fade and not just jump between certain values. In the current version that works on a very basic level, it always does so one step at a time with the time always the same between the steps, although that works, visually a more logarithmic or time based approach would be better. But that’s something for a newer software version. 😉


I guess that’s it for the first article. In the second article I will list all parts I have used and where I sourced them. Next up, all the hardware I used and where to buy it yourself!


As always, comments and tips are welcome and appreciated!

12 thoughts on “ESP8266 WiFi LED dimmer Part 1 of X: The setup”

  1. Hello sir,
    I have ESP8266 circuit and wants to use this as a light dimmer. How can i setup this as a light dimmer.
    I will appreciate any help.
    Thanks in advance

  2. Hi Mohd,

    Your in luck, there are 8 blog posts detailing everything you need to know on how to do this! Everything should be there.

    Kind regards,
    Quindor

  3. Hi Quindor
    Thanks for sharing your great work..
    Is the code available to download ? I'd like to try this out
    Thanks
    Chris

  4. I notice that you are not using any resistors. Is this due to using a MOSFETs and not needing the resistor on the base pin of a transistor?

    Secondly you have two MOSFETs. Because you use White only led strips that have a 12v wire and a signal wire does your setup just allow you to run two independent strips at the same time?

    Lastly. If the design of the v2 board was changed to accomodate rgb strips it would need 3 MOSFETs and at least an esp-03. Do you think it could still be made to fit on a small sized board like you have? Possibly mount the DC to DC converter underneath the board to allow the extra room on top for the extra pins of the ESP and extra MOSFET driver?

  5. Hi,
    I’ve followed this tutorial, but i get flicker in my led even at 1KHz pwm, and even with duty cycle fully on. What can be happening? i’ve used irf540N cause i did not found your mosfetr.

    1. Yeah, sad to say but it’s the MOSFETs. The EPS8266 has 3.3v GPIO pins and the MOSFETs you used require around 4.0 volt to make them work correctly (even more so probably). Changing the MOSFETs for a type that has a “Gate Threshold Voltage” below 3.3v will do the trick.

      If you want to test, you can give the ESP8266 more voltage (like 4.5v) and you should see the strip get brighter and stof flickering. This will rapidly kill your ESP8266 though!

Leave a Reply

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