Graph

This example shows you how to send a byte of data from the Arduino or Genuino to a personal computer and graph the result. This is called serial communication because the connection appears to both the board and the computer as a serial port, even though it may actually use a USB cable, a serial to USB and a USB to serial converter.

You can use the serial monitor of the Arduino Software (IDE) to view the sent data, or it can be read by Processing (see code below), Flash, PD, Max/MSP, etc.

Hardware Required

  • Arduino or Genuino Board
  • Analog Sensor (potentiometer, photocell, FSR, etc.)

Software Required

Circuit

Connect a potentiometer or other analog sensor to analog input 0.

click the image to enlarge

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic

click the image to enlarge

Code

Processing Sketch

Using the Processing sketch in the code sample above, you'll get a graph of the sensor's value. As you change the value of the analog sensor, you'll get a graph something like this:

Max Code

The max patch looks like this. The text of the patch is in the code sample above. Copy the text and paste it into a new Max window to see the sketch.

See Also:

  • serial()
  • analogRead()

  • ASCIITable - Demonstrates Arduino's advanced serial output functions.
  • Dimmer - Move the mouse to change the brightness of an LED.
  • Midi - Send MIDI note messages serially.
  • MultiSerialMega - Use two of the serial ports available on the Arduino and Genuino Mega.
  • PhysicalPixel - Turn a LED on and off by sending data to your board from Processing or Max/MSP.
  • ReadASCIIString - Parse a comma-separated string of integers to fade an LED.
  • SerialCallResponse - Send multiple variables using a call-and-response (handshaking) method.
  • SerialCallResponseASCII - Send multiple variables using a call-and-response (handshaking) method, and ASCII-encode the values before sending.
  • SerialEvent - Demonstrates the use of SerialEvent().
  • VirtualColorMixer - Send multiple variables from Arduino to your computer and read them in Processing or Max/MSP.


Last revision 2015/07/29 by SM