Arduino to processing

So I have a Sharp IR sensor connected to my Arduino, feeding to my pc the values of its analog input, via the Serial connection.

To do this, I'm using the Serial.write() command. I want to be able to read these values into processing, but when I use the command in Processing, the values it picks up are nothing like what the Arduino Serial monitor is giving me, and are unaffected by the IR sensor.

What am I doing wrong, and how can I get processing to read these values from the IR sensor?

Any help is appreciated.

Divide by 4

You are trying to send 10 bits (the adc on your arduino is 10 bit (0-1023)). When sending to the serial monitor, the fact that you are not sending 8-bit bytes is sorta taken care of for you. When you get to processing, those extra 2 bits (actually a second byte) is screwing everything up. The easiest solution is to divide your ADC reading by 4 to make it a byte and then send it. If you want more accuracy, you will need to receive 2 bytes on the processing side (high and low) and then put them back together into your big number. 


Chris: Thanks, will give that a go.

ChuckCrunch: got no idea. The relevant code is:

value = analogRead(A0);


Another question

How do you do the reverse?

Send data from Processing to the Arduino, to, say, control a servo with the keyboard?

works the same way

Just do serial sends from Processing and receive them in Arduino. Did you see all the examples of this from the arduino website?