Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple Arduino Serial Communication with Echo of line
* Author: Domenico Monaco
* Description: Simple Arduino Serial communication, with echo of entire line received.
* Source:
* License: GNU v2 2014
int incomingByte = 0; // for incoming serial data
bool waiting = false;
String line = "";
void setup() {
void loop() {
if (Serial.available() > 0) {
waiting = false; // Set to false, Arduino not in "Waiting" state but are in "Reading" state
incomingByte =; // read Char
line = line + (char)incomingByte; // add Char to line
delay(1); //Delay of Serial transfer speed
//waiting is False only after "reading" state
//with this line are printed only one times into "waiting" state
waiting = true;
// print entire line
Serial.print(" ");
line = ""; // Resete line
Serial.println("Waiting for a message...");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.