help on connecting 2 arduinos

i´m trying to connect 2 arduinos, and i need some help to achieve this

for example:

press a button on one arduino and light an led on the other

or

using a potenciometer connected to one arduino and make a led light on the other arduino

any help would be much apreciated

I think the easiest way to do this is using the serial to connect them (i'm actually doing this over RS-485, one "master" Arduino controlling some "slaves" (Arduinos too). I suggest you to create some kind of communication protocol, i.e. you read digital inputs of one arduino, when one of them is actuated (by a press on an push-button, maybe?) send over serial (in ascii) "D41", that can mean "D"igital input number "4" actuated ("1")... the other Arduino receive this message and based in your programmed logic do an digitalWrite(4, HIGH), powering an led... for the pot, same logic... send the analogRead value, the other Arduino will decide what to do based in what you programmed.

Maybe some confuse text, but i think it's understandable... ::)

hi celsoffraga, thanks for helping, your text is very understandable and i can´t wait to try it

just tell me how should i connect the arduinos, i know that Tx goes to Rx and Rx goes to Tx... should i connect 5v and GND also?

will post results soon :)

In fact you just need to connect GND between the two boards (NEVER interconnect +V of different power sources). Unless you want to use only one power supply and power the "remote" Arduino from the local one. That's the way I use mine, a "master" unit, with power supply, and the "slaves", that are all interconnected over an 4-wire RS-485 network (+V, A, B, GND). This way I can have them up to 1200 meters away... so far away than the standard 5~15 meters of RS-232 (even less using only TTL signals).

Best regards, Celso Fraga.

sorry to ask this but.. can you explain how do i code the send and the recieve stuff??

Yeah, of course.

For the sender, the basic of the basic will be a lot of pieces of code like this:

if ( !digitalRead(2) ) // 2 is the pin where the push-button is tied to, don't forget pull-up resistor. Just change pin nuber as you need. { Serial.print("D21") // "D"igital pin "2" actuated }

In the receiver:

if ( Serial.available() == 3 ) { kindof = Serial.read(); addressof = Serial.read(); valueof = Serial.read(); flagrcvdata = 1; }

if ( flagrcvdata && kindof == "D" ) // enter here if complete data packet received and is an digital reading { digitalWrite(addressof, valueof); flagrcvdata = 0; }

Of course, this is not the most elegant or pro-like way for code this, but from here you can figure out the way it will do what you need. You will probably want to add some kind of header and better control in the serial part of it.

Don't forget that you may will need to add some delay between readings, otherwise you will fill the RX serial buffer faster than you will could process it.

Hope have helped.

Thanx a lot for helping me Celso!!

I still can´t make this work and i´m trying to understand why!!

I´ve been reading this post also http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1165325319 and i´m having the same problem as Pinky had!

I´ll make more attempts and post feedback soon :)

Best Regards!!