arduino Serial Communication Simple read and write


This example listens for input coming in over the serial connection, then repeats it back out the same connection.

byte incomingBytes;

void setup() {                
  Serial.begin(9600); // Opens serial port, sets data rate to 9600 bps.

void loop() {
  // Send data only when you receive data.
  if (Serial.available() > 0) {
    // Read the incoming bytes.
    incomingBytes =;

    // Echo the data.