Pages: [1] 2   Go Down
Author Topic: Voltage Divider & Voltmeter help  (Read 4992 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to set-up a simple voltage meter using the Arduino Duemilanove..


First I need to make the voltage divider...

I am current using a PSU to power... but am trying to use 7.4v in my equation for figuring out the math (which I set my PSU to)...  (which doesnt seem to be working)..

Im sure I have it wired up wrong smiley-cry


alternately..once past the voltage divider.. I am un-sure if I need to use a resistor on each led.. or can I combine all negative leads and use 1 resistor for the total?


(to throw a wrench in all this.. but not needed.. I was hoping to maybe use different color leds too.. which of course reds/yellows have lower vF...I believe)..

anyways.. the voltage divider first I guess...

here is what I tried before posting:


I took the LEDs out of the picture.. until I can dial in the voltage.. (at least 'close enough'..doesnt need to be perfect)


using this simple code.. I watched the serial monitor:

Code:
//voltmeter tester/PLI

int voltagePin = 5;
int voltageVal = 0;           // variable to store the value read

void setup()
{
  Serial.begin(9600);          //  setup serial
}

void loop()
{
  voltageVal = analogRead(voltagePin);    // read the input pin
  Serial.println(voltageVal);             // debug value
}


if at 7.4v. I should be getting 1023..

and as I turn down lower.. the reading/output should also adjust (lower)..

however.. I dont get a change in the reading until I am under 5v+.. (which to me says the voltage divider is set up wrong)

as always.. I tried to read what I could (and understand).. and also give it a 'try' before asking to be spoon fed!  lol

Thanks
Logged


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

Quote
I am un-sure if I need to use a resistor on each led.. or can I combine all negative leads and use 1 resistor for the total?
You need a resistor on each LED. If the LEDs share a resistor then the brightness of the LEDs will depend on how many you have on.

Quote
however.. I dont get a change in the reading until I am under 5v+..
Then you have not wired it up in the way you have shown, the values look fine, although a volt meter with an input impedance of 1K5 is a bit of a poor meter.
Logged

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Grumpy_Mike-

re: leds.

thanks.. makes sense.. as also takes care of the 'color' problem (as I can use a resistor to match that specific led's vF



re: wiring

I have +Vin (PSU +).. going to breadboard..   same row, next hole.. I have resistor (470 Ohm), in-line/same row after that second resistor leg (again same row).. I have the +Vout going to Arduino A5 pin.

still (same row) after the Vout to A5.. I have (last hole in row) 1 leg of resistor (1k Ohm)..going to another , new row.

In new row.. on 1 side of resistor.. I have -Vin lead (goes to PSU -).. on other side of resistor (same 1K Ohm) I have the -Vout to a GND pin on the Arduino


here is a different schematic.. more or less showing it how it is on the breadboard..  (maybe because Im using a BB I screwed it up?)   (yes, I know you dont like breadboards.. its all I have!)  LOL





Also.. can you dumb this up a bit?  LOL.. or maybe give an explanation?

Quote
although a volt meter with an input impedance of 1K5 is a bit of a poor meter.

Im not  sure what you mean?  in any project "I" would use this in would be a 3.7v, 4.5v, 6v or 7.4 volt (the only battery packs I really use in my hobby)..  mostly 7.4v Li-Ions.. but others have been used.

I want to light ALL leds if full juice.. and go down on the number of leds lit after that..  (reaching my cut-off/threshold)...which would leave the leds only 1 lit.

what do you mean by 'poor'?

and how do you remedy that?

thanks
Logged


Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 443
Posts: 23851
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"input impedance of 1K5 " just means your meter draws a lot of current - in this 7.4V/1500 = 5mA, could use 4.7K.10K and cut that down to 0.5mA.

7.4 to 470, to 1K to gnd. Junction of 470/1K should be 5.03V if batteries were discharged and down at 3.7V. (7.4*1K)/(.47K + 1K)
Fresh batteries will  be more like 8.4V tho, so 5.71V, dropping to ~5V when discharged.
Consider changing your R values to reflect that.
« Last Edit: October 28, 2011, 01:46:34 pm by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

You want to look at the LM3914, that does what you seem to want to do with no arduino at all.
Logged

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(stupid session timeouts...lost my whole damn post!)   grrr..


anyways..

thanks for replies.. to quickly sum up what I had origianlly typed out.

I 'do' want to use an Arduino..  (but in the end.. Im hoping to NOT take up 10 I/O pins to do so...  (maybe a shift register?..going back to my other post...kinda works for same principle?)



@CR_

man you guys are just too smart/knowledgeable on this junk!..  Its another project just to decipher the answers!  LOL


1.)  Grumpy_Mikes comment..  (the meter itself is drawing excess current)... got it!  Although I wouldnt have an clue nor cared without you guys pointing it out..

2.) I think your saying..I can cut that 'pull' of excess current down by... ??  'adding'??  additional 4.7k & 10k resistors?  (where?.. and additional?..not in place of...right?)

3.) I think your saying I should re-calculate my resistor values.. based on Vin of 8.4v and not 7.4v.......yes?  (fully charged is more at 8.4v instead of 7.4v)


Thanks
Logged


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

Quote
I think your saying..I can cut that 'pull' of excess current down by... ??  'adding'??  additional 4.7k & 10k resistors?  (where?.. and additional?..not in place of...right?)
By using resistors where you have them but making them ten times the value you have them.

Quote
I think your saying I should re-calculate my resistor values.. based on Vin of 8.4v and not 7.4v.......yes?
Yes
Logged

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(DOH!)...

ok.. so 'replace' with those values.. (I didnt even catch it was 10x the value either)..

thanks.

and then the second part.. if I re-calculate using a larger Vin..  wont those values ^^ need to change then?



I am running it from a PSU (stable Vin)  7.4V/1Amp..

So I will change out the resistors to be 4.7k & 10k respectively.. and lets me keep the draw form the 'meter' low...

but why @ a stable 7.4v from the PSU am I getting readings of 1023 from +5v - +7.4v??

Logged


Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 443
Posts: 23851
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, I was thinking you had two Li-Ion batteries, which are 3.7V x 2 = 7.4V.  Just a coincidence I guess.  Sorry about that.

If the output is a stable 7.4V, how are you getting it down to 5V?  Think we're missing something there.

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi CR_

to clarify.. in the 'end' I will be using two li-ions (7.4v)..

but until then I am using a variable PSU set at 7.4v to mimic it...

(then I am dialing the PSU down from 7.v to see the serial monitor output)
Logged


Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 443
Posts: 23851
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, then I stand by my recommendation to change the resistor values so that at 8.4V you have 5V at the resistor junction.

5V = (8.4V x 10000)/(x + 10000)

solve for x.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

Hi, I have a problem also with a arduino voltmeter/ammeter that is part of a power supply I made.
I have written all the code connected it up and it reads the volts and amps pretty accurately on an lcd.
My problem is when i connect a load to the power supply the voltage drop shown on the lcd is no where near what it reads on a multimeter. ie. if I set the voltage to say 6.00 volts connect a 3.9ohm load the lcd shows 5.8 volts where as the multimeter shows something around 5.00 volts. and doesn't drop much more with bigger loads either.
Does anyone know why this might be?
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 443
Posts: 23851
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Mostl likely a  math error in your calculation from the analogRead to the voltage you display.
Maybe mismatched variable types?

Can't really say without seeing  your code tho.

6/3.9 = 1.53846 Amp, is that being displayed correctly?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

thought the problem might be electrical but ill attatch the code for you to look at.

but I get about 1.1 amps when i do the maths there so its a little out.

cheers

Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);

// These constants won't change:
const int analogPin = A4;    // pin that the sensor is attached to
const int ledPin = 6;       // pin that the LED is attached to
const int threshold = 365;   // an arbitrary threshold level that's in the range of the analog input

int analoginput0 = 3;    //analoge pin 2
int analoginput1 = 4;    //analoge pin 5
float vout1 = 0.0;    
float vout2 = 0.0;
int value1 = 0;
int value2 = 0;
float R1 = 5100.0;    // !! resistance of R1 !!
float R2 = 2193.0;     // !! resistance of R2 !!
float vin1 = 0.0;
float vin2 = 0.0;

void setup(){
  lcd.begin (16,2);
  lcd.setCursor (5,0);
  lcd.print ("G'day");
  delay (1000);
  lcd.setCursor (6,1);
  lcd.print ("Mate");
  delay (2000);
  
    // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
   // initialize serial communications:
  Serial.begin(9600);

  // declaration of pin modes
  pinMode(analoginput0, INPUT);
  pinMode(analoginput1, INPUT);
  lcd.begin(16, 2);

}

void loop(){
  // read the value on analog input
  value1 = analogRead(analoginput0);   //voltage value
  vout1 = (value1 * 4.555)/1023.0;
  vin1 = vout1 / (R2/(R1+R2));
  

  value2 = analogRead(analoginput1);    //Amp output
  vout2 = (value2 * 4.555)/1023.0;    //4.555=voltage threshold (1023=4.555V);
  vin2 = vout2*2;  //vin2 = value2;
  
 lcd.setCursor(12,0);
  lcd.print("  ");
  lcd.setCursor(8,0);
  lcd.print(vin1+0.1);
  lcd.setCursor(8,1);
  lcd.print(vin2);

  lcd.setCursor(0,0);
  lcd.print("Volts");
 
  lcd.setCursor(0,1);
  lcd.print("Amps");
  
   // read the value of the potentiometer:
  int analogValue = analogRead(analogPin);
  
   // if the analog value is high enough, sound alarm:
 // if (analogValue > threshold)
 
   if (vin2 > 3.2)      // Set amp alarm value
  {
    digitalWrite;     //(ledPin, HIGH); //ledpin for led
    tone(7, 3);
    delay(100);
  }
    else{
     digitalWrite(ledPin,LOW);
    noTone(7);
    }

  delay(100);
}

(code symbols added by moderator)
« Last Edit: October 28, 2011, 10:55:29 pm by CrossRoads » Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 443
Posts: 23851
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why is your threshold voltage 4.555 and not 5.0?  Power supply is a little low?

vout = readvalue * 4.55/1023, okay

vout = vin *R2/(R1+R2 ) with R1 connected to Vin and R2 connected to gnd
vout*(R1+R2)/R2 = vin , okay

 This seems odd:
 value2 = analogRead(analoginput1);    //Amp output
  vout2 = (value2 * 4.555)/1023.0;    //4.555=voltage threshold (1023=4.555V);
  vin2 = vout2*2;  //vin2 = value2;   <<< where does the 2 come from?  0.5 ohm shunt to ground or something?



Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1] 2   Go Up
Jump to: