In this article I’ll show how to make RGB controller for conventional 12V LED strips (and single powerful RGB leds too). When I say “conventional LED strip” – I mean LED strip where we have common positive lane, and separate R,G,B negative lanes. There is “smart” LED strips also, and, probably, I’ll write another article about them sometime 🙂

This device make on STM32F372 microcontroller, and I use FTDI chip as USB-uart converter. Yes, there is possible to make virtual COM-port on STM32 itself, using its USB interface, but I don’t did it yet. As switching devices I use MOSFETs with “logic” control (it means they have low gate voltage threshold).
Brightness can be controlled from web-page, and from Android-application, and also you can add “time-color” schedule. Last feature is very useful to make your device work as alarm-clock that wakes you up not by sound, but by light. And even if it will be not enough for you to wakeup – it will make wakeup much easier.

 

Schematics:

Overal schematics is very simple – just connect STM32F372 to FTDI usb-uart chip and add 3 FET’s. LED stripe uses 12V as power source, and board with microcontroller powered with USB (5V).

You can download schematics and board layout in Eagle format here:
https://drive.google.com/open?id=0B1blPsoKK5tad1dDTGNtd3l2OHM

Please note – it is very raw at this moment. You probably will want to add sone enhancements in board layout – for example, LED to indicate FTDI RX/TX activity, or SWD programming pins for STM32 (or you car solder wires directly to STM outs – they will needed only one time, for programming). Or, if you don’t want to solder a much – you can use one of these discovery kits.

After soldering, connect common GND (-) of 12V power supply to TP4, and connect LED stripe R,G,B channels to TP1-3, then connect common “+” output of LED stripe to “+” of 12V power supply. AT/ATX supply can be used for this purpose.

Firmware:

You can download project for STM32Cubes here:
https://drive.google.com/open?id=0B1blPsoKK5taWmNoeloyOWEtUDQ

You’ll need Keil v5 to edit/compile code.

After you’ll load firmware to STM, connect LED stripe and power STM and LED stripe up, you’ll see that initlally brightness of all channels set to 50%, and it slowly faded to 0%. This will means that microcontroller is functional, and all connections is good. Now you can move to setting up controlling PC.

Software for controlling PC:

Now we have working PWM controller board, but it still needs commands source to change brightness. In this project, I’ve used Raspberry Pi 1 model A + USB  WiFi adapter to do this, but there is no special magic in Raspberry Pi 1 – you can use any other computer running Linux to do this.
Our PWM controller board wants to have string with lenght of 9 symbols at input. These symbols are three groups of digits, from 000 to 999 each, representing targed brightness of each channel. But you don’t need to enter this manually, of course – there is software for linux-machine that allows controlling device using web-interface, or cron.

At this moment, controlling software is actually set of php files. You will need working HTTP server + PHP + MySQL on your controlling machine. You can easy find manuals how to set-up it. Here is one example: http://www.penguintutor.com/linux/light-webserver
BTW, don’t forget to set-up static IP address of you controlling PC!

You can download software for PC here: https://drive.google.com/open?id=0B1blPsoKK5taRHh5TS1mRTFjS00
Installation is very simple – copy contents of archive to you www server document root, create MySQL database (you can check/change database name in file settings.php), and source base.sql file in you new database.

After you do this, you’ll need to grant httpd user rights to access to tty ports. On raspbian (running lighttpd) you can do this with next command:

#sudo usermod -a -G dialout www-data

And don’t forget to add these two lines in /etc/crontab:

* *          * * *        root        php /var/www/html/cron.php
* *          * * *        root        stty -F /dev/ttyUSB0 115200

At this point, it should work! Check it by trying to set some color from web-interface. Non-clean color (i.e. non only red, green, or blue) can look different on your screen and on your LED lamp – this because they color profiles are very different, this is not solved in current version of device. You can try to set vary color from your laptop/tablet, and set favor ones in schedule.

Controlling software for this device, and schematics is a little raw for now, yes. For now you need to have one PC per one lamp, this is probably ok, if you have only one lamp, but if you want several of it – this is not very useful. So there is a lots of things to improve, yes. It is far from ideal now, and I’ll try to make more useful versions.

Software for Android device
I’ve wrote simple application for Android, that will allow you to set current color for device manually. It just turns you phone/tablet to remote control.
You can download project for Android Studio here: https://drive.google.com/open?id=0B1blPsoKK5tabUpoM2E0WDdBTlE

Few words about usage:
-Screen of mobile device virtually divided to three vertical rows. Just put finger somewhere near to left-down corner of screen, swipe up, and release finger. Color of screen should change from initial white to more-or-less intensive red. More pixels scrolled up – more intensive color. To decrease color intensivity, just swipe down. Similar for green and blue, they controlled by center and right rows of screen.
At this version, android software tries to send command to IP 192.168.0.98. You should change it in sources, if you have different IP of your controlling PC, or set this IP as static IP for your controlling PC.