Serial Communication Between Arduinos

Hey Guys,

This seems like a very simple task, but for some reason I am having a terribly hard time with it. I am trying to initiate communication between 2 Arduinos. The master has to read an analog value from the slave, and then, based on that value, send a signal to the slave that will trip a relay. This is the code that I have already, but it is not working. Any help would be greatly appreciated.

Thanks a lot!

Greg

/**
Serial communication between 2 arduinos - Master Code
**/

int switchPin = 13;
int rxByte=0;
char rx_string[5];
int string_pos=0;

void setup()
{
Serial.begin (9600);
pinMode(switchPin, OUTPUT);
for(int i=0; i<6;i++)
{
rx_string*=0;*

  • }*

}
void read_serial()
{

  • rxByte=Serial.read();*

  • if((rxByte>=0) && (rxByte<=9))*

  • {*

  • rx_string[string_pos]=rxByte;*

  • string_pos++;*

  • }*

  • if(inByte==5)*

  • {*

  • Serial.println(rx_string);*

  • for (int u=0; u<6: u++)*

  • {*

  • rx_string=0;*
    }
    string_pos=0;
    }


    }
    void loop()
    {
    while(Serial.available())
    {
    read_serial();
    }

    }

Look at that code. Look at the code in the IDE. Do they really look the same? Use the icon with the # on it when posting code.

"It doesn't work" is pretty lame. Something happens. Something should happen. Clearly those two somethings are different, or you wouldn't have felt the need to post. But, what either of those somethings is is not at all clear.

Where is the slave code? Surely there is some...

How are the two Arduino's connected? Describe ALL connections, as best you can.