Try these.
Master:
void setup()
{
Serial.begin(9600);
delay(1);
Serial.println("Transmitting");
}
void loop()
{
Serial.print('H');
delay(1000);
Serial.print('L');
delay(1000);
}
Slave: Keep in mind you will need to use Software serial if you want to use the Serial monitor, to see the received char.
char val; // variable to receive data from the serial port
int ledpin = 13; // LED connected to pin 13 (on-board LED)
void setup() {
pinMode(ledpin, OUTPUT); // pin 13 (on-board LED) as OUTPUT
Serial.begin(9600); // start serial communication at 115200bps, must match the transmitting side
delay(1); // 1 millisecond delay between starting the serial communication and sending out a message
Serial.println("Receiving");
}
void loop()
{
if( Serial.available() > 0) //See if data is available to read
{
val = Serial.read();
Serial.println(val);
if( val == 'H' || val == 'h' ) // if 'H' was received
{
digitalWrite(ledpin, HIGH); // turn ON the LED
}
if( val == 'L' || val == 'l' )
{
digitalWrite(ledpin, LOW); // otherwise turn it OFF
}
}
}
Make sure the Serial monitor is set to 9600, otherwise you will see garbage in the terminal.
EDIT:
On second thought, they might need to be set to 9600, as per the default baud rate. I changed them.