Arduino Projects

Interface DC Voltage Sensor with Arduino

Voltage Detection Sensor Module with Arduino

Overview: 0-25V DC Voltage Sensor with Arduino

In this tutorial, we will learn to interface DC Voltage Sensor with Arduino and measure DC Voltages up to 25V on a 0.96″ OLED Display. Previously, we’ve made IoT based battery monitoring system and a simple voltmeter to measure the output voltages.

This module is a 0-25 DC voltage sensing device which is based on a resistive voltage divider circuit. It reduces the input voltage signal by the factor of 5 and then generates a corresponding analog output voltage. This can be the reason why you’ll be able to measure the voltage up to 25V using the 5V analog pin of any microcontroller.

In this project, we are going to first interface the voltage sensor module with Arduino and measure the various Battery voltages. We will then use a small 0.96″ I2C OLED Display to look at the output voltage. This voltage measurement circuit is small & portable and you’ll be able to use it to detect under or over-voltage faults in electrical circuits.


Components Required

The list of components required for this project is as follows. You can purchase all the components from Amazon.

S.NComponents NameQuantityGet Products from Amazon
1Arduino UNO REV31https://amzn.to/3c6weVM
2Voltage Detection Module DC 0~25V Voltage Sensor for Arduino1https://amzn.to/33Gk2tP
30.96" I2C OLED Display1https://amzn.to/3kvENyc
4Few jumpers wires10https://amzn.to/3klh0A4
5Breadboard1https://amzn.to/3H2tbeQ

0-25V Voltage Sensor Module

The Voltage Sensor Module is a simple but very useful module that uses a possible divider to reduce an input voltage by a factor of 5. The 0-25V Voltage Sensor Module allows you to use the analog input of a microcontroller to observe voltages much higher than it is capable of sensing.

Voltage Sensor Module

Features & Specifications

  • Output Type: Analog
  • Input Voltage (V): 0 to 25
  • Voltage Detection Range (V): 0.02445 to 25
  • Analog Voltage Resolution (V): 0.00489
  • Dimensions: 4 × 3 × 2 cm

Voltage Sensor Module Pinout

The voltage sensor module has 5 pins, two on the front side and three on the backside.

  • VCC: Positive terminal of the External voltage source (0-25V)
  • GND: Negative terminal of the External voltage source
  • S: Analog pin connected to Analog pin of the microcontroller
  • +: Not Connected
  • : Ground Pin connected to GND of microcontroller

Voltage Sensor Module Design & Construction

The Voltage Sensor is essentially a voltage divider consisting of two resistors with resistances of 30KΩ and 7.5KΩ i.e. a 5 to 1 voltage divider. Hence the output voltage is reduced by a factor of 5 for any input voltage. the internal circuit diagram of the Voltage Sensor Module is given below.

Arduino Voltage Sensor Module Schematic

The Arduino analog input pin accepts voltages up to 5V. Hence you’ll be able to use this module easily with Arduino. If the controller has 3.3V systems, the input voltage shouldn’t be greater than 3.3Vx5=16.5V.

Arduino AVR chips have 10-bit AD, so this module simulates a resolution of 0.00489V (5V/1023), therefore the minimum voltage of the input voltage detection module is 0.00489Vx5=0.02445V.


Interface 0-25V DC Voltage Sensor Module with Arduino

Let us learn to interface the Voltage Sensor Module with Arduino. The circuit diagram is given below.

Interfacing Voltage Sensor Module with Arduino

The connection is very simple. Connect the Signal (S) and Negative (-) pin of Voltage Sensor to Arduino A0 & GND pin respectively.


Source Code/Program

// Define analog input
#define ANALOG_IN_PIN A0
 
// Floats for ADC voltage & Input voltage
float adc_voltage = 0.0;
float in_voltage = 0.0;
 
// Floats for resistor values in divider (in ohms)
float R1 = 30000.0;
float R2 = 7500.0; 
 
// Float for Reference Voltage
float ref_voltage = 5.0;
 
// Integer for ADC value
int adc_value = 0;
 
void setup()
{
   // Setup Serial Monitor
   Serial.begin(9600);
   Serial.println("DC Voltage Test");
}
 
void loop(){
   // Read the Analog Input
   adc_value = analogRead(ANALOG_IN_PIN);
   
   // Determine voltage at ADC input
   adc_voltage  = (adc_value * ref_voltage) / 1024.0; 
   
   // Calculate voltage at divider input
   in_voltage = adc_voltage / (R2/(R1+R2)) ; 
   
   // Print results to Serial Monitor to 2 decimal places
  Serial.print("Input Voltage = ");
  Serial.println(in_voltage, 2);
  
  // Short delay
  delay(500);
}

To test the working of the sensor, I used 3 different types of batteries and observed the voltage on the Serial Monitor.

Initially, the sensor was tested with a 5V USB Power supply.

Input voltage result on serial monitor

The Serial Monitor showed the correct reading as per the voltage on the USB.


Making Portable Voltage Detector with OLED Display

Now let us make a portable DC Voltmeter that can measure the voltage from 0V to 25V. Earlier we made 0-25V DC Voltmeter with a 16×2 LCD Display. But now we will use a 0.96″ OLED Display.

The following is the connection diagram for Interfacing Voltage Sensor Module & OLED Display with Arduino NANO Board.

Interfacing 0-25V DC Voltage Sensor Module with Arduino and OLED Display

The connection is fairly simple. The voltage sensor module has the connection with Arduino same as earlier. We need 4 more connections. So, Connect the VCC & GND Pin of OLED to Arduino 3.3V & GND pin. Similarly, connect the SDA & SCL Pin of OLED to Arduino A4 & A5 pin respectively.


Ordering the PCBs at PCBWay

You can simply assemble the circuit on a breadboard. But if you don’t want to assemble the circuit on a breadboard, you can follow this schematic and build your own PCB. You can download the Gerber file of my PCB Design from the link attached below. The PCB looks like the image shown below.

Voltage sensor Arduino and OLED PCB

I provided the Gerber File for Interfacing 0-25V DC Voltage Sensor with Arduino PCB below.

You can simply download the Gerber File and order your custom PCB from PCBWay

PCBWay website

Turn your DIY breadboard circuits into professional PCBs – get 10 boards for approximately $5 + shipping (which will vary depending on your country).

Once you have your Gerber files, you can order the PCB. The reason behind most of the people trusting PCBWay for PCB & PCBA Services is because of their quality. The PCB quality is superb and has a very high finish, as expected.

  • Front PCB of Voltage sensor Arduino and OLED Display
  • Voltage sensor Arduino and OLED PCB Back
  • Voltage sensor Arduino and OLED PCB

Final Source Code/Program

The code requires two libraries for OLED Display. Download the libraries from the following link and add them to the Library Folder of the Arduino.

1. Adafruit GFX library: https://github.com/adafruit/Adafruit-GFX-Library
2. Adafruit SSD1306 Library: https://github.com/adafruit/Adafruit_SSD1306

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
// Define analog input
#define ANALOG_IN_PIN A0
 
// Floats for ADC voltage & Input voltage
float adc_voltage = 0.0;
float in_voltage = 0.0;
 
// Floats for resistor values in divider (in ohms)
float R1 = 30000.0;
float R2 = 7500.0;
 
// Float for Reference Voltage
float ref_voltage = 5.0;
 
// Integer for ADC value
int adc_value = 0;
 
void setup()
{
  // Setup Serial Monitor
  Serial.begin(9600);
  Serial.println("DC Voltage Test");
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
  {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }
  display.clearDisplay();
}
 
void loop() {
  // Read the Analog Input
  adc_value = analogRead(ANALOG_IN_PIN);
 
  // Determine voltage at ADC input
  adc_voltage  = (adc_value * ref_voltage) / 1024.0;
 
  // Calculate voltage at divider input
  in_voltage = adc_voltage / (R2 / (R1 + R2)) ;
 
  // Print results to Serial Monitor to 2 decimal places
  Serial.print("Input Voltage = ");
  Serial.println(in_voltage, 2);
 
  display.setCursor(20, 10); //oled display
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.println("Battery Voltage");
 
 
  display.setCursor(25, 30); //oled display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.print(in_voltage, 2);
  display.println(" V");
  display.display();
  delay(500);
  display.clearDisplay();
 
}

When no Voltage source is connected to the input terminal of voltage, the OLED will display 0V as output.

Interface 0-25V DC Voltage Sensor with Arduino

Similarly connecting the voltage sensor to different voltage sources gives different results as shown in the image below.

Interfacing 0-25V DC Voltage Sensor with Arduino

So this is how you can use 0-25V DC Voltage Sensor with Arduino & make your own DC Voltmeter.


Project Demonstration & Conclusion

This tutorial shows you how to Interface 0-25V DC Voltage Sensor Module and 0.96″ OLED Display with Arduino. So, this way you learned to build your own DC Voltmeter. I hope this tutorial was interesting to you. If you need any type of help related to this project, then let me know in the comment section below. Video demonstration & Guide is embedded below.


Related Articles

One Comment

  1. Thanks! So how do we power the Arduino with the battery instead of the USB cable? I want to make a temperature sensor for my swimming pool that can monitor it’s own battery voltage level every hour. As soon as I disconnect the USB cable, it doesn’t have any power. I want the device to get power only from the battery (LiFePO4 3.2V) and be able to read the battery’s voltage every hour.

Leave a Reply

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

Back to top button