BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Hacking a Wi-Fi LED Controller to work with Blynk


#1

I came across these Wi-Fi LED Controllers, for RGB LED strips on eBay:

Mine was GBP £5.40 because I ordered it from a UK supplier, but if you’re happy to wait for them to arrive from China you can buy the same item cheaper on eBay, AliExpress, Banggood etc.
They also make a slightly more expensive version that has an IR remote as well as Wi-Fi app control, but I wasn’t interested in that functionality so went for the cheaper version. If you flash the code below onto the IR version then the IR remote won’t work (but I’m guessing that the Blynk functionality should work okay).

As usual, I didn’t brother trying the manufacturer’s app and instead went straight for popping the case apart and seeing what was inside.
As I’d hoped, it was an ESP chip (an ESP8285 in this case) and the manufacturer has thoughtfully made it fairly easy to identify and connect to the pins that are needed to flash your own firmware.

A bit of time spent tracing the tracks and referring to the Expressif data sheet for the ESP8285 revealed that GPIOs 5, 12 and 13 are used to control the R, G and B channels.

I soldered some temporary wires on to the board and connected-up a USB to Serial FTDI interface (set to 3.3v), temporarily shorted GPIO0 to ground whilst plugging the FTDI into my PC then flashed some test firmware which worked first time :open_mouth:

Here’s the basic Blynk code:

// Blynk + OTA Code for "Wi-Fi LED Controller" by Pete Kniight

// Arduino IDE Upload Settings
// Board:            "Generic ESP8285 Module"
// Upload Speed:     "115200"
// CPU Frequency:    "80MHz"
// Crystal Frequency "26 MHz"
// Flash Size:       "1M (No SPIFFS)"
// Reset Method:     "ck"               
// IwIP Variant:     "v2 Higher Babdwidth"
                                                                                                                 
// Blynk App Project Setup:
// Add a Button widget connected to Virtual Pin V1, set to Switch mode
// Add a ZeRGBa widget connected to Virtual Pin V2, set to Merge mode and values of 0-1023 for each channel

#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "REDACTED"; 
char ssid[] = "REDACTED"; 
char pass[] = "REDACTED";
char OTAhost[] = "RGB Controller";    
 
#define REDPIN     5
#define GREENPIN  12
#define BLUEPIN   13

int Power = 0;  // We want the power to be Off at startup

void setup()
{
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);

  WiFi.mode(WIFI_STA);
  Blynk.begin(auth, ssid, pass);
  while (Blynk.connect() == false) {}       // Don't proceed until we're connected to WiFi/Blynk

  Blynk.virtualWrite(V4, 0);  // Turn the button widget Off on the app, to match the power off status
 
  ArduinoOTA.onError([](ota_error_t error) { ESP.restart(); });
  ArduinoOTA.setHostname(OTAhost);
  ArduinoOTA.begin();
}

void loop()
{
  Blynk.run();
  ArduinoOTA.handle();
}

BLYNK_WRITE(V1) // Button assigned to V1 
{
  Power = param.asInt();
  if (Power == 0) // If the button widget is set to Off then turn the LEDs off
  {
    analogWrite(REDPIN, 0);
    analogWrite(GREENPIN, 0);
    analogWrite(BLUEPIN, 0);               
  }
  else
  {
    Blynk.syncVirtual(V2);  // If the button widget is On, force a BLYNK_WRITE(V2) to set the LEDs to the ZeRGBa values
  }
}

BLYNK_WRITE(V2) // zeRGBa assigned to V2 
{
 if (Power == 1) // Only apply the ZeRGBa changes if the power is On
  {
    // get the RED channel value and update the corresponding GPIO Pin
    int r = param[0].asInt();
    analogWrite(REDPIN, r);
    // get the GREEN channel value and update the corresponding GPIO Pin
    int g = param[1].asInt();
    analogWrite(GREENPIN, g);   
    // get the BLUE channel value and update the corresponding GPIO Pin
    int b = param[2].asInt();
    analogWrite(BLUEPIN, b);   
  }
}

There’s obviously no re-connection routine included in this simple code, and it’s designed so that the LED strip will be off when the controller is powered-up. Changes to the ZeRGBa widget while the power button widget is off will have no effect until the power button widget is turned on.
OTA routines are included so that the temporary wires needed to flash the initial code can be removed and future updates done via standard OTA.

Enjoy!

Pete.


#2

Nicely done! I think I will give this a try when I have time.

You could also add Espalexa for voice control.


#3

My Magic Home controllers:

this is the IR Version

Magic Home also work with Google Home and Amazon echo dot


#4

Nicely done @PeteKnight Thanks for the write-up :+1:


#5

After I’d written this, I came across this Github project:


the controllers he’s been working with look similar to yours, but not identical.

It should be fairly easy to connect directly to the pins on the ESP to flash it, and the Github project has some IR code as well (although updating the Blynk ZeRGBa with the new RGB values set by the IR control would be a bit of a pain).
I think once you have the ability to control the LED strip using Blynk, the LED controller would be redundant.

Pete.


#6

Hello Pete
yes, his controller was ESP8266 (old model) now all new ones are ESP8285 (smaller)

I mention it here on # 6 “Alternative firmware for Arilux AL-LC0X LED controllers”
How to use Google Home + Blynk with ESP8266 { without " IFTTT " }

he is using two models RGB and RGBW (5 wires). (W) is for White and (WW) for Warm White LEDs

also I succeeded to let it work with GH and Alexa using Sinric.

another site I would like you to try is the Tasmota :
https://github.com/arendst/Sonoff-Tasmota

it is a large sketch where you can find all modules you need and +.

https://github.com/arendst/Sonoff-Tasmota/tree/development/sonoff

by the way this week I bought my first Raspberry Pi 3 .
I am trying MQTT MOSQUITTO HA and more . till now every thing is fine. Youtube is great for learning .

thanks.


#7

To be honest, I’m not a great fan of Tasmota, Espurna etc.
I guess that they’re okay if you want an out of the box solution to give a ‘one size fits all’ sketch with Wi-Fi manager etc included, but for me they’re just far too bloated.

The code I posted above isn’t what I’d normally run on one of my devices, it’s just something I put together to get Blynkers with limited coding skills up and running.
My regular code is MQTT based, with each device responding to Red, Green and Blue MQTT messages, plus on/off messages. I don’t tend to alter the RGB colours very much, so once they’re set I just uses @scargill’s Big Timer node to turn the lights on and off according to a schedule that’s based on when twilight occurs.
The only exception to this is where I have some RGB LED’s near our TV. These used to be on 24/7 on a blue setting, but I figured that the blue light before bedtime might not be the best option for getting a good night’s sleep. I now have a timer that switches over from blue to red in the evening, then switches to a very dim white light when we go to bed and back to full intensity blue again in the morning.

I don’t use Alexa to set the RGB colours, simply because it’s not something I need and isn’t the best way of doing it anyway. Alexa is just used for the on/off/bedtime commands instead.

Pete.