Go Down

Topic: Decoding the WHA2 PIR for the 433MHz WHA1 alarm system (HOLTEK HT48XX based). (Read 5989 times) previous topic - next topic

ahull

I decided to take a crack at decoding the output of a PIR from a Freidland WHA1 alarm

Code is too large to fit in one post here, so I moved it to its own git repo on Bitbucket.

Bitbucket repo for most up to date code.. https://bitbucket.org/ya_433MHz/ya_433mhz_lib/src/bdfd3b7812d452ccf1c498a340f239b64a4ae572/Ya_Holtec_decoder.ino?at=master

Code sensitivity improved.
Added a timed LED blink function.
Also added a select statement to allow each individual device to be identified on the serial console.

Something like..

Device 1
Device 1
Device 1
...
Device 1
Device 1
Device 4
...
Device 4
Device 1
Device 1
...

and so forth

ahull

#1
Feb 14, 2014, 05:59 pm Last Edit: Feb 15, 2014, 05:25 pm by ahull Reason: 1
Here is a more complete description.

The Alarm in question operates on 433MHz (this is stamped on the radio device in the PIR), it has a Holtek microcontroller, a  HT48XX 18 pin one time programmable device with generic numbers on it, so custom programmed.


Freidland WHA2 http://uk.rs-online.com/web/p/security-alarm-detectors-proximity-sensors/7193109/


Using  a scope to view the output of the microcontroller pin going to the radio circuit suggested the protocol was similar to other Holtek designs, but I couldn't make any of the existing libraries work reliably.

They either saw nothing, or produced garbage.  

I therefore wrote my own code to grab the "packet" from the PIR.

The sketch is very configurable, in terms of timing, packet length and so forth and should work for other similar devices with very little modification.

Code is fully commented. Let me know if it works for you. If it doesn't, then uncomment a few of the DEBUG lines and see if you can figure out what went wrong. Bear in mind this is a proprietary protocol, so your device may operate in a slightly different manner, with slightly different timings and/or firmware.


EDIT: The picture above shows the sketch in action, the bright LED on the nano clone has been set to blink in response to a valid code from the PIR in the background.

Note: The crude "tunable" 433MHz aerial formed from a pencil wrapped with a  "random long wire" actually works quite well, giving a range of 4 metres or so without any attempt to tune it.  

The radio receiver is one of the "cheapest of the cheap" 433MHz receiver modules that eBay is awash with, so a good antenna is a must, otherwise the range is only a few cm.


Here is the Sketch in action, showing the serial output including some of the DEBUG output from poor sync pulses enabled.

On the Arduino Nano, the Sketch uses 3,782 bytes (12%) of program storage space. Maximum is 30,720 bytes.
Global variables use 228 bytes (11%) of dynamic memory, leaving 1,820 bytes for local variables. Maximum is 2,048 bytes.

No doubt a little trimming here or there could cut this down a bit, by ditching the led functions for example, but it compares quite well with any of the other Holtek libraries I tried.  I should also refactor the code for things like..   unsigned long this_radio_pin_state = !radio_pin_state; .. since this would probably be better as a bool rather than unsigned long... which saves us at least 1 byte..

sh0dan

I'd really appreciate some help if anyone can.

Unfortunately RS were out of stock but I was able to get two of the same PIR sensors (I think) from elsewhere. The chip on the back of the board says HT48R06A-1.

When running the code from https://bitbucket.org/ya_433MHz/ya_433mhz_lib I get the output copied underneath. The code does seem reliable and so far has only outputted to serial when the PIR detected motion.

I have commented in the bits of debug code but in all honestly I'm lost. I am a coder but new to Arduino and wireless communications.

Both PIR's primarily output "device 4" to serial, intermixed occasionally with other device numbers. However, device 4 is still set to "4" in the constants and it seems very unlikely "4" is the PIR's unique id. So I'm thinking that it is not working out the device id correctly for me?

Debugging indicates that "radio_packet" is definitely "4".

The only thing I am not doing is using an LED and so have commented out "pinMode(led_pin, OUTPUT)" and the contents of the two LED methods.

Here is some sample output from motion:
"
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 7
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 4
Device 2
"

And here are the device id constants:
"
const unsigned long   device1 = 271660324;
const unsigned long   device2 = 2;
const unsigned long   device3 = 3;
const unsigned long   device4 = 4;
const unsigned long   device5 = 5;
const unsigned long   device6 = 6;
const unsigned long   device7 = 7;
const unsigned long   device8 = 8;
const unsigned long   device9 = 9;
const unsigned long   device10 = 10;
"

I am happy running any diagnostic code you required and would really appreciate any responses.

Thanks!

Go Up