Wednesday, 5 October 2016

NodeMCU Rgb controller


I made a easy IR controller for my generic RGB light strip. You can simply use curl(like http://IP-ADDR/rgbon) to turn on/off, dim the light or do some silly effects.

Arduino code:
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266mDNS.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
//RGB VALUES
#define LED_ON 0XFFE01F
#define LED_OFF 0xFF609F
#define LED_BRIGHTNESS_UP 0xFFA05F
#define LED_BRIGHTNESS_DOWN 0xFF20DF
#define LED_FLASH 0xFFF00F
#define LED_STROBE 0xFFE817
#define LED_FADE 0xFFD827
#define LED_SMOOTH 0xFFC837
#define LED_RED 0xFF906F
#define LED_GREEN 0XFF10EF
#define LED_BLUE 0xFF50AF
#define LED_WHITE 0xFFD02F
#define LED_ORANGE 0xFFB04F
#define LED_YELLOW_DARK 0xFFA857
#define LED_YELLOW_MEDIUM 0xFF9867
#define LED_YELLOW_LIGHT 0xFF8877
#define LED_GREEN_LIGHT 0XFF30CF
#define LED_GREEN_BLUE1 0XFF28D7
#define LED_GREEN_BLUE2 0XFF18E7
#define LED_GREEN_BLUE3 0XFF08F7
#define LED_BLUE_RED 0XFF708F
#define LED_PURPLE_DARK 0XFF6897
#define LED_PURPLE_LIGHT 0XFF58A7
#define LED_PINK 0XFF48B7
ESP8266WebServer server(80);
const char* ssid = "";
const char* password = "";
IRsend irsend(D3);
void handleOk() {
server.send(200, "text/plain", "ok");
}
void handleRoot() {
server.send(200, "text/plain", "hello from esp8266!");
}
void handlergbOn() {
irsend.sendNEC(0XFFE01F, 32);
handleOk();
}
void handlergbOff() {
irsend.sendNEC(0xFF609F, 32);
handleOk();
}
void setup()
{
irsend.begin();
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
// on/off
server.on("/rgbon", handlergbOn);
server.on("/rgboff", handlergbOff);
//effects
server.on("/rgbbrightup", []() {
irsend.sendNEC(LED_BRIGHTNESS_UP, 32);
handleOk();
});
server.on("/rgbbrightdown", []() {
irsend.sendNEC(LED_BRIGHTNESS_DOWN, 32);
handleOk();
});
server.on("/rgbflash", []() {
irsend.sendNEC(LED_FLASH, 32);
handleOk();
});
server.on("/rgstrobe", []() {
irsend.sendNEC(LED_STROBE, 32);
handleOk();
});
server.on("/rgbfade", []() {
irsend.sendNEC(LED_FADE, 32);
handleOk();
});
server.on("/rgbsmooth", []() {
irsend.sendNEC(LED_SMOOTH, 32);
handleOk();
});
server.on("/rgbred", []() {
irsend.sendNEC(LED_RED, 32);
handleOk();
});
server.on("/rgbgreen", []() {
irsend.sendNEC(LED_GREEN, 32);
handleOk();
});
server.on("/rgbblue", []() {
irsend.sendNEC(LED_BLUE, 32);
handleOk();
});
server.on("/rgbwhite", []() {
irsend.sendNEC(LED_WHITE, 32);
handleOk();
});
server.on("/rgborange", []() {
irsend.sendNEC(LED_ORANGE, 32);
handleOk();
});
server.on("/rgbyellowdark", []() {
irsend.sendNEC(LED_YELLOW_DARK, 32);
handleOk();
});
server.on("/rgbyellowmedium", []() {
irsend.sendNEC(LED_YELLOW_MEDIUM, 32);
handleOk();
});
server.on("/rgbyellowlight", []() {
irsend.sendNEC(LED_YELLOW_LIGHT, 32);
handleOk();
});
server.on("/rgbgreenlight", []() {
irsend.sendNEC(LED_GREEN_LIGHT, 32);
handleOk();
});
server.on("/rgbbluered", []() {
irsend.sendNEC(LED_BLUE_RED, 32);
handleOk();
});
server.on("/rgbpurpledark", []() {
irsend.sendNEC(LED_PURPLE_DARK, 32);
handleOk();
});
server.on("/rgbpurplelight", []() {
irsend.sendNEC(LED_PURPLE_LIGHT, 32);
handleOk();
});
server.on("/rgbpink", []() {
irsend.sendNEC(LED_PINK, 32);
handleOk();
});
server.on("/rgbgreenblue2", []() {
irsend.sendNEC(LED_GREEN_BLUE1, 32);
handleOk();
});
server.on("/rgbgreenblue2", []() {
irsend.sendNEC(LED_GREEN_BLUE2, 32);
handleOk();
});
server.on("/rgbgreenblue3", []() {
irsend.sendNEC(LED_GREEN_BLUE3, 32);
handleOk();
});
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}
view raw gistfile1.txt hosted with ❤ by GitHub
Pinlayout:
Vin(USB 5v): Vcc
Gnd: Gnd
D3: Signal



Parts:
Home Assistant Implentation
switch:
platform: command_line
switches:
kontordeskrgb:
command_on: 'curl http://<<IP ADDR>>/rgbon'
command_off: 'curl http://<<IP ADDR>>/rgboff'
view raw gistfile1.txt hosted with ❤ by GitHub



Simple 3d printed prototype box with everything mounted

1 comment:

  1. Thanks for sharing good article. If you want more information.Please visit my website. just click on this.
    lighting in Perth

    ReplyDelete