Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmotea authored Dec 1, 2017
2 parents d351bc0 + cab2d6f commit d78afcc
Show file tree
Hide file tree
Showing 26 changed files with 551 additions and 244 deletions.
36 changes: 36 additions & 0 deletions Lights/Arduino/Generic_Dimmable_Light/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Custom light instruction

This build is for: https://github.com/mariusmotea/diyHue/tree/master/Lights/Arduino/Generic_Dimmable_Light

1. try out your parts and plan pathways

2. solder gnd/- pathway and the 1k OHM resistors in place

3. fasten wemos headers, and connect G pin to ground pathway

4. Bring a wires from GPIO pins to the paths with resistors

5. Fasten the blue cables (these go to the - of your strip(s)) (the board in the picture will have 2 individual controlable lights, you can have multiple strips on each)

7. Fasten 3 pin headers for mosfets

8. Connect the various paths to 3 pin headers

9. Done


This build is very simular to the Generic RGBW light build. (didnt take picture with the mosfets and wemos inserted, but i guess this can be imagined) make sure the G pin on the wemos hits the grounded path.

![Top](https://github.com/mariusmotea/diyHue/blob/master/Lights/Arduino/Generic_Dimmable_Light/images/Over.jpg?raw=true)
![Back](https://github.com/mariusmotea/diyHue/blob/master/Lights/Arduino/Generic_Dimmable_Light/images/Under.jpg?raw=true)

## Components
[IRLB8721-TO220 MOSFETS (2x)](https://www.aliexpress.com/item/10PCS-IRLB8721-TO220-IRLB8721PBF-TO-220-free-shipping/32714364118.html)

[Wemos D1 mini (1x)](https://www.aliexpress.com/item/ESP8266-ESP12-ESP-12-WeMos-D1-Mini-WIFI-Dev-Kit-Development-Board-NodeMCU-Lua/32653918483.html)

[1k OHM resistor (2x)](https://www.aliexpress.com/item/100pcs-1-4W-Metal-Film-Resistor-1K-ohm-1KR-1-Tolerance-Precision-RoHS-Lead-Free-In/1851964338.html)

[Female Headers (2x)](https://www.aliexpress.com/item/10-10-pcs-Single-Row-Pin-Female-Header-Socket-2-54mm-Pitch-1-10p-12p-20p/32783590196.html)

[Prototyping board (1x)](https://www.aliexpress.com/item/20pcs-5x7-4x6-3x7-2x8-cm-double-Side-Copper-prototype-pcb-Universal-Board-for-Arduino/1847727667.html)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@


/*
This can control bulbs with 5 pwm channels (red, gree, blue, warm white and could wihite). Is tested with MiLight RGB_CCT bulb.
*/

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <EEPROM.h>
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

#define devicesCount 4

uint8_t devicesPins[devicesCount] = {12, 13, 14, 5};

uint8_t transmitterPin = 4; //Pin the Transmitter is attached to
uint8_t transmitterDelay = 100; // Delay between sending commands
uint8_t repeatTransmit = 2; // Number of Transmit attempts (sometimes one Transmit is not enough)

char* deviceId[] = {"10000", "01000", "00100", "00010"}; // Button Codes
char* houseCode = "11110"; //Housecode set in Handheld Remote
int c;




// if you want to setup static ip uncomment these 3 lines and line 72
//IPAddress strip_ip ( 192, 168, 10, 95);
//IPAddress gateway_ip ( 192, 168, 10, 1);
//IPAddress subnet_mask(255, 255, 255, 0);

bool device_state[devicesCount];
byte mac[6];

ESP8266WebServer server(80);

void handleNotFound() {
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}

void SwitchOn433(uint8_t c) {

for (int x = 0; x < repeatTransmit; x++) {

mySwitch.switchOn(houseCode, deviceId[c]);
delay(transmitterDelay);

}

}
void SwitchOff433(uint8_t c) {

for (int x = 0; x < repeatTransmit; x++) {

mySwitch.switchOff(houseCode, deviceId[c]);
delay(transmitterDelay);

}
}


void setup() {
EEPROM.begin(512);
Serial.begin(115200);
mySwitch.enableTransmit(transmitterPin);

for (uint8_t ch = 0; ch < devicesCount; ch++) {
pinMode(devicesPins[ch], OUTPUT);
}

//WiFi.config(strip_ip, gateway_ip, subnet_mask);


if (EEPROM.read(1) == 1 || (EEPROM.read(1) == 0 && EEPROM.read(0) == 1)) {
for (uint8_t ch = 0; ch < devicesCount; ch++) {
digitalWrite(devicesPins[ch], OUTPUT);
}

}

WiFiManager wifiManager;
wifiManager.autoConnect("New Hue Device");

WiFi.macAddress(mac);

// Port defaults to 8266
// ArduinoOTA.setPort(8266);

// Hostname defaults to esp8266-[ChipID]
// ArduinoOTA.setHostname("myesp8266");

// No authentication by default
// ArduinoOTA.setPassword((const char *)"123");

ArduinoOTA.begin();


server.on("/set", []() {
uint8_t device;

for (uint8_t i = 0; i < server.args(); i++) {
if (server.argName(i) == "light") {
device = server.arg(i).toInt() - 1;
}
else if (server.argName(i) == "on") {
if (server.arg(i) == "True" || server.arg(i) == "true") {
if (EEPROM.read(1) == 0 && EEPROM.read(0) != 1) {
EEPROM.write(0, 1);
EEPROM.commit();
}
device_state[device] = true;
digitalWrite(devicesPins[device], HIGH);
SwitchOn433(device);
}
else {
if (EEPROM.read(1) == 0 && EEPROM.read(0) != 0) {
EEPROM.write(0, 0);
EEPROM.commit();
}
device_state[device] = false;
digitalWrite(devicesPins[device], LOW);
SwitchOff433(device);
}
}
}
server.send(200, "text/plain", "OK, state:" + device_state[device]);
});

server.on("/get", []() {
uint8_t light;
if (server.hasArg("light"))
light = server.arg("light").toInt() - 1;
String power_status;
power_status = device_state[light] ? "true" : "false";
server.send(200, "text/plain", "{\"on\": " + power_status + "}");
});

server.on("/detect", []() {
server.send(200, "text/plain", "{\"hue\": \"bulb\",\"lights\": " + String(devicesCount) + ",\"modelid\": \"Plug 01\",\"mac\": \"" + String(mac[5], HEX) + ":" + String(mac[4], HEX) + ":" + String(mac[3], HEX) + ":" + String(mac[2], HEX) + ":" + String(mac[1], HEX) + ":" + String(mac[0], HEX) + "\"}");
});

server.on("/", []() {
float transitiontime = 100;
if (server.hasArg("startup")) {
if ( EEPROM.read(1) != server.arg("startup").toInt()) {
EEPROM.write(1, server.arg("startup").toInt());
EEPROM.commit();
}
}

for (uint8_t device = 0; device < devicesCount; device++) {

if (server.hasArg("on")) {
if (server.arg("on") == "true") {
device_state[device] = true;
digitalWrite(devicesPins[device], HIGH);

SwitchOn433(device);

if (EEPROM.read(1) == 0 && EEPROM.read(0) != 1) {
EEPROM.write(0, 1);
EEPROM.commit();
}
} else {
device_state[device] = false;
digitalWrite(devicesPins[device], LOW);
SwitchOff433(device);
if (EEPROM.read(1) == 0 && EEPROM.read(0) != 0) {
EEPROM.write(0, 0);
EEPROM.commit();
}
}
}
}
if (server.hasArg("reset")) {
ESP.reset();
}


String http_content = "<!doctype html>";
http_content += "<html>";
http_content += "<head>";
http_content += "<meta charset=\"utf-8\">";
http_content += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">";
http_content += "<title>Light Setup</title>";
http_content += "<link rel=\"stylesheet\" href=\"https://unpkg.com/[email protected]/build/pure-min.css\">";
http_content += "</head>";
http_content += "<body>";
http_content += "<fieldset>";
http_content += "<h3>Light Setup</h3>";
http_content += "<form class=\"pure-form pure-form-aligned\" action=\"/\" method=\"post\">";
http_content += "<div class=\"pure-control-group\">";
http_content += "<label for=\"power\"><strong>Power</strong></label>";
http_content += "<a class=\"pure-button"; if (device_state) http_content += " pure-button-primary"; http_content += "\" href=\"/?on=true\">ON</a>";
http_content += "<a class=\"pure-button"; if (!device_state) http_content += " pure-button-primary"; http_content += "\" href=\"/?on=false\">OFF</a>";
http_content += "</div>";
http_content += "</fieldset>";
http_content += "</form>";
http_content += "</body>";
http_content += "</html>";

server.send(200, "text/html", http_content);

});


server.onNotFound(handleNotFound);

server.begin();
}

void loop() {
ArduinoOTA.handle();
server.handleClient();
}


Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions Lights/Arduino/Generic_ON_OFF_device_433Mhz/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 433Mhz Power Socket - Control (Hue Bulb Emulation)
This ESP-8266 Firmware controls generic 433Mhz Power Sockets.
Showing up as regular Hue Bulbs with ON/OFF feature.

* I used one of those cheap Transmitters. [Ebay-Link](https://www.ebay.com/itm/5pcs-433Mhz-RF-transmitter-and-receiver-kit-for-Arduino/381374427148?epid=2037463354&hash=item58cbaff00c:g:8wEAAOSw6EhUN9s-)
* Controlling cheap 433mhz Power Sockets [Picture below]

* Directly connected to VCC(+3,3V) GPIO4 (Data) and GND.
* You need to Edit your **"House Code"** in order to control the correct Sockets!


<center>
<img src="https://cdn.instructables.com/FU4/UJYA/HM8DG3Q3/FU4UJYAHM8DG3Q3.MEDIUM.jpg" width="250">
<br>
</br>
<img src="https://glsk.net/wp-content/uploads/2016/08/433mhz_sockets.jpg" width="300">
<br>
</br>

<div style='float: center'>
<img style='width: 300px' src="images/Fritzing.JPG"></img>
</div>
<br>
</br>
<div style='float: center'>
<img style='width: 300px' src="images/Schematic.JPG"></img>
</div>
<br>
</br>
<div style='float: center'>
<img style='width: 300px' src="images/PCB1.jpg"></img>
</div>
<br>
</br>
<div style='float: center'>
<img style='width: 300px' src="images/PCB2.jpg"></img>
</div>

</center>
32 changes: 4 additions & 28 deletions Lights/Arduino/Generic_RGBW_Light/Generic_RGBW_Light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -102,36 +102,12 @@ void convert_hue()

void convert_xy()
{
float Y = bri / 250.0f;

float z = 1.0f - x - y;

float X = (Y / y) * x;
float Z = (Y / y) * z;

// sRGB D65 conversion
float r = X * 3.2406f - Y * 1.5372f - Z * 0.4986f;
float g = -X * 0.9689f + Y * 1.8758f + Z * 0.0415f;
float b = X * 0.0557f - Y * 0.2040f + Z * 1.0570f;

if (r > b && r > g && r > 1.0f) {
// red is too big
g = g / r;
b = b / r;
r = 1.0f;
}
else if (g > b && g > r && g > 1.0f) {
// green is too big
r = r / g;
b = b / g;
g = 1.0f;
}
else if (b > r && b > g && b > 1.0f) {
// blue is too big
r = r / b;
g = g / b;
b = 1.0f;
}
float r = x * 3.2406f - y * 1.5372f - z * 0.4986f;
float g = -x * 0.9689f + y * 1.8758f + z * 0.0415f;
float b = x * 0.0557f - y * 0.2040f + z * 1.0570f;

// Apply gamma correction
r = r <= 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * pow(r, (1.0f / 2.4f)) - 0.055f;
Expand Down Expand Up @@ -167,7 +143,7 @@ void convert_xy()
g = g < 0 ? 0 : g;
b = b < 0 ? 0 : b;

rgbw[0] = (int) (r * 255.0f); rgbw[1] = (int) (g * 255.0f); rgbw[2] = (int) (b * 255.0f); rgbw[3] = 0;
rgbw[0] = (int) (r * bri); rgbw[1] = (int) (g * bri); rgbw[2] = (int) (b * bri); rgbw[3] = 0;
}

void convert_ct() {
Expand Down
Loading

0 comments on commit d78afcc

Please sign in to comment.