arduino reliable analog input

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ohgary
 
Posts: 19
Joined: Wed Jul 24, 2013 8:08 pm

arduino reliable analog input

Post by ohgary »

I am trying to measure the voltage on one of the analog input pins on an arduino (uno or nano). With a stable constant DC supply the values I read from the port jumps all over the place. code is pretty straight forward. Is this normal? I am using a voltage divider with a couple of resistors, but also see similar issues with the voltage output from other sensors.

int volt_pin=a5
float voltage;
float l_volt;
l_volt=analogRead(volt_pin);
voltage=(l_volt/4.092)/10;

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: arduino reliable analog input

Post by adafruit_support_rick »

Have you set A5 to input?
What are you using as a voltage source?
What are you using as a reference voltage?

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: arduino reliable analog input

Post by zener »

Right. Also, could you be more specific about "jumps all over the place"? What exactly is happening? For example, it is typical for the first read to be off. Averaging is typically used. Also post you schematic.

User avatar
ohgary
 
Posts: 19
Joined: Wed Jul 24, 2013 8:08 pm

Re: arduino reliable analog input

Post by ohgary »

adafruit_support_rick wrote:Have you set A5 to input?
What are you using as a voltage source?
What are you using as a reference voltage?
I have a bench supply for the voltage.
I am using analog read so dont think I need to set A5 to input do I?
not sure about your reference voltage question

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: arduino reliable analog input

Post by adafruit_support_rick »

Have you connected the ground from the power supply to the Arduino?

User avatar
ohgary
 
Posts: 19
Joined: Wed Jul 24, 2013 8:08 pm

Re: arduino reliable analog input

Post by ohgary »

Grounds are connect together.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: arduino reliable analog input

Post by adafruit_support_rick »

If you haven't set the analog reference, then you will be using the default reference, which is 5V.
What voltage your you supplying to the pin?

Try setting the pin to input anyway.

User avatar
ohgary
 
Posts: 19
Joined: Wed Jul 24, 2013 8:08 pm

Re: arduino reliable analog input

Post by ohgary »

Zener wrote:Right. Also, could you be more specific about "jumps all over the place"? What exactly is happening? For example, it is typical for the first read to be off. Averaging is typically used. Also post you schematic.
voltage is jumping from 0-5 volts. I can read the input port 5 times and 3 radically different values.

Schematic is similar to the following
Image

MY R1 is a 10K resistor, the R2 pot is 3K. Divider was setup for 25v max, typical in my circuit is 15-18v.
both arduino ground and source ground is tied togeather, vout goes to the arduino analog port.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: arduino reliable analog input

Post by zener »

I would try hooking the input (A5) to ground and see what you read. Then hook to Vcc, which I am guessing is 5V, and see what you read. Also, can you post your entire code? Maybe there is something else in there.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: arduino reliable analog input

Post by adafruit_support_rick »

ohgary wrote:MY R1 is a 10K resistor, the R2 pot is 3K. Divider was setup for 25v max, typical in my circuit is 15-18v.
The range for the ADC is 0-5V

User avatar
ohgary
 
Posts: 19
Joined: Wed Jul 24, 2013 8:08 pm

Re: arduino reliable analog input

Post by ohgary »

adafruit_support_rick wrote:
ohgary wrote:MY R1 is a 10K resistor, the R2 pot is 3K. Divider was setup for 25v max, typical in my circuit is 15-18v.
The range for the ADC is 0-5V
Correct and the voltage divider network provides a 0-5 volt input to the micro. 25 volts into the divider gives 5v out. My 15-18v range gives me 2-3v typical voltage.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: arduino reliable analog input

Post by adafruit_support_rick »

OK - I misunderstood.

Have you verified that the voltage is stable?

User avatar
ohgary
 
Posts: 19
Joined: Wed Jul 24, 2013 8:08 pm

Re: arduino reliable analog input

Post by ohgary »

adafruit_support_rick wrote:OK - I misunderstood.

Have you verified that the voltage is stable?
My scope shows a flat DC signal.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: arduino reliable analog input

Post by adafruit_support_mike »

Just for the sake of synchronization, could you post a photo of your setup please?

In debugging, a schematic is a picture of what we think the circuit should be, but the hardware tells us what the circuit really is.

One thing to check: are you taking your 'scope input from the pin as it enters the Arduino's header? Having a broken wire inside the insulation of a jumper is a known source of colorful language.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”