Pages: [1]   Go Down
Author Topic: jumpy analog values [Solved]-thankyou  (Read 403 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}


* serial1.png (29.14 KB, 292x457 - viewed 34 times.)

* battery.png (24.27 KB, 288x455 - viewed 30 times.)

* temperature.png (23.95 KB, 286x453 - viewed 31 times.)
« Last Edit: May 14, 2013, 05:24:36 pm by grendle » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26291
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Offline Offline
Edison Member
*
Karma: 34
Posts: 1318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2299
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Mark
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.



* results.png (27.21 KB, 290x459 - viewed 24 times.)
« Last Edit: May 14, 2013, 04:38:23 pm by grendle » Logged

Pages: [1]   Go Up
Jump to: