Go Down

### Topic: Receiving Data (Read 659 times)previous topic - next topic

#### Catcher

##### Aug 20, 2011, 02:32 amLast Edit: Aug 20, 2011, 02:36 am by Catcher Reason: 1
Hello
I have a crystal oscillator and an AM radio set up so the crystal transmits and the radio recieves. The crystal's high and low is controlled by pin 9. The AM radio goes through an envelope detector and then to analog pin 0. When analog pin 0 goes past a certain value variable A = 1, or if it goes under then variable A = 0.

My goal is to set up a system whereby I can transmit a message and receive it.

My system could probably only handle two bits per second.

One way for me to transmit data would be in binary. Change the state of pin 9 every half second to reflect the binary data.
My problem is that I'm unsure how to receive that data. I clearly see variable A changing states. I just can't put all those changing 0's and 1's back together to make a message.

Code: [Select]
`int A = 0;int B = 0;long interval = 500;long previousMillis = 0;int crystalPin = 9;int crystalState = LOW;void setup() {  Serial.begin(9600);  pinMode(crystalPin, OUTPUT);}void loop() {  //This part makes the crystal go High then Low every 0.5 seconds  unsigned long currentMillis = millis();  if(currentMillis - previousMillis > interval) {    previousMillis = currentMillis;      if (crystalState == HIGH) {      crystalState = LOW;      B = 0;    }    else {      crystalState = HIGH;      B = 1;    }  }  digitalWrite(crystalPin, crystalState);    //This part receives the Highs and Lows, 1 = High, 0 = Low  if(analogRead(A0) > 10) {    A = 1;  }  else {    A = 0;  }    Serial.print(A); //A is the value of what is received  Serial.print(" ");  Serial.println(B); //B is the value of what is transmitted. //A and B should be equal }`

The code above was just a test. According to the Serial, variable A and B have the same states all the time, which is good.

If you have a solution, a hint, or another method, please let me know.
Thanks!

#### Catcher

#1
##### Aug 20, 2011, 03:07 am
I have a new problem. I decided to let the above code run and I turned off my radio, turns out A and B still equaled each other. I unplugged the audio jack, and analogRead went haywire as it should. I plugged the audio jack back in, A = B. I took out the batteries, A = B. I unplugged the jack, A != B.

Is the 1 Mhz crystal oscillator causing analog pin 0 to fluctuate?

I narrowed it down to this wierd circuit, whereby A = B.

Original Circuit

#### PaulS

#2
##### Aug 20, 2011, 03:30 am
Quote
One way for me to transmit data would be in binary. Change the state of pin 9 every half second to reflect the binary data.

Quote
I just can't put all those changing 0's and 1's back together to make a message.

If you change the state every half second, you are not transmitting data. If you set the state every half second based on the data to be sent, you might be.

If the receiver changes state to match the transmitter, then data exchange is occurring. Each 8 bits (one bit per half second) defines a byte.

Quote
I narrowed it down to this wierd circuit, whereby A = B.

To your finger? What, now you're a radio?
The art of getting good answers lies in asking good questions.

Go Up