May 25, 2016

Interact with Arduino through serial

In this post I will show how to use the USB serial interface to issue commands and retrieve output from an Arduino board. The main goal of this project is to build a simple interface to use Arduino as a 'sensors hub' and integrate it with other more complex devices like Raspberry PI or and PC.

Now plug your Arduino board to the PC and upload the following sketch.

int PIN_LED = 13;

void setup()
  pinMode(PIN_LED, OUTPUT);

  Serial.println("Welcome to ArduinoSerialControl");
  Serial.println("Enter 't' to retrieve current millis");
  Serial.println("Enter 'l' to toggle LED on pin 13");

void loop()
  int bytes=Serial.available();
  if (bytes > 0)
    char c =;
    switch (c)
    case 't':
      // return the uptime in milliseconds
    case 'l':
      // toggle on-board led connected to pin 13
      digitalWrite(PIN_LED, !digitalRead(PIN_LED));
      Serial.print("LED status is ");

Open the serial monitor and set the baud rate to 9600. Try sending commands using the serial console.

This is just an experiment. If you want to build a solid communication using Firmata protocol.

Complete Control Of An Arduino Via Serial