Skip to content

Latest commit

 

History

History
83 lines (63 loc) · 5.82 KB

README.md

File metadata and controls

83 lines (63 loc) · 5.82 KB

220V controlled ESP8266 IR Ceiling Fan transmitter

We recently bought a "Lyndby" (vanilla brand) ceiling Fan for our new home with an embedded light. It is controlled by an IR remote, normally sitting on a night stand next to our bed. The fan is mounted above our bed, where normally the bedroom ceiling light fixture sits which is wired to the standard on-off light switch next to the door.
The problem is that when we enter the room when it is dark, we have to first locate the remote on the night stand before we can switch on the light. Pretty inconvenient. We considered mounting a second lamp above the fan, but that would look a bit odd.
So, enough excuses to start crafting my little ESP IR box that mimics the (light) signal of the remote.

The approach I took: a small box with an esp8266 (Wemos D1 mini), IR LED, and optocoupled 220V detection. I used the IRremoteESP8266 library to analyse and send signals.

This is how the final result looks This is how it looks

The prototype The Prototype

The schematics The Schematics

The final PCB (Note: the Gnd coloured green/yellow wire is connected to the light switch)

The PCB

I mounted the IR led under the Wemos D1, because the led peeps through a small hole at the front of the 3D printed box.
Make sure that the 220V part on the PCB is properly separated/insulated from the low voltage parts. Be safe !

Some details about the code & project.

Components

Opto coupler is a LTV-817-B, but pretty much any opto coupler capable of dealing with > 220V will do.
Diode at input is an IN4001 (high voltage). Transistors are 2N2222 , but any NPN will do just fine.

IR led resistor value

I use a 10 Ohm resistor to limit the IR current. See This link for an explanation. We need good light, because the IR signal is indirect (reflection) because the fan's IR eye sits opposite of the powerleads.
IR led has 1.5V forward, Hfe of the transistor is somewhere about 100. With the 1KOhm base resitor, base current = (3.3-0.7)/1000 = 2.6 mA, with a Hfe of 75 we saturate the transistor. When saturated, the VCE is about 0.7V. So max current is (3.3-1.5-0.7)/10 = 110 mA. A bit over the max or the IR led (100mA). But since the LED is driven by short 38Khz bursts, the peak current is very short, thus effective current much lower.
You find many other examples with IR transmitters powerd by a transistor where only 10Ohms is used. But if I would rebuild, I would probable try 18 Ohms or so.

Photo resistor

On the PCB you may have noticed a photoresistor that was not in the schematics. The photoresistor is serially wired to a 10K resistor (between gnd and vcc) and connected to Wemos A0, an analog input. This is because I wanted to find out if I can detect if the light is (already) on or off. However, that does not work, the daylight interferes way to much with the light.

IR commands

It took some time to figure out what the IR command codes are. The FAN IR control unit appears to be from Westinghouse, but there are quite a few variants.
The basic protocol turns out to be "Symphony", but the sequences are a bit different from the usual which is: a "single" bitsequence for each command.

The IR analyzer (breadboard prototype) reported:

Protocol  : SYMPHONY
Codes     :  (12 bits)
uint16_t rawData[95] = {
1254, 432,  1254, 432,  408, 1276,  408, 1256,  428, 1276,  410, 1276,  408, 1276,  408, 1278,  408, 1278,  406, 1276,  410, 1276,  408,
7940,  1254, 432,  1254, 432,  408, 1276,  408, 1276,  408, 1278,  1252, 434,  1254, 432,  1254, 430,  1254, 432,  1254, 434,  1252, 432,  1252, 
7096,  1254, 432,  1254, 432,  408, 1278,  408, 1276,  408, 1276,  410, 1256,  428, 1276,  408, 1276,  1254, 432,  410, 1274,  408, 1276,  408, 
7940,  1254, 434,  1252, 432,  408, 1276,  410, 1276,  408, 1278,  408, 1278,  408, 1276,  408, 1278,  1252, 434,  406, 1276,  408, 1276,  408};  // SYMPHONY C00

A sequence of approx 12xx usecs then 4xx usecs is a logical 1, 4xx followed by 12xx is a logical 0. The 7xxx usecs is pause.
Hence, the (on/off) sequence above is: 1100 0000 0000 = 0xC00 , 1100 0111 1111 = 0xC7F, 1100 0000 1000 = 0xC08 ; each 12 bits. The last command is repeated 3 (+) times.
By repeating this analysis for each remote buttonpress I found the following commands:

image

Each command must be repeated 3 times. The dimmer, of course, as many times as needed to set the light at the desired level (if you want to use that via the Telnet interface)
Hence, the proper way to send these using the IR library turned out to be:

//  Send the Fan IR command
void sendCmd(IRcommand cmd, int repeat = 3) {
    irsend.sendSymphony(0xC00,12,1);
    irsend.sendSymphony(0xC7F,12,1);
    irsend.sendSymphony(cmd,12,repeat);
}

Wemos D1 configuration

The Arduino IDE Wemos D1 config for this sketch is:
Flash size: 4MB, 1MB OTA, 115200, Use the OTA port to flash.
Note: the initial upload requires an USB connection. That must be done with the 3v3 jumper disconnected, to prevent a clash between the onboard power from USB and the 3v3 from the power supply. NEVER POWER THE PCB AND USE THE USB AT THE SAME TIME

Telnet

For experimenting, I added a telnet interface using the ESP Telnet library from Lennart Hennigs.
Typing a question mark followed by a CR shows the possible commands.
At some time, using that interface you can connect it to home automation, sending commands through that interface. Of course, this is pretty unsafe. NO UID /PWD or the like, so never ever make this accessible from the internet

Have fun !