Arduino – Home Automation Project, part 2.

 Arduino, DIY, Home Automation  Comments Off on Arduino – Home Automation Project, part 2.
Apr 242012

Well, at last I have made a simple Arduino library of the previous Tx433_Proove sketch. I have pushed the complete code up on GitHub.

Here is the public class interfaces.

class Tx433_Proove
@digitalpin - the digitalpin to send data on to transmitter
@transmittercode - the unique code of the transmitter (52 bits)
@channelcode - the channel code (4 bits)
Tx433_Proove(int digitalpin, char *transmittercode, char *channelcode);

@unit - the device to turn on.
0,1,2 are the three separate devices.
3 is the complete group.
void Device_On(int unit);

@unit - the device to turn off.
0,1,2 are the three separate devices.
3 is the complete group.
void Device_Off(int unit);

Made a new page at to give something back to a great site.

Also added a new link at pointing at the Github upload.

Android touch events script

 Android, Python  Comments Off on Android touch events script
Apr 242012

When I have been working with touch drivers on Android devices, I usually end up using the getevent tool in adb.
But the output takes some time to understand. In order to make it easier for me and my colleagues, I made a small python script called
It is a brute force implementation, but it gets the job done. I uploaded it to github here.

This is how it is used.

adb shell getevent | python event9
adb shell getevent -t | python event9

Arduino – Home Automation project

 Arduino, DIY, Home Automation  Comments Off on Arduino – Home Automation project
Apr 152012

Something I have thought about, on and off, for a long long time is to setup some remote controlled lamps at home.
I have read about the Tellstick from Telldus, but that requires a computer for controlling it. Also I have read and heard that the RF performance/reach is somewhat restricted.
Another solution is of course to use the Arduino together with a RF transmitter.
The different devices available in the stores are all using the same RF frequency, 433.92 MHz, with ASK modulation.

As this is the true DIY solution, I got both a transmitter and a receiver for this frequency ūüôā

The transmitter,
Data sheet,

|       |
|   O   |
|       |
 | | | |
 | | | |
 1 2 3 4

pin    name
1      GND
2      Data In
3      Vcc
4      ANT

The receiver,
Data sheet,

|                    |
|             O []   |
|                    |
 | | | |      | | | |
 | | | |      | | | |
 1 2 3 4      5 6 7 8
pin    name
1      GND
2      Data Out
3      Linear out
4      Vcc
5      Vcc
6      GND
7      GND
8      ANT

I bought the receiver to be able to sniff the data from the remote controller.

Initially I was going to get some Nexa devices. Something like these,
But when I got to the store they didn't have these. Instead they had ,, which is of the brand Proove. They told me it was the same thing(TM), but of course it would turn out it wasn't.

The reason for me to get Nexa was my research done prior to the purchase.
Well, well, they said it was the same in the store.

At home I fired up the Arduino IDE, and made a first attempt on controlling some lights, by just importing the HomeEasyCtrl library into a sketch as the example showed.
But of course that didn't work. It didn't even compile!
Some quick searching on the net, and I found out that old libraries, using #include "WProgram.h", needs to be updated with the following.

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "WProgram.h"
#include <pins_arduino.h>

With this change it compiles, but it does nothing with my remote controlled light.

Time for some extended research. Found out that Nexa has, at least, two different protocols. The old simple protocol, and the new self learning protocol.
A very good web site describing these protocols are, at least if you understand swedish.
I took this information, translated it, at put it on a single page here,

My next approach, after reading up on the protocol, is to use the receiver to get the data from the remote, without needing to open it up.
After some tries, I got some result which I think is the code sent for turning on device number one.

? 1010100101101001010101100101011001010101010101010110 10 01 0101 0101 ?
? = seems like the start bit and stop bit described in the protocol does not exist.

But when I try to send this myself from the Arduino setup, nothing happens. Frustrating!
I tried this approach several times for several days, with modifications, but without any success.
As I ran out of new ideas on how to proceed, I open up the remote.
This is what it looked like.

The Xtal says 'ND13.560'.
The IC says 'Holtek HT48(or 46)R01T3 ...". Web here,
Holtek IC pinout:
(by measurement, visual inspection and looking in the datasheet)

Dout -|1   16|- SW5
SW1  -|2   15|- Sw6
SW2  -|3   14|- SW7
SW3  -|4   13|- SW8
SW4  -|5   12|- Vcc?
?    -|6   11|- ?
?    -|7   10|- ?
Vcc? -|8    9|- Vcc?
SWx, is the buttons on the remote.

Pin #1, Dout, is the actual data sent via RF!! This is what we want!
Time to decode (by probing Dout):
Pressing button #1 On switch and capture data with oscilloscope.
A Pause is, approx. 10 ms low.
A Sync is, high 240 us, low approx. 2.5 ms.
Data sent is: 10101001011010010101011001010110010101010101010101101001010101010
Pressing button #1 Off switch.
Data sent is: 10101001011010010101011001010110010101010101010101101010010101010
Zero = high 300 us, low 1.3 ms
One = high 280 us, low 250 us

A packet consist of:
Data 64 bits
The same packet is sent four times.

The above data is THE SAME(!) as I managed to sniff out of the air with my RX433 sketch!
Still, when I send this data, the receiver does nothing.
But if I look at the data I am sending, it doesn't look as nice as the one the remote is sending.
Especially the 'ones' are kind of distorted. The low part is not as 'distinct'. Wonder what the reason could be? Faulty HW?

Continued to probe all data patterns of the remote, while I still had it opened.

#                10        20        30        40        50           60
#       1234567890123456789012345678901234567890123456789012 34 56 7890 1234
#1 On:  1010100101101001010101100101011001010101010101010110 10 01 0101 0101
#1 Off: 1010100101101001010101100101011001010101010101010110 10 10 0101 0101
#2 On:  1010100101101001010101100101011001010101010101010110 10 01 0101 0110
#2 Off: 1010100101101001010101100101011001010101010101010110 10 10 0101 0110
#3 On:  1010100101101001010101100101011001010101010101010110 10 01 0101 1001
#3 Off: 1010100101101001010101100101011001010101010101010110 10 10 0101 1001
Gr On:  1010100101101001010101100101011001010101010101010110 01 01 0101 0101
Gr Off: 1010100101101001010101100101011001010101010101010110 01 10 0101 0101

Here is oscilloscope pictures of a data packet.

Now when I know I have the correct data from the remote, I try and change the HomeEasyCtrl lib accordingly.
But still, nothing happens when I try to send the data.
Just to rule out HW failure, I bought a second TX433 transmitter. But the result was the same. Conclusion, not a HW issue.
Start looking over my TX433 sketch again, and ... ARGHH!!!..., I found an error in my sendZero function.
Correcting that, and moving the Pause bit to after data instead of before Sync - IT WORKS!
Somehow, at least. Every fourth try fails, could it be a timing issue?
Changing the timing of the pulses, and now it works 100%!!!
The timing used now is:
Zero = 250 high, 1250 low
One = 250 high, 250 low
Sync = 250 high, 2500 low
Pause = 250 high, 10000 low.
A packet is sent as Sync + Data + Pause.

Here is my sketch for TX433 Proove,

TX433 - a 433.92 MHz ASK transmitter
Joakim Wesslen

This program handles the 'Proove' devices, not Nexa.

Found the 'Nexa Self learning' protocol description here (in swedish),
From which I started out.

But as it turns out, the Proove protocol is somewhat different.

Here is a brief description.

A packet is 64 bits in toatal (without dimming bits, whichI do not know if it handles).

Packet structure:
Bit nbr:    Name:
01-52       Transmitter code. 26 bits, but sent as 52 as every other bit is the inverse of the previous.
53-54       Group On(01), Off(10)
55-56       On(01), Off(10) (or Dim(11)?)
57-60       Channel. 1=1010, 2=1001, 3=0110, 4=0101
61-64       Switch.  1=1010, 2=1001, 3=0110, 4=0101
(65-73       Dimmer value, 16 steps. (optional))

Every message is started by a Sync (high pulse followed by a 2.5 ms low)
Every mesage is ended by a Pause (high pulse followed by a 10 ms low)
Every message is sent four (4) times.


#define DBGpin  13

#define TXpin  4
#define RETRANSMIT  4

int tOneHigh = 250; //275;
int tOneLow = 250; //170;

int tZeroHigh = 250;
int tZeroLow = 1250;

int tSyncHigh = 250;
int tSyncLow = 2500;

int tPauseHigh = 250;
int tPauseLow = 10000;

char *dim[15] = {

char *On1   = "1010100101101001010101100101011001010101010101010110100101010101";
char *Off1  = "1010100101101001010101100101011001010101010101010110101001010101";

char *On2   = "1010100101101001010101100101011001010101010101010110100101010110";
char *Off2  = "1010100101101001010101100101011001010101010101010110101001010110";

char *On3   = "1010100101101001010101100101011001010101010101010110100101011001";
char *Off3  = "1010100101101001010101100101011001010101010101010110101001011001";

char *GrOn  = "1010100101101001010101100101011001010101010101010110010101010101";
char *GrOff = "1010100101101001010101100101011001010101010101010110011001010101";

void setup() {
pinMode(TXpin, OUTPUT);
pinMode(DBGpin, OUTPUT);
//  dimtest();

void loop() {
//  group(on);

void group(boolean on) {

if (on) {
Serial.println("Group on");
} else {
Serial.println("Group off");

void test() {
Serial.println("Turn on #1");
Serial.println("Turn on #2");
Serial.println("Turn on #3");
Serial.println("Turn off #1");
Serial.println("Turn off #2");
Serial.println("Turn off #3");

void dimtest() {
for (int d = 15; d >= 0; d--) {
for (int i = 0; i < RETRANSMIT; i++) {
sendCode(On1, strlen(On1));
sendCode(dim[d], strlen(dim[d]));

void sendPackets(char *pkt) {
for (int i = 0; i < RETRANSMIT; i++) {

void sendPacket(char *pkt) {
sendCode(pkt, strlen(pkt));

void sendCode(char *str, int len) {
char *p = str;
int i = 0;
while (i <= len) {
if (*p == '0') {
if (*p == '1') {

void sendZero() {
digitalWrite(TXpin, HIGH);
digitalWrite(TXpin, LOW);

void sendOne() {
digitalWrite(TXpin, HIGH);
digitalWrite(TXpin, LOW);

// Sync
void sendSync() {
digitalWrite(TXpin, HIGH);
digitalWrite(TXpin, LOW);

// Pause
void sendPause() {
digitalWrite(TXpin, HIGH);
digitalWrite(TXpin, LOW);

Something I haven't mentioned so far, but as you might have seen in the code above, is the dimming levels.
The devices I have does not seem to use the dimming levels. But when I added it, it still worked, but without dimming.
It justed continued to turn on and off. Other Proove device though, might be able to handle this. I just don't know, as I havent tried it myself.

A small side note of information is that I found out that it is ArcTech that does the HW for Proove and Nexa et al,

A note on the antenna. As the frequency is 433.92 MHz, I used an antenna (just a piece of wire) with a length of 690 millimeters. Also tried a quarter wave antenna, length 170 millimeters, with same result as the longer one.

As I now have a working sketch for the TX433 transmitter, the next step is to make it a library, to make it easier to re-use in other projects. Something new to learn, great!