Hi Adam,
this is a short example to switch 4 relais on and off over the serial line.
// change the pin numbers if necessary
int relais1 = 2; // relais 1 at pin 2
int relais2 = 3; // relais 2 at pin 3
int relais3 = 4; // relais 3 at pin 4
int relais4 = 5; // relais 4 at pin 5
void setup()
{
// switch pins to outputs
pinMode(relais1,OUTPUT);
pinMode(relais2,OUTPUT);
pinMode(relais3,OUTPUT);
pinMode(relais4,OUTPUT);
// initialize serial port
Serial.begin(9600); // Baud rate 9600
}
void loop()
{
// wait until a character received
if (Serial.available())
{
char c = Serial.read();
if (c == '1') digitalWrite(relais1,HIGH);
if (c == '2') digitalWrite(relais2,HIGH);
if (c == '3') digitalWrite(relais3,HIGH);
if (c == '4') digitalWrite(relais4,HIGH);
if (c == 'a') digitalWrite(relais1,LOW);
if (c == 'b') digitalWrite(relais2,LOW);
if (c == 'c') digitalWrite(relais3,LOW);
if (c == 'd') digitalWrite(relais4,LOW);
}
}
The relais must be connected to the above specified pins with a transistor or something else as amplifier (depending on the type of relais). If you load this program to the board you can switch relais 1 on and off by sending the character '1' or 'a' to the serial port (use the integrated serial monitor or hyperterminal or something else).
Use '2' or 'b' for relais 2 and so on.
Good luck
Mike