Processing returning 0, but arduino works.

Hi, i managed sucessfully to connected both arduino and processing.I was getting results on my graph , but i tried to organize stuff,and i change some suff on the sketchbook, now everytime i run my processing code i dont any result.
I have no idea how to fix, some insight on how it works would help.

Arduino serial monitor says like: 165, 167, 167, etc…
Programming graph return : 0, 0, 0, 0, … Arduino serial monitor Processing result

ArduinoSketch Code

int sensorValue;

void setup()
  Serial.begin(9600);      // sets the serial port to 9600

void loop()
  sensorValue = analogRead(0);       // read analog input pin 0
  Serial.println(sensorValue, DEC);  // prints the value read
  delay(500);                        // wait 100ms for next reading

Processing Sketch Code

import processing.serial.*;
import cc.arduino.Arduino;

Arduino arduino;
PFont font;
int xPos=0;
boolean firstLoop = true;
String arduinoPort = "COM4";

void setup(){
  String ports[];
  ports = Arduino.list();
  for(int i=0;i<ports.length;i++) {
      if (ports[i].equals(arduinoPort)) {
	  arduino = new Arduino(this, ports[i]);
  if (arduino == null) {
      throw new RuntimeException("could not find Arduino port");

  font = loadFont("MinimaSSK-96.vlw");
  textFont(font, 48);


void draw(){
    if (firstLoop) {
	firstLoop = false;

    int value = arduino.analogRead(0);
    int yPos = (int)map(value, 0, 1023, height, 20);

    if (xPos > width) {
	rect(min(xPos+30, width-100), max(yPos-70, 0), 100, 45);
	xPos = 0;

    fill(30, 5);
    rect(0, 0, width, height);

    rect(xPos, 1, 160, height-2);
    rect(min(xPos+30, width-100), max(yPos-70, 0), 100, 45);

    plot(xPos, yPos, value);

    text(""+value, min(xPos+30, width-100), max(yPos-30, 40));

    rect(0, 0, width-1, height-1);


void plot(int x, int y, int value) {
    fill(255, map(value, 0, 1023, 255, 0), 0);
    ellipse(x, y, 30, 30);
    int value = arduino.analogRead(0);

This statement implies that the Arduino is supposed to be running a Firmata sketch. It isn't, so it's no wonder that the result is incorrect.

Thanks bro, i uploaded the StandardFirmata from the example and ran processing and now everything works :smiley:
But where is my code for the sensor now, i coulndt get my head around this.
I have the code for the sensor the firmata one and one for the graph in processing.
If i upload the firmata code after my sensor code on arduino dont it get lost?

Didn't help but thanks for wasting my time too

Yes, it gets overwritten. But, the StandardFirmata code turns the Arduino into an idiot. That's what Processing is expecting. It sends a command to the Arduino, telling it to return the value of the analog or digital pin that Processing needs the value of. The Arduino responds in the correct way, after calling the same function your sketch calls.

Thanks, i don't get the quote but, definitely helped me.