Pages: [1]   Go Down
Author Topic: Arduino MEGA analog problem  (Read 427 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey, guys
I'm a noob...
so my problem is that I designed the arduino as Voltmeter by using voltage divider.
Firstly, it was ok to measure the voltage... thereafter, i wanted to try it again,
and i discovered that the value was not accurate and 0 ( such as V= 11.xxV) when even i didn't plug anything on it....
its supposed to be 0 if i haven't plug everything on it... i m wondering if the arduino is kind of broken of fried out......
plz help me...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is my code ....


int analogInput = 2;
float vout = 0.0;
float vin = 0.0;
float R1 = 50000.0;   
float R2 = 4400.0;     


int value = 0;

void setup(){
  Serial.begin(9600);

  pinMode(analogInput, INPUT);



}

void loop(){
  value = analogRead(analogInput);

  vout = (value * 5.0) / 1024.0;
  vin = vout / (R2/(R1+R2)); 

  Serial.print("Vin=");
  Serial.print(vout);



  delay(1000);
}

Logged

Maryland, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 162
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think analog ports start with A, they're just a macro that boils down to a number, so try int analogInput = A2;  (up top)
Logged

Maryland, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 162
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

also your "Serial.print(vout);" you might want to change to "Serial.println(vout);" just so it prints a newline character to the serial monitor after the number, i.e. then each reading will show up on its own line.
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 64
Posts: 6055
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Firstly, it was ok to measure the voltage...
Okay...

thereafter, i wanted to try it again,
So what changed?

Use another analog input.  If it behaves the same, you probably have something in your circuit wrong.


I think analog ports start with A, they're just a macro that boils down to a number, so try int analogInput = A2;  (up top)
Calling analogRead() with A2 or 2 results in the same pin being used. 
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the value was not accurate and 0 ( such as V= 11.xxV) when even i didn't plug anything on it....
its supposed to be 0 if i haven't plug everything on it...

No it isn't. With nothing plugged in it reads random noise.
Logged

Pages: [1]   Go Up
Jump to: