/* contact plate graph A simple communication from the Arduino board to the computer: the value of analog input 3 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. The circuit: Any analog input sensor is attached to analog in pin 3. created 2015 by Matt Vercelletto */ void setup() { // initialize the serial communication: Serial.begin(9600); Serial.println(analogRead(A3)); } void loop() { // send the value of analog input 3: Serial.println(analogRead(A3)); // wait 10 ms for the analog-to-digital converter // to stabilize after the last reading: delay(10); } // Processing code for this example below: // Must be run in Processing, an external program free to download online // Graphing serial data from arduino analog input 3 // This software takes ASCII-encoded strings // from the serial port at 9600 baud and graphs them. It expects values in the // range 0 to 1023, followed by a newline, or newline and carriage return // Created 20 Apr 2005 // Updated 30 Oct 2015 /* import processing.serial.*; Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph float inByte; int lastxPos=1; // draw continuous line int lastheight=0; void setup () { // set the window size: size(800, 600); // List all the available serial ports, for Processing 2.1 and on only printArray(Serial.list()); // Open whatever port printArray says is the one you're using. myPort = new Serial(this, Serial.list()[2], 9600); // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); // set inital background: background(0); } void draw () { // draw the line: // everything else happens in the serialEvent() stroke(127,34,255); //stroke color strokeWeight(3); //stroke wider line(lastxPos, lastheight, xPos, height - inByte); if (xPos >= width) { xPos = 0; // clear screen at end background(0); } else { // increment the horizontal position: xPos++; } } void serialEvent (Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); if (inString != null) { // trim off any whitespace: inString = trim(inString); // convert to an int and map to the screen height: float inByte = float(inString); inByte = map(inByte, 0, 1023, 0, height); // draw continuous line lastxPos= xPos; lastheight= int(height-inByte); // at the edge of the screen, go back to the beginning: if (xPos >= width) { xPos = 0; background(0); } else { xPos = xPos; } } } */