Arduino Voltmeter DIY project

A voltmeter is one of the most important instruments in electronics, that’s why for today’s tutorial, we are going to learn how to build our own Arduino voltmeter using a very inexpensive voltage sensor. The voltage we measured will be displayed to the user via a Nokia 5110 LCD display. This project is very easy to build and provides a great learning experience which makes it Ideal for beginners.

With today’s project, we will be able to measure the voltage level of different voltage sources and(or) monitor the battery level of our projects.

The major component of this tutorial is the B25 voltage sensor which is a very simple and easy to use voltage sensor module. It consists only of two resistors and you can choose to build your own module easily if you wish, or you can buy this module sensor with less than a dollar if you want something already built. The sensor is based on a voltage divider circuit which is a very common circuit in electronics and it is used most of the time t0 convert a higher voltage to a lower one by using a pair of resistors with the output voltage calculation based on Ohms law.

B25 Voltage sensor

The sensor converts any voltage supplied to the Arduino between the range of 0 and 25v to a voltage within the capacity of the Arduino analog pins which is below 5v for DC voltages.

When a voltage is applied to the sensor, it divides it and the output is received by the Arduino’s ADC on the Analog pin to which the sensor is connected and the analog value of the voltage is gotten. This analog value is converted by the code to the actual voltage which is displayed on the Nokia 5110 LCD Display.

It is Important to note that this particular sensor has a maximum input voltage of 25v and exceeding that voltage at the input to the sensor could damage the Arduino.

 

Required Parts and Where to Buy

The following components/parts are required to build this project and they can each be bought via the link in front of each part.

  1. Arduino Uno: https://educ8s.tv/part/ArduinoUno
  2. Nokia 5110 LCD: https://educ8s.tv/part/NOKIA5110
  3. Voltage Sensor: http://bit.ly/VoltageSensorGB
  4. Small Breadboard: https://educ8s.tv/part/SmallBreadboard
  5. Wires: https://educ8s.tv/part/Wires

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

[adsense]

 

Schematics

The schematics for this project is very simple. Connect the parts as shown in the schematics below.

Schematics

The connection with Arduino is very easy as we only have to connect two wires to Arduino. A pin to pin map of the connection is described below to make the connection clearer and easy to follow.

Voltage Sensor – Arduino

pin(-)  GND

pin(S)  A0

To connect the Nokia 5110 LCD Display, please watch the detailed tutorial I have prepared on this display which is available at this link(https://www.youtube.com/watch?v=aDwrMeu4k9Y).

With the LCD connected, go over the connections once more to make sure everything is as it should be before proceeding to the next section.

Code

The code for this project is simple, for this project, our goal is to simply read the voltage of any connected DC voltage source and display the value on the nokia5110 LCD Display. To achieve this, we will be using just the LCD5110_Graph library which is needed for the Arduino to interact safely with the nokia5110 LCD display.

To run through the code, the first thing we do, as usual, is to include the library we will be using which is the LCD5110_graph for this project, after which we create an object of the LCD library specifying the pins of the Arduino to which it is connected.

//////////////////////////////////////////////
  //        Arduino Voltmeter Project         //
 //            with NOKIA 5110 LCD           //
//           https://educ8s.tv           //
/////////////////////////////////////////////


#include <LCD5110_Graph.h> // THE LIBRARY I AM USING IS THIS:  http://www.rinkydinkelectronics.com/library.php?id=47


LCD5110 lcd(8,9,10,12,11);

Next, we specify the name for the graphics to be displayed on the LCD, the UI and the initial start screen graphics after which we declare the analog pin of the microcontroller to which the signal pin of the voltage sensor is connected.

extern unsigned char BigNumbers[];
extern uint8_t ui[];
extern uint8_t startScreen[];

float voltage = 0.0;
int sensorPin = A0;

Next, we declare some variables to be used during the code and proceed to the void setup.

float sensorValue = 0.0f;  
String voltageString ="0.0";
int stringLength = 0;

float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; 
float R2 = 7500.0;

Under the void setup function, we simply initialize the serial communication and initialize the LCD after which we display the start screen and set the font for the LCD.

void setup() {
  Serial.begin(9600);
  lcd.InitLCD();
  lcd.drawBitmap(0, 0, startScreen, 84, 48);
  lcd.update();
  delay(3000);
  lcd.setFont(BigNumbers);
  delay(1000);
}

Next is the void loop function.
our task under the void loop function is simple, all we have to do is call the read voltage function which reads the value from analog pin 0 and performs some computations on it. The voltage is then printed on the serial monitor and converted into a string so it can be displayed on the LCD too. The LCD is updated and a time delay of 1000ms added to allow the value stay on the screen long enough to be seen.

void loop() {
  lcd.clrScr();
  lcd.drawBitmap(0, 0, ui, 84, 48);

  voltage = readVoltage();
    
  Serial.println(voltage);

  voltageString = String(voltage,1);
 
  stringLength = voltageString.length();
  displayVoltage(stringLength);
  lcd.update();
  delay(1000);
}

The complete code for this project can be downloaded by clicking on the link below.

——————–

CODE OF THE PROJECT
——————–

 

 

Upload the code to your Arduino and test with different types of batteries as shown in the image below.

Test

If you compare the readings with a Multimeter, you will see that the measurements are really close!

That’s it for this tutorial, feel free to reach out via the comments section if you have any question as regards the tutorial.

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv