I have not used the Arduino in over 2 years and have forgotten a bunch of stuff I was wondering if someone could help me out. I have two analog sensors both the same connected to the appropriate analog pins. I am getting a read on the serial monitor and when i test the sensors the values are changing so i know the circuit is correct and everything is in the right place. I just have an issue with my code.
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue1 = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue1);
//Serial.print("val1 = " );
Serial.print(sensorValue1);
Serial.print(" ");
delay(1000); // delay in between reads for stability
// read the input on analog pin 1:
int sensorValue2 = analogRead(A1);
// print out the value you read:
Serial.println(sensorValue2);
//Serial.print("val2 = " );
Serial.print(sensorValue2);
Serial.print(" ");
delay(1000); // delay in between reads for stability
}
once i view this in the serial monitor it is not organized and the sensorvalue1 is skipping over to the next line. I would appreciate the help.
There are two sensors so there should be two values but in the picture the values are all messed up i would ideally like it to give me a two seperate values one for each sensor
val1= sensorvalue1 val2= sensorvalue2
analogRead()
doesn't happen before thedelay()
. If you switch pins with an extraanalogRead()
and throw away the value before the delay() you will get more stable readings.