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;
arduino reliable analog input
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: arduino reliable analog input
Have you set A5 to input?
What are you using as a voltage source?
What are you using as a reference voltage?
What are you using as a voltage source?
What are you using as a reference voltage?
- zener
- Posts: 4567
- Joined: Sat Feb 21, 2009 2:38 am
Re: arduino reliable analog input
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.
- ohgary
- Posts: 19
- Joined: Wed Jul 24, 2013 8:08 pm
Re: arduino reliable analog input
I have a bench supply for the voltage.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 am using analog read so dont think I need to set A5 to input do I?
not sure about your reference voltage question
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: arduino reliable analog input
Have you connected the ground from the power supply to the Arduino?
- ohgary
- Posts: 19
- Joined: Wed Jul 24, 2013 8:08 pm
Re: arduino reliable analog input
Grounds are connect together.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: arduino reliable analog input
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.
What voltage your you supplying to the pin?
Try setting the pin to input anyway.
- ohgary
- Posts: 19
- Joined: Wed Jul 24, 2013 8:08 pm
Re: arduino reliable analog input
voltage is jumping from 0-5 volts. I can read the input port 5 times and 3 radically different values.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.
Schematic is similar to the following
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.
- zener
- Posts: 4567
- Joined: Sat Feb 21, 2009 2:38 am
Re: arduino reliable analog input
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.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: arduino reliable analog input
The range for the ADC is 0-5Vohgary 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.
- ohgary
- Posts: 19
- Joined: Wed Jul 24, 2013 8:08 pm
Re: arduino reliable analog input
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.adafruit_support_rick wrote:The range for the ADC is 0-5Vohgary 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.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: arduino reliable analog input
OK - I misunderstood.
Have you verified that the voltage is stable?
Have you verified that the voltage is stable?
- ohgary
- Posts: 19
- Joined: Wed Jul 24, 2013 8:08 pm
Re: arduino reliable analog input
My scope shows a flat DC signal.adafruit_support_rick wrote:OK - I misunderstood.
Have you verified that the voltage is stable?
- adafruit_support_mike
- Posts: 67446
- Joined: Thu Feb 11, 2010 2:51 pm
Re: arduino reliable analog input
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.
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.
Please be positive and constructive with your questions and comments.