Go Down

### Topic: Fluctuating Voltage Readings (Read 4453 times)previous topic - next topic

#### zcapozzi

##### Oct 07, 2013, 04:54 am
Hi all,

My big issue is that my voltage divider circuit can read a very stable 3.3V or 5V if my power comes from the arduino power pins, but when I try to use a battery to power the circuit, the voltage readings are all over the place.  The Arduino is on USB power from my laptop if that matters.  Voltage divider circuit is using a 100K ohm and 10K ohm resistor with a wire from between them to analog  pin 0.  Any thoughts?  Is there something about batteries specifically that results in voltage fluctuations.  As you can see below, I'm taking 1000 readings and averaging the values.

The application is going to be a voltage reader connected to the  DC input for an inverter so that I can measure the voltage, and eventually current, of my loads.  I have a solar panel and I'm interested in monitoring and recording the amount of power that I actually use.

Here is the code:

#include <Bridge.h>

const int voltPin = 0;
double denominator;
double resistor1 = 100000;
double resistor2 = 10000;

void setup() {
// put your setup code here, to run once:
Bridge.begin();
Console.begin();
pinMode(13, OUTPUT);
denominator = (float)resistor2 / (resistor1 + resistor2);
Console.print("Denominator: ");
Console.println(denominator);
}

void loop() {
// put your main code here, to run repeatedly:
float total_voltage = 0;
float voltage;
//Obtain RAW voltage data
for (int i=0; i<1000; i++) {
//delay(1);
}
voltage = total_voltage / 1000;
Console.print("Raw score (0-1024): ");
Console.println(voltage);
//Convert to actual voltage (0 - 5 Vdc)
voltage = (voltage / 1024) * 5.0;
Console.println(voltage);
//Convert to voltage before divider
//  Divide by divider = multiply
//  Divide by 1/5 = multiply by 5

voltage = voltage * (resistor2+resistor1);
voltage = voltage / resistor2;

//Output to serial
Console.print("After voltage drop calculation: ");
Console.println(voltage);
Console.println("-----------------------------");
//Delay to make serial out readable
digitalWrite(13, HIGH);
delay(10000);
digitalWrite(13, LOW);
}

#### Grumpy_Mike

#1
##### Oct 07, 2013, 05:44 am
First off read the how to use the forum sticky post and correct the way you post the code.

Second when you say battery power how is it connected? Vin or power jack or 5V pin.

Next check that the grounds are connected on the arduino battery and what you want to measure. Finally a capacitor of about 0.1uF across the analogue input and ground might help.

#### cjdelphi

#2
##### Oct 07, 2013, 06:41 am
First check to see if the battery gnd is tied to arduino/usb gnd?

#### polymorph

#3
##### Oct 07, 2013, 06:57 am
It would be better to use the internal reference. By default, the Arduino uses Vcc as its reference voltage, so it will affect ADC readings if it changes.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

#### zcapozzi

#4
##### Oct 07, 2013, 02:04 pm
Thanks for the responses.  Sorry, will look into the proper code posting methods for next time.

When I'm attempting to read the battery voltages, the battery is not connected to the Arduino directly.  Instead, I've made a breadboard circuit with the resistors and a output signal voltage that comes from between the two resistors on the circuit board.  I made it this way because when I was measuring the 5V output, I had the wires going from the Arduino 5V and back to the Arduino ground.  I figured that the positive battery terminal was now my 5V pin equivalent and the negative terminal was equivalent to the gnd pin.  So in that scenario, the only connection to the Arduino would be the analog 0 input voltage.

It seemed a little odd that my output voltage wire didn't make a full circuit, but since it worked when I read the 5V, that had to be the right method.

So from the responses, I have a few questions:

- does the battery need to be connected directly to the arduino somehow?  can the analog 0 only read a voltage signal if that signal is coming from the arduino?  if that's the case, how would you send the voltage through the arduino, and if i did that, wouldn't a 9V battery fry the board?

- you mention the internal reference pin, but there is also the aref pin that can be used for external voltages.  1) what is the internal reference pin? and 2) might the aref pin be a better way to measure a voltage than analog 0?

#### alnath

#5
##### Oct 07, 2013, 03:06 pmLast Edit: Oct 07, 2013, 03:09 pm by alnath Reason: 1
A schematic of what you've actually done would help a lot

Quote
- does the battery need to be connected directly to the arduino somehow?  can the analog 0 only read a voltage signal if that signal is coming from the arduino?  if that's the case, how would you send the voltage through the arduino, and if i did that, wouldn't a 9V battery fry the board?

The arduino needs to be powered - Either with a 7V - 12V plugged inthe jack , either using USB .
You don't have to power the arduino with the battery you want to measure (in fact, you'd better not), but the GND of the measured battery and the arduino GND need to be connected together . If they are not, the Input has no GND reference.
You need to limit the voltage on the input, it must be 5V max !! If the measured voltage is supposed to be more than 5V, then use a voltage divider to keep it 5V max. Then your sketch will do the maths to give you the actual measured value .

Quote
- you mention the internal reference pin, but there is also the aref pin that can be used for external voltages.  1) what is the internal reference pin? and 2) might the aref pin be a better way to measure a voltage than analog 0?

have a look here :
http://arduino.cc/en/Reference/AnalogReference

#### jack wp

#6
##### Oct 07, 2013, 03:35 pm
Quote
You need to limit the voltage on the input, it must be 5V max !!
this could be confusing to some. I know what you mean. Just to try to make it more clear. "You need to limit the voltage on the input, it must be no more than 5V !!

#### zcapozzi

#7
##### Oct 07, 2013, 03:37 pm
Here is the schematic (attached), not sure how to put it directly into the post though.  As you can tell, this is my first real sketch and first real circuitry since college, so apologies for the lack of clarity.  Thanks very much for all the responses and questions.

- Zack

#### zcapozzi

#8
##### Oct 07, 2013, 03:42 pm
Also, I didn't mention this, but the Arduino is currently powered by USB, but eventually, it will be powered by another connection to a solar battery.

#### 68tjs

#9
##### Oct 07, 2013, 04:01 pm
There is no connection between the ground of the cell batery and the arduino.
Always think to  heating hot water: there is a Downpipe to bring water and another to return water to the boiler.
With Electricity it is the same,  electrons must move and return to the cell batery.

#### alnath

#10
##### Oct 07, 2013, 04:12 pm

Also, I didn't mention this, but the Arduino is currently powered by USB, but eventually, it will be powered by another connection to a solar battery.

It's OK, but be careful  : the yun is not like the other arduino boards !

Quote
If you are powering the board though the Vin pin, you must supply a regulated 5VDC. There is no on-board voltage regulator for higher voltages, which will damage the board.

The Yún is also compatible with PoE power supply but in order to use this feature you need to mount a PoE module on the board or buy a preassembled one.

The power pins are as follows:

VIN. The input voltage to the Arduino board. Unlike other Arduino boards, if you are going to provide power to the board through this pin, you must provide a regulated 5V.

http://arduino.cc/en/Main/ArduinoBoardYun

- you must connect the battery "-"  with an arduino GND pin
- If it was my project, I would use the DEFAULT parameter for analogReference(type) and R2 = 100kOhm  (if the battery maximum voltage is 9V  ) --> bigger difference on the Analog input between full battery and used one and easy maths in the sketch .

#### zcapozzi

#11
##### Oct 07, 2013, 04:29 pm
Thanks all for the suggestions.  It was as simple as connecting a wire to Arduino's GND.  My EE teachers would probably be ashamed of me.  I'm now able to accurately measure batteries or the 5V pin.  So thanks, it's very exciting to see the numbers you expect to see popping up on the Console.

Now back to the second topic: powering the Arduino from a battery.  My plan was to basically wire the Arduino's 5V input to a 12V battery and have the GND pin connected to the 12V negative terminal.  Now that I'm versed in voltage dividers, I had planned to use some resistor combination to make that 12V into 5V for the Arduino 5V pin.

In theory, this would power the Arduino and still leave me with enough GND pins to connect my circuit for reading the voltages that the battery is sending to my inverter.  The two questions that I have:

1. Will the Arduino need a very consistent 5V?  What if the 12V goes from 12.7V to 12.3 V.  Will that adversely impact the Arduino's ability to read?
2. Is a voltage divider the right way to do this?  I also heard mention of a PoE module, but am not sure what that is.  It sounds like regulated 5V would be enough to power the board, but I want to make sure I'm not missing something here.

I'm not sure if a schematic would help here, so let me know if there are any information gaps that I can fill.

#### alnath

#12
##### Oct 07, 2013, 04:52 pmLast Edit: Oct 07, 2013, 05:03 pm by alnath Reason: 1

Quote
1. Will the Arduino need a very consistent 5V?  What if the 12V goes from 12.7V to 12.3 V.  Will that adversely impact the Arduino's ability to read?
2. Is a voltage divider the right way to do this?  I also heard mention of a PoE module, but am not sure what that is.  It sounds like regulated 5V would be enough to power the board, but I want to make sure I'm not missing something here.

Yes, it needs a consistent 5V, especially for analogReference

No, a voltage divider is not a good way to do that, it will vary with the actual 12V value at the input side of the divider! It is not a regulator, it is a divider, which means that if your 12V comes to 14V .... chances are real that you see the magic smoke   \$)
Edit : and it may also fluctuate if the current the Arduino sinks varies significantly !!
You can use a linear voltage regulator (7805) or, even better, a switching regulator (buck dc to dc converter) . Remember : no more than regulated 5V in Vin for the Yun
PoE is Power Over the Ethernet , which means the board is powered by the ethernet cable. Yes you need a module but I don't know which one and how you wire it .

#### zcapozzi

#13
##### Oct 18, 2013, 11:28 pm
So I found this buck dc to dc converter on amazon.  It will take 12V from a car battery and output consistent 5V that I can connect to vIn and power my arduino.  great.

http://www.amazon.com/HOSSEN%C2%AE-Converter-Power-Supply-Module/dp/B00A71CMDU/ref=sr_1_2?s=automotive&ie=UTF8&qid=1382131816&sr=1-2&keywords=buck+dc+to+dc+converter+12V+to+5V

The question I have is...this converter is rated at 3A, and I believe that the Arduino YUN needs 50mA to operate.  I assume that the YUN will just pull what it needs from the battery through the converter.  In other words, it can give me at least 3A, but I'm only going to pull 50mA through it.  Is this right?  Should this converter allow me to power the Arduino from a car battery through vIn?

#### jack wp

#14
##### Oct 18, 2013, 11:53 pm
Yes, you are correct. The converter will provide a maximum of 3 amps, but if you only require (use) 50ma, that is fine.

Go Up