Why does reading an analog pin give a different results when interfacing with Processing?
You have not provided a schematic of how the Arduino is wired up.

However, if nothing is connected to the pin, i.e. it is not connected to ground or a supply voltage, then the input will float. That means that just by placing your hand near the Arduino, then analogRead() will produce a different value than when your hand in not near it.

I would hazard a guess that if you ran both sets of code multiple times then you will get different answers each time, if you start waving your hand around the Arduino.

Try that first, and then tie the input to either HIGH or LOW and then repeat the previous experiment.

In the second case the results should be consistent, and equal in the Arduino and Processing alike.



However, according to your comment, that is not your issue, as your inputs are not floating.

I think that issue is actually this:


  Even with Firmata installed, the Processing application needs to define the pin mode for ALL the pins being referenced, telling the Arduino instance that xPin, yPin, and zPin are ANALOG pins.


Source: Re: Firmata problem with analogRead in Processing Library

Looking at your Processing code the pins are not defined. You need to do so.

With the Arduino code, there is no need to define the analogue pins.