Voltage Sensor Module Interfacing with Arduino – DC Voltage Measurement

The voltage sensor module is a small size 0-25 DC voltage sensing device. The design of the module is based on a resistive voltage divider circuit. It is a voltage sensor module that reduces the input voltage signal by the factor of 5 and generates a corresponding analog output voltage with respect to step down voltage factor. This voltage measurement circuit is small and portable and can be used to detect under and over-voltage faults in electrical circuits. 

Voltage Sensor Module

The post is a brief description of the voltage sensor module pinout, pin configuration, interfacing with Arduino with an example code and applications.

Voltage Sensor Module Pinout

The voltage sensor module is embedded with two header blocks. One with the screws is connected to the power source whose voltage to be measured while the other connector is used to interface microcontrollers such as Arduino, Pic microcontroller, Raspberry Pi, Beaglebone, etc. The pinout of the voltage sensor module is shown below:

Voltage sensor module pinout diagram

Pin Configuration

The pin configuration details of voltage sensor module are given below.

This module is available in 4cm x 3cm x 2cm dimensions

Pin NameFunction
VCCPositive power supply pin. The positive terminal of the power supply to be measured is connected to this pin.
GNDReference potential pin. It is connected to the negative terminal of the power supply.
SAnalog output pin voltage of sensor. Connect it to the analog input pin of Arduino or any other microcontroller which you want to use.
+Not connected
Ground connection pin. It must be joined to the ground pin of the Arduino or microcontroller and also to the power supply ground pin.

Features & Specifications

  • Input Voltage: 0 Volts – 25 Volts
  • Voltage measurement Range: 0.02445 Volts – 25 Volts
  • Analog signal resolution: 0.00489 Volts
  • Voltage Sensor module dimensions: 4cm x 3cm x 2cm
  • It is a small, portable and reliable device.
  • The module is a simple circuitry and easy to interface with Arduino microcontrollers.

Schematic Diagram

The schematic diagram of the voltage Sensor module which is a resistive voltage divider is shown below:

Voltage sensor module circuit diagram

Voltage Sensor Module Working Principle

The voltage sensor module works on the voltage divider principle. A voltage divider is a circuit made of two resistors connected in series. An input voltage is connected to the circuit. The applied voltage is then passed on between the two resistance and division takes place in direct accordance with the resistances. The output analog voltage is taken from the second resistor and measured. The general equation of the output voltage is

Vout= Vin*R2/R1+R2

The equation shows that the output voltage is directly proportional to the input voltage and the ratio of the R2 resistor to the sum of R1 and R2 resistors.

Important Calculations

Here, we will calculate the range of the concerned voltage sensor module and the resolution of the output signal.

Example

We know that the maximum analog voltage that the Arduino board can take is 5 Volts i.e V1=5 Volts. So, the maximum voltage that the voltage sensor module can take is calculated using Ohm’s Law.

The resistances used in the voltage sensor module are R1=30K, R2= 7.5K

I=V/R

Therefore,

I = 5/7500 = 0.000666 = 666uA

As R1 and R2 are in series, the current is the same for both the resistors. That means IR2 is also  666µA. We can find the voltage across R1 as

VR1= 666uA x 30000 = 20 Volts

The maximum voltage that the module can measure is the sum of the voltage drops.

VR1+VR2=5V+20V= 25V.

Analog Signal Resolution

The Arduino boards have an analog to digital converter with a resolution of 10-bits. So, the resolution of the analog signal that is given out is

Resolution= 5V/2^10 = 5/1024= 0.00489 Volts

Minimum Voltage

Using the resolution, we can calculate the minimum voltage that is to be provided to the voltage sensor module.

Vmin=0.00489 Volts x 5 Volts=0.02445 Volts

Voltage Sensor Module Interfacing with Arduino

The section shows the interfacing of the Arduino UNO and the voltage Sensor module. But you can use any other microcontroller also.

Connection Diagram

The wiring diagram is provided below for the visual

  • First, connect the power source whose voltage you want to measure with the input pins of the voltage sensor module. This is done by connecting the ground pin of the voltage sensor to the negative terminal of the battery and the positive power supply pin i.e VCC to the positive terminal of the battery.
  • Screw the wires tightly.
  • Connect the analog pin S to any of the input analog pins of the Arduino UNO.
  • Similarly, connect the -(minus) pin to the ground pin of the Arduino.
Voltage sensor module interfacing with Arduino connection diagram

The wiring should be done in accordance with the table given:

Arduino UNOVoltage Sensor Module
A0(Green)S
GND(Black)-(minus)
Power SourceVoltage Sensor Module
+(Red)VCC
– (Black)GND

Arduino Code

The Arduino code for Voltage Sensor module is provided below:

int offset =20;// set the correction offset value
void setup() {
  // Robojax.com voltage sensor
  Serial.begin(9600);
}

void loop() {
  int volt = analogRead(A0);// read the input
  double voltage = map(volt,0,1023, 0, 2500) + offset;// map 0-1023 to 0-2500 and add correction offset
  
  voltage /=100;// divide by 100 to get the decimal values
  Serial.print("Voltage: ");
  Serial.print(voltage);//print the voltge
  Serial.println("V");

delay(500);
  
  
}

How does the code work?

The voltage sensor module does not require any pre-written Arduino libraries for its interfacing with the Arduino microcontrollers. It works ideally without using the built-in libraries in the Arduino IDE software. We need only to use the AnalogRead() function of Arduino IDE to measure analog output of the voltage sensor.

Explaining the code

Voltage Offset

A voltage offset of 20 is used as a correction value to the input analog signal in case the module is not working fine. Otherwise set the offset to zero.

void setup

The next statement is the setup block. In the code, the setup block initializes the serial monitor with a typical baud rate of 9600 bits per second. We need it to display the values of the analog voltage signal.

void loop

Inside the loop, an integer variable “volt ” is initialized. The analog value is read through the pre-defined analogRead() function and stored in it. The next instruction line is the map function which maps one set of values to another set of values. It has five parameters. The first one is the variable “volt” whose values are to be mapped. The values would be between 0 and 1023 because the Arduino has a 10-bit inbuilt analog to digital converter and mapped them in range 0 to 2500.

We are mapping the initial range in the latter range because if we map them between 0 and 25, we get one volt increment and won’t obtain values in between. Hence, after mapping and adding the offset, the result is stored in the “voltage” which is further divided by 100 to get the decimal point. Finally, these are displayed on the Serial monitor and there is a delay of 500 milliseconds before the next value is read. The lesser the delay, the faster the values will be read. To test the module, burn the code on the Arduino UNO and see the measurements on the monitor.

Voltage Sensor Applications

  • Voltage measurement
  • Fault sensing
  • Safety switching
  • Power Control

Related Voltage measurement projects:

Other modules:

Leave a Comment