Serial Communication

In this project, you'll learn how to use serial communication for two Arduino boards to talk to each other.

Parts needed:
  • Two Arduinos
  • One wire
Software stuff you'll learn:
1 Making the connections
  • Label one Arduino the sender and the other Arduino the receiver.
  • Connect pin 7 on the sender Arduino to pin 8 on the receiver Arduino.
  • Connect one Arduino to one computer with the regular USB cable.
  • Connect the other Arduino to a second computer with the regular USB cable.
Serial connection between two Arduinos
2 Type in and upload this sender program to the SENDER Arduino
// This is the Serial SENDER code
// Connect pin 7 on this Arduino to pin 8 on the receiver Arduino

#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7); // RX, TX

void setup() {
  mySerial.begin(9600); // begin software serial
}

void loop() {
  static char c = ' '; // starting character is a space
  mySerial.write(c);   // send out the character
  c++;
  delay(1000); 
}
3 Type in and upload this receiver program to the RECEIVER Arduino
// This is the Serial RECEIVER code
// Connect pin 8 on this Arduino to pin 7 on the sender Arduino

#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9); // RX, TX

void setup() {
  Serial.begin(9600); // hardware serial for output to monitor
  mySerial.begin(9600); // begin software serial
}

void loop() {
  if (mySerial.available()) { // if there is a byte
    char c = mySerial.read(); // read in the character
    Serial.write(c);          // display the character on the monitor
  }
}
4 Open up the serial monitor on the receiver Arduino. Set the baud speed to 9600. Press the reset button on the sender Arduino to start sending from the beginning. You should see the characters that are being received from the sender Arduino.