Serial Output

In preparation for the media controller project, I had to learn how to transmit serial data from Arduino to another program. For this lab, I wired up an FSR on the Arduino board, as I have several times before. The Arduino code for this exercise was very simple:

[code lang="c"]void setup()

void loop()
  int analogVal = analogRead(A0)/4;

When I opened up the serial monitor in Arduino, squeezing the FSR resulted in a long string of junk data.

This is because the FSR sends data in binary, but the serial monitor expects transmissions in ASCII, so it displays the corresponding ASCII value for the byte it receives.

I also viewed this data in CoolTerm, which displayed the information more comprehensibly in hex.

Finally, I programmed Processing to display the data graphically.

This is the Processing code that makes it possible. It draws a vertical line that corresponds to the amount of force on the FSR.

[code lang="java"]
import processing.serial.*;
Serial myPort; 

int xPos;

void setup()
  size(800, 600);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

void draw()

void serialEvent(Serial myPort)
  int inByte =;
  float yPos = height - inByte;
  line(xPos, height, xPos, height - inByte);
  if (xPos >= width) {
    xPos = 0;
    background(#0582FC);  //clear screen - reset background
  else {