433mhz *RECEIVER* arduino - How to deal with interferance?

Huzzah!

Thanks for all the help everyone!

I have yet to reach the goal of my journey, but now I can see a path through the forest, and stepping stones across the river, and there is a light in the darkness.

#define ListenST 1
#define rxpin 19

int lastPinState;
unsigned long lastPinHighTime;
unsigned long lastPinLowTime;;
unsigned long lastTempHighTime=0;
unsigned long lastTempLowTime=0;
unsigned long rxdata;
int lastTempPinState;
int bitsrx;
int rxing;
int MyState;
unsigned long curTime;

void setup() {
        lastPinState=0;
        lastPinLowTime=0;
        lastPinHighTime=0;
        rxdata=0;
        bitsrx=0;
        rxing=0;
        MyState=2;
	Serial.begin(9600);
}

void loop() {
        curTime=micros();
	onListenST();
}

void onListenST() {
	int pinState=digitalRead(rxpin);
	        if (pinState==lastPinState) {
		return;
	} else {
              lastPinState=pinState;
        }
	if (pinState==0) {
		lastPinLowTime=curTime;
		unsigned long bitlength=lastPinLowTime-lastPinHighTime;
                //Serial.println("bitlength:");
                if (bitlength < 1400 && bitlength > 600) {
                  //Serial.println(bitlength);
                }
		if (bitlength > 1500) {
			//bogus bit
                        // Serial.println(bitlength);
			resetListen();
			return;
		} else if (rxing==1) {
                        //Serial.print("Receiving");
                       // Serial.println(bitlength);
			if (bitlength > 575 && bitlength < 750) {
				rxdata=rxdata<<1;
				Serial.print("F");
                                Serial.println(bitlength);
			} else if (bitlength > 1200 && bitlength < 1350 ) {
				rxdata=(rxdata<<1)+1;
				Serial.print("T");
                                Serial.println(bitlength);
			} else {
				//Serial.println(bitlength);
				resetListen();
				return;
			}
			bitsrx++;
			if (bitsrx==8) {
				Serial.println("Got 8 bits");
				Serial.println(rxdata);
				resetListen();
			}
			return;
		}   
	} else {
		lastPinHighTime=curTime;
                if (lastPinHighTime-lastPinLowTime > 1900 && lastPinHighTime-lastPinLowTime <2100) {
		  //Serial.println("Starting");
                  rxing=1;
                  return;
                }
		if (lastPinHighTime-lastPinLowTime > 700 && rxing==1) {
                        //Serial.print("oddly long delay during rx");
		        //Serial.println(lastPinHighTime-lastPinLowTime);
			resetListen();
			return;
		}
	}
}

void resetListen() {
        //Serial.print("end");
	bitsrx=0;
	rxdata=0;
        rxing=0;
}
    var txpin=A1;

function sendTest2() {
  	for (i = 0; i < 20; i++) {
    	digitalPulse(txpin,1,0.5); 
    	digitalPulse(txpin,0,0.5); 
    } 
    digitalPulse(txpin,1,0.5); //end training burst
    digitalPulse(txpin,0,2);   //sync
    digitalPulse(txpin,1,0.7); //send a 0
    digitalPulse(txpin,0,0.5); //pause
    digitalPulse(txpin,1,1.3); //send a 1
    digitalPulse(txpin,0,0.5); //pause
    digitalPulse(txpin,1,0.7); //send a 0
    digitalPulse(txpin,0,0.5); //pause
    digitalPulse(txpin,1,1.3); //send a 1
    digitalPulse(txpin,0,0.5); //pause
    digitalPulse(txpin,1,1.3); //send a 1
    digitalPulse(txpin,0,0.5); //pause
    digitalPulse(txpin,1,0.7); //send a 0
    digitalPulse(txpin,0,0.5); //pause
    digitalPulse(txpin,1,1.3); //send a 1
    digitalPulse(txpin,0,0.5); //pause
    digitalPulse(txpin,1,1.3); //send a 1
    digitalPulse(txpin,0,0.5); //pause
  	digitalPulse(txpin,0,0);
    digitalWrite(txpin,0);
}

Basically, at this point, I've got it recognizing the test pattern and printing the correct data out.

Next, I need to extend it to more data (I think I need 32 bits including some sort of checksum), make the method of sending the signals not totally suck (lol 86 jsvars to send an 8 byte test signal) , and then it's just a matter of processing the commands....

And I guess I'll eventually need to fab the boards and stuff... but that's all easy stuff.

You earned those wings. :slight_smile:

DrAzzy:
I need to extend it to more data (I think I need 32 bits including some sort of checksum)

You would want a checksum, but it does not have to be fancy. The 8 bit sum or XOR of the other bytes or something would be just fine. There are plenty of CR8 implementations around though -- one in the OneWire library, for example. Finding one for the javascript side is likely feasible.

Forward error correction is a useful feature, since the 433 MHz band is full of noise and crud. A good way to do this is to just send the same exact message 3 or 5 times. The receiver then keeps the zero/one counts seen for each bit position in the message. After the whole frame is received, reconstruct the message by taking the majority value for each bit position.

The simple implementation uses a bit of RAM, but you could likely get it down to 4 bits of buffer per message bit, by counting up/down and keeping the 4-bit (-8..+7) count two to a byte.

You would do checksum checking after the forward error correction.

This stuff also lets you make a software assessment of signal quality -- maybe your application can make use of knowledge that the signal, although usable, is not great.