Posts: 38
Joined: Sun Oct 23, 2011 1:45 pm

Software implementation of HT12E encoder

Sat Sep 29, 2012 11:27 am

Hello all,

I'm trying to make an RF mains switch with an HT12D decoder on the receiver side. I tested with HT12E on the transmitter side and all works well (no switching yet, just lighting up LEDs). But since the encoder takes parallel input, the number of required GPIO pins would be too high.

I'd like to implement/simulate the HT12E in C using wiringPi lib. For now I'd just like to connect one GPIO pin to the data in on the decoder and send the serial data to make the decoder recognize the data sent. I know the voltage level on the GPIO is most likely too low, so this needs some extra components. But something else seems to be wrong, too.

The decoder's oscillator frequency is set to accept encoder @ 3kHz, So one encoder clock cycle should be somewhere around 300us. According to datasheets, each address/data bit lasts 3 clock cycles, "one" being represented as low,low,high and "zero" as low,high,high. The address/data sequence is preceded by a pilot and sync period, pilot being 12 bits of low and sync 1/3 bit high. One information word is pilot+sync+address+data and encoder sends it out 4 times. This should be understood by the decoder, which is not my case, unfortunately, so I'm doing something completely wrong. Since I don't have a scope, I can't rule out that I misunderstood the word structure. But there must be something wrong with my circuit, too, because the leds on the data out light up like a Christmas tree even though I'm not sending any data...

There is this one guy, who did something very similar if not the same http://www.mhr.me.uk/projects/RemotePowerRpi.html, but the waveforms he measured on his HT12E don't look like the ones in the datasheets and the ones I described here. I guess I'll drop him an email, perhaps he'll be willing to help.

In the meantime, anyone with experience with HT12E encoders and their internal workings, please be so kind and let me know what I'm doing wrong. All advice is highly appreciated.


Hugh Jarse
Posts: 46
Joined: Mon Mar 05, 2012 5:03 pm

Re: Software implementation of HT12E encoder

Sat Sep 29, 2012 1:45 pm

I have sent some information to your email address.

Posts: 38
Joined: Sun Oct 23, 2011 1:45 pm

Re: Software implementation of HT12E encoder

Sat Sep 29, 2012 2:19 pm

Hi and thanks a bunch. In the I meantime started from scratch.

I realized, I could "scope" the encoder output using the raspi itself, so I switched the gpio to input and sampled it (I used a voltage divider). The output had some holes in it, due to the sampling rate, but I could confirm the data in the datasheets, so the info stated in my original post regarding the waveform and word structure fits

I rewrote the code more or less from scratch (it was just a proof of concept anyway) and tried it again. And it worked. Now I know why the leds lit up like a Christmas tree, too. It's most likely due to the inverted signal, caused by the NPN transistor switching the 5V by 3.33V (and inverting it in the process). Before, I connected the raspi to the board and then fired the program, which caused the decoder to be deranged, because of the constant high signal at the beginning. Now I fired the program and then connected the raspi to the board. Worked like a charm, at least the first step along the way.

Thanks for your very prompt feedback and source code. I'll take a look at it, I'm sure it'll be helpful (even though we are using different libraries). I'll most likely be posting my progress here, so feel free to check once in a while or drop me a mail if you like.

Posts: 1
Joined: Fri Nov 07, 2014 6:37 pm

Re: Software implementation of HT12E encoder

Fri Nov 07, 2014 6:43 pm

I am trying to do same thing with Arduino Uno and am not able to do this. I am basically using a small program to 'watch'/decode the DOUT from encoder and then trying to capture the timing info in another program. But it does not seem to work.
Here is what I send:
sendPilot() //low for 10000 us
sendSync() //high for ~290 us
for (i=0;i<8;i++)
sendHigh(); //assuming all high bits
for (i=0;i<4;i++)

sendHigh is basically a wave 001 (290us+290us (LOW), 290us (HIGH)

I do this whole thing thrice. Is there anything obviously wrong? Any help will be deeply appreciated.


Posts: 1
Joined: Fri Jan 19, 2018 7:18 am

Re: Software implementation of HT12E encoder

Fri Jan 19, 2018 7:54 am

hey..! could you please send the details of this implementation to my email id: akram1pu@gmail.com

Posts: 245
Joined: Thu Nov 22, 2012 9:38 pm

Re: Software implementation of HT12E encoder

Tue Mar 19, 2019 12:46 am

Any more work on this? I would love to great a project to emulate HT-12E encoding and with 303.875 Mhz SAW to create a RF remote control transmitter.

Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 27461
Joined: Sat Jul 30, 2011 7:41 pm

Re: Software implementation of HT12E encoder

Tue Mar 19, 2019 10:33 am

This is a pretty old thread, and I suspect the original posters are no longer posting here.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

Return to “Automation, sensing and robotics”