Hi.
I connected a LDR sensor to the arduino, Everything is going well, the serial in the arduino monitor is correct.
but when i listen to serial in processing the values are constantly jumping and have nothing to do with the LDR values.
Any idea what might be going wrong? My code is as follows
Arduino
int ldr;
void setup(){
Serial.begin(9600);
}
void loop(){
ldr = analogRead(A0);
Serial.println(ldr);
}
Processing
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
myPort = new Serial(this, "COM5", 9600);
}
void draw(){
background(0);
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
}
println(val);
}
And here's the serial output