# 433mhz PIR sensor decoding / receive only.

I’m looking to modify the rcswitch library to decode this 433mhz PIR sensor i have.

looking at it in audacity, it appears to be 18 or 19bits ASK but i can’t find any info on the protocol so far.

What specific steps would i take to modify the RCswitch library so i can receive these 18-19bit messages? (not looking for tutorials on general 433mhz decoding) unless there’s a better way than using rcswitch, like modifying a specific IR decoding library that exists.

My final sketch will be a recieve only project, i don’t need to transmit the encoded message.

I attatched the encoded wav if anyone has time to help. thanks.

(note: the original wav had many more repeats of the 19bit message, i edited them out to make the file smaller)

Looking at your sample I would guess there are 18 bits of data if it’s using a fixed timebase for each bit as I have marked them on the attached image.
If you set Audacity to display the selection length as samples, set the sample rate to 48000 and highlight a section between the red lines then each bit is about 70 samples long. If you also do the selection for the durations the signal is zero then the short one (green) is about 20 samples and the long one (yellow) 50 samples. You can now calculate the pulse durations…
Each bit is 1 / 48000 * 70 = 1458uS (microseconds)
Short low is 1 / 48000 * 20 = 417uS
Long low is 1 / 48000 * 50 = 1041uS
We don’t know if the short or long low is a zero bit but this probably does not matter if your not transmitting.

Now all you need to do is receive the data (suitably conditioned) on an Arduino pin and note the duration the signal is at zero.
Wait for a start condition. If the duration is greater than 1458uS then assume it’s the signal start (the gap between repeats).
If we have a signal start then a low of about 417 will say be a 1 bit and a low of around 1041 will be a zero bit. Keep clocking in the high/low times until you have 18 bits or the low time falls outside acceptable margins (you can maybe ignore very short pulses as noise). When you have the 18 bits you can compare the number to a value your expecting and act on it.

I have code that reads non fixed duration bits but it will not work in your example but if you cannot find suitable code I will try and knock something up in my spare time.

Do you have the sketch example you made? I'd at least like to look at it to get an idea. I was really just hoping to modify an existing library with the timings, but you think there maybe isnt a library out there that could be modified easily enough?

I'm not new to arduino but I haven't done anything like this yet.

Thanks for dissecting the wav too btw. I'm still trying to find the encoder chip it uses based on what I know but there doesn't seem to be much out there.

Attached is a test sketch I used to decode a weather sensor. The sensor output different lengths for a 0 or 1 bit where your example uses the same length but different timings. I think it can maybe be modified it to suit your needs.

WeatherRF.ino (5.04 KB)

I had no luck modifying the sketch with the value ranges I received. any tips on what else i could modify within the sketch? I also changed the # of bits to 18

CorneliusBrowns:
I had no luck modifying the sketch with the value ranges I received. any tips on what else i could modify within the sketch? I also changed the # of bits to 18

I have quickly knocked up a variation on my code (attached) but I don’t have the data or time at the moment to test it so expect errors.
Hope it helps or can point you/someone in the right direction.

RF_Decode.ino (6.53 KB)

I'll try this as soon as i can. I actually gave up and reused the 433mhz Tx from the PIR sensor for another project, it was actually one of the nicer/more expensive heterodyne ones, luckily it's only 3 pins to desolder. I'll post updates. Thank you.