0% found this document useful (0 votes)
16 views

20b - Graph Send Data To The Computer and Graph It in Processing.

Uploaded by

phuchmse183572
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

20b - Graph Send Data To The Computer and Graph It in Processing.

Uploaded by

phuchmse183572
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Graph

This example shows you how to send a byte of data from the Arduino 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 Board
 Analog Sensor (potentiometer, photocell, FSR, etc.)

Software Required
 Processing or (This software provided in course resources)
 Max/MSP version 5
Circuit
Connect a potentiometer or other analog sensor to analog input 0.
Schematic
Code
/*
Graph

A simple example of communication from the Arduino board to the computer: The value of analog input 0 is
sent out the serial port. We call this "serial" communication because the connection appears to both the
Arduino and the computer as a serial port, even though it may actually use a USB cable. Bytes are sent one
after another (serially) from the Arduino to the computer.

You can use the Arduino Serial Monitor to view the sent data, or it can be read by Processing, PD,
Max/MSP, or any other program capable of reading data from a serial port. The Processing code below graphs
the data received so you can see the value of the analog input changing over time.
*/

void setup() {
// initialize the serial communication:
Serial.begin(9600);
}

void loop() {
// send the value of analog input 0:
Serial.println(analogRead(A0));
// wait a bit for the analog-to-digital converter to stabilize after the last reading:
delay(2);
}

---------------------------------------------------------------
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:

Note: Close the serial monitor window to give the serial port for the Processing software

You might also like