Arduino B.Tech/Diploma Beginner

Interfacing 0-25V DC Voltage Sensor with Arduino

Interfacing 0-25V DC Voltage Sensor with Arduino to measure output DC Voltages from Lithim-ion or Lipo Battery with Arduino Code & schematic

  • Suitable forB.Tech/Diploma Arduino students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

Overview
In this tutorial, we will learn interfacing of 0-25V DC Voltage Sensor with Arduino to measure DC Voltages. Earlier, we made
0-50V DC Voltmeter
to measure the output voltages & also learned about the
DC−to−DC converters
The voltage sensor module is a 0-25 DC voltage sensing device that is based on a resistive
voltage divider circuit
. It reduces the input voltage signal by the factor of 5 and generates a corresponding analog output voltage. This is the reason why you can measure the voltage up to 25V using the 5V analog pin of any microcontroller.
In this project we will first interface the voltage sensor module with Arduino and measure the different Battery voltages. We will then use a small 0.96″ I2C OLED Display to observe the output voltage. This voltage measurement circuit is small & portable and you can use it to detect under or over-voltage faults in electrical circuits.
Bill of Materials
The list of materials required for this project are as follows. You can purchase all the components from Amazon.
S.N.
Components
Quantity
Purchase Links

Arduino Nano Board

Amazon
AliExpress

0-25V Voltage Sensor Module

Amazon
AliExpress

0.96" I2C OLED Display

Amazon
AliExpress

Jumper Wires

Amazon
AliExpress

Breadboard

Amazon
AliExpress
0-25V Voltage Sensor Module
The Voltage Sensor Module is a simple but very useful module that uses a potential 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 monitor voltages much higher than it is capable of sensing.
Features & Specifications
1. Output Type: Analog
2. Input Voltage (V): 0 to 25
3. Voltage Detection Range (V): 0.02445 to 25
4. Analog Voltage Resolution (V): 0.00489
5. Dimensions: 4 × 3 × 2 cm
Voltage Sensor Module Pinout
The voltage sensor module has 5 pins, 2 on the front side and 3 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 basically 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.
The Arduino analog input pin accepts voltages up to 5V. Hence you can use this module easily with Arduino. If the controller has 3.3V systems, the input voltage should not 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), so the minimum voltage of the input voltage detection module is 0.00489Vx5=0.02445V.
Interfacing 0-25V DC Voltage Sensor Module with Arduino
Let us learn interfacing of Voltage Sensor Module with Arduino. The circuit diagram is given below.
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
=

;
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
(
"Input Voltage = "
)
;
Serial
println
(
in_voltage

)
;
// Short delay
delay
(

)
;
}
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 3.7V common Lithium-Ion Battery.
The Serial Monitor showed the correct reading as per the voltage of the Battery.
Similarly testing the sensor with 9V Battery also worked fined.
The voltage sensor detected the reading around 5V when tested with Discharged 3S Lithium-Ion Battery.
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-50V DC Voltmeter
with 7 segment LED Display. But now we will use 0.96″ OLED Display.
The following is the connection diagram for Interfacing Voltage Sensor Module & OLED Display with Arduino Board.
The connection is fairly simple. The voltage sensor module has the connection with Arduino same as earlier. But OLED Display requires 4 connections. Connect the VCC & GND Pin of OLED to Arduino 3.3V & GND pin. Similarly connect the SDA & SCL Pin of OLED to Arduino SDA & SCL Pin, i.e A4 & A5.
Source Code/Program
The code requires two libraries for OLED Display. Donwload the libraries from the following link and add it 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
=

;
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
(
"Input Voltage = "
)
;
Serial
println
(
in_voltage

)
;
display
setCursor
(

)
;
//oled display
display
setTextSize
(

)
;
display
setTextColor
(
WHITE
)
;
display
println
(
"Battery Voltage"
)
;
display
setCursor
(

)
;
//oled display
display
setTextSize
(

)
;
display
setTextColor
(
WHITE
)
;
display
(
in_voltage

)
;
display
println
(
" V"
)
;
display
display
(
)
;
delay
(

)
;
display
clearDisplay
(
)
;
}
When no Voltage source is connected to the input terminal of voltage, the OLED will display 0V output.
Similarly connecting the voltage sensor to 3 different voltage sources gives 3 different results as shown in the image below.
So this is how you can u

Technologies used

ArduinoBLESSD1306OLEDI2CSPIADC

Hardware components

  • Arduino
  • SSD1306
  • OLED

Software & tools

  • Arduino IDE

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.