Pages: [1]   Go Down
Author Topic: Fluctuating Voltage Readings  (Read 930 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
  Console.println("Reading voltages...");
  for (int i=0; i<1000; i++) {
    total_voltage += analogRead(voltPin);
    //delay(1);
  }
  voltage = total_voltage / 1000;
  Console.println("Done reading voltages...");
  Console.print("Raw score (0-1024): ");
  Console.println(voltage);
  //Convert to actual voltage (0 - 5 Vdc)
  voltage = (voltage / 1024) * 5.0;
  Console.print("Actual Reading: ");
  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);
}

Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 34502
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 30
Posts: 2483
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First check to see if the battery gnd is tied to arduino/usb gnd?

Logged

Lacey, Washington, USA
Offline Offline
Edison Member
*
Karma: 162
Posts: 2437
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Steve Greenfield AE7HD
CET Consumer Electronics and Computer
Please don't read your attitudes into my messages

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

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

Offline Offline
God Member
*****
Karma: 16
Posts: 601
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A schematic of what you've actually done would help a lot  smiley


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
« Last Edit: October 07, 2013, 08:09:04 am by alnath » Logged

Texas
Offline Offline
Edison Member
*
Karma: 25
Posts: 1298
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Good luck, Jack

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

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


* Battery Measurement.png (4.27 KB, 176x243 - viewed 25 times.)
Logged

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

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

IDF/SO
Offline Offline
Edison Member
*
Karma: 41
Posts: 2273
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
God Member
*****
Karma: 16
Posts: 601
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

about your schematic:
- 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 smiley-wink .
Logged

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

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

Offline Offline
God Member
*****
Karma: 16
Posts: 601
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-cool

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 smiley-wink

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   smiley-money
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  smiley-mr-green
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 smiley-wink.
« Last Edit: October 07, 2013, 10:03:51 am by alnath » Logged

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

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

Texas
Offline Offline
Edison Member
*
Karma: 25
Posts: 1298
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you are correct. The converter will provide a maximum of 3 amps, but if you only require (use) 50ma, that is fine.
Logged

Good luck, Jack

Pages: [1]   Go Up
Jump to: