Go Down

Topic: jumpy analog values [Solved]-thankyou (Read 450 times) previous topic - next topic

grendle

May 14, 2013, 09:42 pm Last Edit: May 15, 2013, 12:24 am by grendle Reason: 1
hi all,
quick questions, running a sensor on analog0, and a coin cell on analog1, and then on analog2. both sharing the same ground, when run by themselves i get correct values. when i run them in the same sketch i get jumpy and incorrect values? any ideas? serial monitor pics enclosed.

Code: [Select]

float battery;
float temperature;
float b;
float a;
void setup(){
 Serial.begin(115200);
}
void loop(){
 b=0;
 a=0;
 battery=0;
 temperature=0;

 battery=analogRead(0);
 b=battery/1023*5.0;
 Serial.println(b);
 delay(100);
 get();
}
void get(){
 temperature=analogRead(2);
 a=(5.0*temperature*100.0)/1023.0;
 Serial.println(a);
 delay(1000);
}


AWOL

Try two readings each time you do an analogRead, and chuck the first one away.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DVDdoug

Quote
Try two readings each time you do an analogRead, and chuck the first one away.
Right... There is really only one analog-to-digital converter in the chip, and the analog inputs are multiplexed (switched).    I haven't studied the timing-diagrams, but it takes some time to process & "settle".

holmes4

Your using 0 and 2 in the combined code not 0 and 1!

Mark

grendle


Your using 0 and 2 in the combined code not 0 and 1!

Mark


yes i was trying it both ways right now the sensors are on 0, 2.

grendle

#5
May 14, 2013, 11:35 pm Last Edit: May 14, 2013, 11:38 pm by grendle Reason: 1

Try two readings each time you do an analogRead, and chuck the first one away.

ok thx im gnna try this now

this looks like its working the values are more consistent now. thank you guys.


Go Up