2 Arduino Communication

This is what i am aiming for:

An Arduino with buttons and switches hooked up to it.
An Arduino with leds on it.

I want to have an xbee on both of the arduinos. When i press a button on the Arduino it will activate a light on the other one.

Dont take having the lights into much account because i will be using it for other stuff aswell once i get time.


That's a pretty basic setup to achieve.
The xbee's pretty much take the place of wires between the 2 arduinos - Rx to Tx, Tx to Rx -
so you can send simple messages:

Tx side:
void loop(){
if (digitalRead(button1) == LOW){ // button connects to Gnd when pressed, with internal pullup enabled
else {
Serial.print ('0');
delay (100); // forces read no more than 10 times a second for initial testing
// replace with blink without delay style reading every 100mS
} // end button read
} // end loop

Rx side:
void loop(){
If (Serial.available()>0){
incomingByte = Serial.read();
if (incomingByte == '1'){
digitalWrite (ledPin, HIGH); // assumes output drives anode high thru current limit resistor
else {
digitalWrite (ledPin, LOW); // must have been '0' that came in
} // end serial check
} // end loop

Brilliant. Thanks So Much This is really helpful.