Go Down

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

#### grendle

##### May 14, 2013, 09:42 pmLast 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

#1
##### May 14, 2013, 09:44 pm
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

#2
##### May 14, 2013, 09:51 pm
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

#3
##### May 14, 2013, 10:20 pm
Your using 0 and 2 in the combined code not 0 and 1!

Mark

#### grendle

#4
##### May 14, 2013, 11:33 pm

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 pmLast 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

Please enter a valid email to subscribe

### Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy