Serial Communication Lab

In this lab you will learn:

  • how to get up & running with Processing
  • how to send sensor readings to Processing and have them control on-screen elements
  • how to use data from Processing to control an LED
  • how to send & receive different data types

1. Parts & Supplies:

Round ‘em up!

  • Arduino Uno
  • USB A-B cable
  • Breadboard
  • Tactile switch
  • sensors & switches of your choosing
  • LEDs
  • 330 ohm resistor
  • 10K ohm resistor
  • Potentiomenter
  • Photocell or other analog sensor
  • Hookup wire
  • Wire Strippers

2. Simple Read

On your Arduino and breadboard setup, connect a tactile switch with a 10K pull-down resistor to digital pin 4 (as pictured below):

Open Processing and go to “File” -> “Examples” -> “Libraries” -> “Serial” -> “SimpleRead”.
Scroll to the bottom of the code.
Select and copy the Arduino code.
Open Arduino.
Open a new sketch.
Paste the code from the Processing SimpleRead example. Upload it to the Arduino board.
Go back to Processing and play the Processing Simple Read Sketch. What happens?
Now try modifying the Processing code so you have different reactions to the button press. For instance, something like this:

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup()
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

void draw()
  if ( myPort.available() > 0) {  // If data is available,
    val =;         // read it and store it in val
  background(255);             // Set background to white
  rect(50, 100, 20, 50); //leg 1
  rect(130, 100, 20, 50); //leg 2
  rect(50, 80, 100, 30); //base

  if (val == 0) {              // If the serial value is 0,
    rect(70, 50, 60, 30);
  else {                       // If the serial value is not 0,
    rect(70, 60, 60, 20);

2. Graphing a sensor

Complete the following graph tutorial:
Replace the potentiometer with a new analog sensor and adjust the graph accordingly.
Change the look and behavior of the graphic program and include the results in your blog post.
Try additing a smoothing or calibration technique to your Arduino sketch and see how it affects your graph.

3. Dimmer

Now it’s time to do the reverse. Complete the following dimmer tutorial:
Once you have it up and running, try swapping a servo in for your LED and modify the Arduino code accordingly.
Include your results in your blog post.


4. Data Types

Now it’s time to think about different ways to communicate. Complete the following tutorials using sensors of your choosing:

Document your results with screenshots and notes.


5. Make your own

Working off of the last example (, modify the Processing code so that your sensors intuitively control an object on screen.