Decoding an RF signal using the pulseIn method and nested ifs

Hi. I'm trying to decode an rf433 signal from a thermo sensor, which periodically sends the signal every 43 seconds. For starters, I am only trying to find the preamble. I know the format of the protocol (FM0 encoding, encoded bit 0 duration is 0.48ms and 1 is 0.97ms).

I tried decoding the signal like somebody else already did, but I only get, successfully, to the 7th pulse, and it never went beyond that.

Now I don't know what is the reason I can't get past the seventh pulse. I speculate it is one of the two: * I am receiving some interference and I fear, this prevent's all of the nested if's from executing * Arduino's speed (could it be possible, that arduino is to slow?)

Could there be another reason? I tested with the transmitter and receiver 3 cm apart.

Thanks in advance for your help.

  1. Your receiver will receive random noise when no signal is present. All 433mhz RF receivers do this normally. If your receiver is based on the SYN470, you can squelch the noise with a 5 megaohm (yup, 5 meg) resistor from CTH (physical pin 7) to Vcc - this will get rid of most of the noise - this is very useful for figuring out protocols, though it does reduce range.

When I do receiving, I don’t try to use pulsein (although it should be a perfectly viable method, probably better) - I do it with micros() and a loop() that does nothing other than monitor the RF pin when it’s got a message incoming.


byte rxing=0;

void loop()
if (rxing==0) {
//rest of loop - don’t run if we’ve seen the start of a message, and don’t abuse delay(), since it won’t receive while in delay().

and in doListen(), I just track the pin state blink-without-delay style with micros(), and set rxing=1 when I see something that looks like the start of a message.

Here’s what I did for my custom RX/TX code (it uses my own protocol, ofc, but it might be useful since you’re making a receive routine for a mostly-known protocol):

That said, your problem is quite likely a bug in your code, which you haven’t posted. If you post your code, we might be able to point out the problem.

I didn't post the code, because it is written in the same way as in the posted link above. I tried playing around some more with the intervals for detection of 1's and 0's, and the sketch detected the preamble 2 times so far.

I noticed another thing. The preamble is 111110010. Sometimes the receiver prints that the 7th pulse of the signal was reached 3 times (which is Ok, because it probably repeats the signal 3 times).When it does that (or the two times it detected the whole preamble), the arduino's rx light blinked, otherwise it doesn't (even when the thermo unit blinks (transmits the signal).