8 February 2016

WiFiRGB - A WiFi-enabled RGB high-power LED

Features
  • Simple hardware, using pre-fabricated modules
  • Controls an RGB LED via any recent browser, any operating system
  • WiFi credentials can be configured via browser
  • Software is written as an Arduino sketch
Introduction

Some time ago I read about the cheap and easy to use ESP8266 WiFi modules and I had to have a couple of them. So I ordered two ESP-01 modules. At the time I had no idea what to do with them, but I was sure that this was only a matter of time.

 
Later, I discovered that high-power LEDs can be had for a ridiculously low price from China, so again, an impulse purchase was the inevitable consequence. Of course it was soon clear that I had to combine both...



By the time that insight dawned on me, the community had made major advances on the IDEs for the ESP8266. Whereas earlier you had to use a separate microcontroller and communicate with the ESP via UART and AT commands, it is now possible to use the Arduino IDE. This is an amazing and fascinating development and I decided that I would build a WiFi controlled power LED without a separate controller. After all, setting a few outputs to PWM is easy, right?

Hardware Concept

I was pretty confident that the hardware side of things would be trivial. I needed a 3,3 Volts power supply for the ESP, and a few transistors to drive the current for the LED. That would be more or less it.

And of course this went wrong - at least to begin with. The LED that I intended to use was advertised as a "high-power super bright RGB LED" with the following technical data:
  • Power: 10W
  • Voltage: Red 6-7V; Green 9-12V; Blue 9-12V
And that was all. No data sheet, nothing else. But how could that stop me with a price tag of €1.20?! From other, similar offerings I learned that this variety of LEDs should be fed a current of 300 mA. That sounded reasonable to me. It meant that each colour was contributing about 3 Watts to the total sum of 10 Watts. And the high voltage meant that for each respective wavelength, three LED chips were connected in series.

A current of 300 mA can easily be switched by a standard transistor like the BC337, especially when using PWM. The power supply for the whole project would be a 12V / 1A wall-wart. Life can be so easy...

RGB means three colours. So three outputs of the ESP-01 module had to be used. The ESP-01 module has only two GPIO pins. But this is sufficient with a little compromise. Of the 8 pins on the module, two are used for power supply, one is RESET and one is a PWR_DN (power down) pin. Two are GPIO 0 and 2 and two are used for serial communication. I decided to use the TX output of the latter two for the third channel.

Initial Design Flaws...

During the work on this project, I discovered that things were not quite as simple as expected. The linear regulator that I used to supply 3.3 Volts to the ESP got VERY hot. That was to be expected, had I done my homework. The ESP uses sporadically more that 100 mA and that means that the regulator has to convert a power of (12V - 3.3V) = 8,7 V x 0,1 A to heat. This is around 1 Watt and borderline with an AMD1117-3.3 in its tiny SMD package.

The initial driver control was straight forward: A resistor on each GPIO connected to the base of an NPN transistor. I had not expected that this would cause any trouble, but it did. If during boot-up GPIO 0 is low, the WiFi chip waits for an upload of new firmware and gets stuck. I had somehow expected, that with the transistor's base-emitter diode and the base resistor, there was a very small load on that pin. And so I expected a "high" state there. But I had not considered the fact that the internal pull-up resistor on the ESP8266 is very weak. So the chip didn't start up properly.

And finally I did not calculate the power that the respective LED's current limiting resistors would have to dissipate. The worst case is of course the red channel. With an LED forward voltage of around 6.5 Volts, a power supply of 12 Volts and a 300 mA supply current, that is about 1.5 Watts. A standard resistor is rated at about 1/8 to 1/4 Watts - a slight discrepancy.

...and Solutions

There is a saying that goes: "Buy cheap, buy twice". For my circuit this was more like "Don't think, build twice".

In the second incarnation of the electronics I replaced the linear 3.3V voltage regulator by a buck converter module. This means next to no heat and higher efficiency.

In order to raise the voltage on GPIO 0 during boot I added a red standard LED in series with the base resistor. It adds around 1.6 V to the base-emitter diode of the driver transistor. This means a total voltage drop of 1.6 + 0.6 = 2.2V. This is enough for the ESP to started in normal mode. And the little LEDs are great for debugging without the power LED connected.

On the output I determined the current limiter resistor values and used 3W resistors. But I still didn't like the heat that was produced on the red channel's resistor. So I replaced it by a series of two 3W resistors.

Problems solved...



The Software 

The software as such isn't really complicated. And it is built on the work of others. First and foremost, there is of course the Arduino IDE with the ESP8266 core and the WiFi library that comes with it.

Then, there is a very useful library called WifiManager. It helps you to connect the ESP to a network and to enter and permanently store the networks credentials. So you don't have to hard-code them into the software.

WifiManager starts a captive portal on 192.168.4.1 if it can't connect to a previously set WLAN or if no login data was ever set. Just connect to a network with SSID "WifiRGB" and enter the relevant data. Once it does connect successfully, you need to find the IP number it got from your DHCP server. Data is stored permanently, so I implemented a page that can be invoked manually (http://ww.xx.yy.zz/reset) to delete the credentials.

That library comes with a few examples, which also show you how to create a very rudimentary web server. I extended that in order to add pages which can display a colour picker and to set the PWM for the LED.

When I created the pages, I came across the fact that in HTML5 there is a complete colour picker input element. This is perfect! You can create a page to select a colour almost without any code. Unfortunately, not all browsers support this feature yet. Microsoft browsers don't (Edge, IE), IPhone browsers neither (Safari, Firefox, Chrome). Firefox and Chrome in Windows work great, the same holds true for Android and Linux. In order to provide a fall-back solution, I added an alternative input method, namely R/G/B sliders. These worked on all browsers that I have tested.

The page also contains some simple javascript so that the "submit" button doesn't have to be pushed. It is there nevertheless, in case javascript is disabled in your browser.

And brushing up on my html knowledge I even included a little icon to the page.

Practical Issues

Heat is a general issue with a device like this. I had no problems with the LED on a relatively small heat-sink. But the resistors in series with the LED do get rather hot. Don't put them in a closed project box, but use a box where hot air can escape.

Voltage
The ESP runs at 3.3 Volts. If you use an adjustable voltage regulator like me, set the voltage before you insert the ESP-01 module, otherwise you will kill it.

Finding the IP address
Once the ESP has valid credentials, it will connect to your network. But you will not know, what address it has. I recommend to use a network scanner like Fing on your phone to find it. Scan the network and look for a device from Espressif.


Programming the ESP8266

There is no explanation in this post how to compile and upload the firmware to the ESP-01 module. There are plenty of wikis and documents for that.

The hardware that is described here doesn't support writing the firmware. So you need a separate programming jig. And you have to read up on how to use the Arduino IDE with the ESP. But it is worth it.

As always, the software and schematics are available for download from my download page. Enjoy!


1 comment: