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.
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!