I am trying to make a simple device where if I push a button on one Arduino, it sends a signal to the other and turns on an led. I used the Arduino Uno with an Xbee shield to do this. To program the Xbee's I followed the instructions in this video (
Tutorial 09 for Arduino: Wireless Communication ) <--- about 4 minutes in. Here is the code I used for the transmitting Arduino:
int readpin = 8;
void setup() {
pinMode(readpin, INPUT);
Serial.begin(9600);
}
void loop() {
if ( digitalRead(readpin) == HIGH)
{
Serial.println(1);
}
else
{
Serial.println(2);
}
delay(500);
}
And here is the code for the receiving Arduino.
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
while(Serial.available() == 0);
int data = Serial.read() - '0';
if ( data == 1)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
delay(500);
}
Here is a link to how I wired up both Arduinos.
https://docs.google.com/document/d/1gutGrC1MvyxaZVaXN6wNnfweBJIWJN1LM7k3FR4oq2I/editI know the first Arduino works for sure because I dismounted the Xbee shield and plugged the cable into the computer, opened up the serial terminal from the Arduino screen and I got the desired numbers when I clicked the button. I am not sure whether it is the Xbee's being configured wrong or if the code for the second Arduino is incorrect. Can anyone give me any input?