How to make a DC Voltmeter with Arduino & Seven Segment Display

Published by MKDas on

A DC volt meter is very common in electronics and need to use in many systems as well. In this article, we are going to learn how to make a DC voltmeter with Arduino and Seven Segment display. If you learn this carefully, you’ll be able to make voltmeter of any voltage range.

Disclaimer: Electricity is always dangerous. Skill required to work with electricity. Do work with your own risk. Author will not be responsible for any misuse or harmful act. This website contents is also copyright protected. Anything copied and directly posted in your website and claiming it as yours is prohibited and nonsensical. Author published all the articles as opensource to help you making your project and learning purpose only. Learn and make one for yourself. If need any help feel free to ask the author. Author will be helpful to you. Thanks.

Basic part of a voltmeter:

A voltmeter have a sensing components or device and a display to show the reading. Sensing components may consists of resistor voltage dividers, Analog to Digital Converter (ADC) and other associated devices. For a low range voltmeter, we can use resistor voltage divider with capacitor filters. Then we can sense the low voltage across resistor and calculate the input voltage using voltage divider rules.

Example resistor voltage divider circuit

This is a resistor voltage divider circuit for the voltage sensing purpose which will be used in our project. Here, C1 works as a noise filter here. If any noise is present in the sensing line, we can not detect exact voltage or our reading may result in error. That is why we always need to use a capacitor as noise filter.

As the display, we can use LCD display or Seven Segment displays. In this project we’ll use Seven Segment display.

Circuit diagram:

Circuit diagram

Arduino Coding:

#include <TimerOne.h>
const char segment_pins[] = {13, 12, 11, 10, 9, 8, 7, 6}; //segments a to g
const char digit_pins[] = {5, 4, 3, 2}; // 4digits
const int digit_number = 4;//for 4 digit segment
byte dot_position;//set dot position from right side.
bool dot_point = true; // having dot or not, true = have dot, false = no dot.

const int segment_array[10][8] = // for common cathode segment only
{
  {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW, LOW}, //0
  {LOW, HIGH, HIGH, LOW, LOW, LOW, LOW, LOW},     //1
  {HIGH, HIGH, LOW, HIGH, HIGH, LOW, HIGH, LOW},  //2
  {HIGH, HIGH, HIGH, HIGH, LOW, LOW, HIGH, LOW},  //3
  {LOW, HIGH, HIGH, LOW, LOW, HIGH, HIGH, LOW},   //4
  {HIGH, LOW, HIGH, HIGH, LOW, HIGH, HIGH, LOW},  //5
  {HIGH, LOW, HIGH, HIGH, HIGH, HIGH, HIGH, LOW}, //6
  {HIGH, HIGH, HIGH, LOW, LOW, LOW, LOW, LOW},    //7
  {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW},//8
  {HIGH, HIGH, HIGH, HIGH, LOW, HIGH, HIGH, LOW}, //9
};


void int_sev_segment()
{
  for (int k = 0; k < 8; k++)
  {
    pinMode(segment_pins[k], OUTPUT);//I/O settings
  }
  for (int k = 0; k < digit_number; k++)
  {
    pinMode(digit_pins[k], OUTPUT);//I/O settings
  }
  for (int k = 0; k < 8; k++)
  {
    digitalWrite(segment_pins[k], LOW);//keep low
  }
  for (int k = 0; k < digit_number; k++)
  {
    digitalWrite(digit_pins[k], HIGH);//keep high = disable segments (CC)
  }
  Timer1.initialize(5000);//5000us = 5ms
  Timer1.attachInterrupt(display_segment);
}


char digits[5];
void display_7segment(int number, byte dot)
{
  digits[3] = number / 1000u;//extract 1000th digit
  digits[2] = (number / 100u) % 10u;//extract 100th digit
  digits[1] = (number / 10u) % 10u;//extract 10th digit
  digits[0] = (number / 1u) % 10u;//extract 1st digit
  dot_position = dot;
}


int digit_position = 0;
void display_segment(void) // called periodically using timer interrupt
{
  for (int k = 0; k < digit_number; k++)
  {
    digitalWrite(digit_pins[k], HIGH);//reset digit pins
  }
  if (digit_position > 3)digit_position = 0;

  for (int k = 0; k < 8; k++) //print the a to g segment pins
  {
    digitalWrite(segment_pins[k], segment_array[digits[digit_position]][k]);
    if (digit_position == dot_position && dot_point == true)
    {
      digitalWrite(segment_pins[7], HIGH);//print dot point
    }
  }

  if (digit_position == 3)
  {
    digitalWrite(digit_pins[0], LOW);
    digitalWrite(digit_pins[1], HIGH);
    digitalWrite(digit_pins[2], HIGH);
    digitalWrite(digit_pins[3], HIGH);
  }
  else if (digit_position == 2)
  {
    digitalWrite(digit_pins[0], HIGH);
    digitalWrite(digit_pins[1], LOW);
    digitalWrite(digit_pins[2], HIGH);
    digitalWrite(digit_pins[3], HIGH);
  }
  else if (digit_position == 1)
  {
    digitalWrite(digit_pins[0], HIGH);
    digitalWrite(digit_pins[1], HIGH);
    digitalWrite(digit_pins[2], LOW);
    digitalWrite(digit_pins[3], HIGH);
  }
  else if (digit_position == 0)
  {
    digitalWrite(digit_pins[0], HIGH);
    digitalWrite(digit_pins[1], HIGH);
    digitalWrite(digit_pins[2], HIGH);
    digitalWrite(digit_pins[3], LOW);
  }
  digit_position++; 
}


long dc_voltage = 0;
void setup()
{
  int_sev_segment();//initialize seven segment program
}

void loop()
{
  dc_voltage = 0; //clear previous result
  for (int i = 0; i < 20; i++)
  {
    dc_voltage += analogRead(A0)*5.37; 
  }
  dc_voltage /= 20; //get average value

  display_7segment(dc_voltage, 2); //display value of cnt, dot in position 1 from right side

}

// end

Here, the Multiplexed Seven Segment program is taken from my previous project, “How to interface multiplexed Seven Segment Display with Arduino with no library file in easy way“. I’ll request to check that article first.

  dc_voltage = 0; //clear previous result
  for (int i = 0; i < 20; i++)
  {
    dc_voltage += analogRead(A0)*5.37; 
  }
  dc_voltage /= 20; //get average value

Here, only dc voltage measurement function is additional. In this function, I just took an average result of 20 samples. You may ask where the 5.37 comes from. It comes from:

5/1023 x 11 x 100;

Here, 5 is from ADC reference voltage 5V; 1023 is ADC resolution of 10bit; 11 from resistor voltage divider and 100 is multiplied as we are displaying 2 digits after decimal.

Result:

Proteus simulation result

Conclusion:

In this article, we have seen how to make a DC voltmeter using Arduino UNO and Seven Segment. I hope you’ve learned the techniques and now you can make one for yourself.

Selecting proper resistors, you can read higher voltage. But always remember one thing, electricity is dangerous. Do work on your own risk.

I hope you enjoyed this project. If you need any help, feel free to ask. Thank you. Enjoy!


MKDas

Mithun K. Das; B.Sc. in EEE from KUET. Blog: https://labprojectsbd.com

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *