Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Digital Voltmeter (0-99%)

Status
Not open for further replies.
I want to make voltmeter using arduino uno and 2x 7seg display
My battery has around 9V when it is empty, and that should be 00 on display,
and 12.6V when it is full, and that should be 99 on display.
What is the easiest way to do that?
 
Use map
Description
Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.
Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The constrain() function may be used either before or after this function, if limits to the ranges are desired.
Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the map() function may be used to reverse a range of numbers, for example
y = map(x, 1, 50, 50, 1);
The function also handles negative numbers well, so that this example
y = map(x, 1, 50, 50, -100);
is also valid and works well.
Like this
Code:
Example
/* Map an analog value  (0 to 99) from 9 volts to 12.6 */
void setup() {}

void loop()
{
  int val = analogRead(0);
  val = map(val, 730, 1023, 0, 99);
  Serial.write(val);
}

should output 0 to 99 for a close 9 to 12.6 volts This outputs to the com port
 
Last edited:
Thank you !
I tried to do this with 9V battery which is 9.6V full and 5.4V empty. I am not sure about that but nevermind for now

Problem is that i have "ghost" effect on my 2 numbers and i cant figure out why. I have 2x 7 segment displays that should show 99 at 9.6V, and 0 at 5.4V
Also i use voltage divider, so my actual input voltages are 2.7 to 4.8V
Can you please help me what to change to have clear numbers? (i use 74hc595 shiftregisters)

Code:
void loop() {
  
  int val = analogRead(5);
  val = map(val, 550, 982, 0, 99);
  first = val/10;
  second = val%10;
   
  digitalWrite(seg1, LOW); digitalWrite(seg2, HIGH);
  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, MSBFIRST,br(first)); 
  digitalWrite(latchpin, HIGH);
  delay (10); digitalWrite(seg1, HIGH); digitalWrite(seg2, HIGH);
  
  digitalWrite(seg1, HIGH); digitalWrite(seg2, LOW);
  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, MSBFIRST,br(second));
  digitalWrite(latchpin, HIGH);
  delay (10); digitalWrite(seg2, HIGH); digitalWrite(seg1, HIGH);

And aditional question, how can i "take" analogRead(5) not every ms or even faster but for example every 1000ms? If i put after that delay(1000); it takes it every 1sec, but also slowes down whole program
 
Last edited:
You can use a millis and and just check it for 1000 ms roll overs. Ad to stop ghosting turn on the seven segment after the write to it new data out set shiftreg light digits data change digits off load new data digit on.
 
Can you please explain me a little bit easier? I am not best in programming and because of that i dont understand that easy :)
Can you add that peace of code please?
 
The ghosting is because your not blanking the display. See you write to the shiftreg then turn on the display. Your code has them on when you do a update.

Like this
Code:
digitalWrite (seg1, low); digitalWrite(seg2,low):
shiftOut //data here
digitalWrite (segX,High); //desplay your data here
digitalWrite (seg1, low); digitalWrite(seg2,low)://turn them off to load new data
shiftOut // new data here
digitalWrite (segX,High);//desplay your data here
 
The ghosting is because your not blanking the display. See you write to the shiftreg then turn on the display. Your code has them on when you do a update.

Like this
Code:
digitalWrite (seg1, low); digitalWrite(seg2,low):
shiftOut //data here
digitalWrite (segX,High); //desplay your data here
digitalWrite (seg1, low); digitalWrite(seg2,low)://turn them off to load new data
shiftOut // new data here
digitalWrite (segX,High);//desplay your data here

About ghosting you were absolutely right :)
I have corrected it now, and it is good now. Ill try to slow down refresh rate now, then it will be finished project :)

Everything works perfectly now, thanks to you !
Ill post some pictures or videos as soon as i solder this together (it is all on breadbord for now)
 
Last edited:
I have solder it together and something really wierd is happening :D

The same 75hc595 on breadbord IS working well and on my soldered board isnt :S

I have checked pins, and pin 8 and 10 are connected to ground and pins 13 and 16 are connected to +5V. Input pins are connected like on breadbord and on all otput pins is 0V, when on pin 6 should be +5V (and it is, on the same chip on the breadbord). So what can be wrong with this? :D
 
Post a sch and a good picture. And did you put a .01 uf cap on the power pin.
But most likely a bad solder joint.
 
No i didnt put it. But on my breadbord version it is working. I dont have a scheme, but i can explain it to you, it is easy

I have common catode led display (2 of them with 2 digits ,4 digits all together). Segment pins of them are connected through 1k resistors to outputs of first 74hc595. Outputs of second 74hc595 are connected to 4 "grounds" of displays which when are LOW are active, and that digit shows..
So the difrent from the breadbord version is that here i have 2x 74hc595, and 3 output pins from arduino and on breadbord i have 5 outputs from arduino. Ill post a picture but it is really messed up :D

20130331_163252.jpg
20130331_163503.jpg
20130331_163441.jpg
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top