IOT

How to interface 0-25V DC Voltage Sensor with Arduino?

The voltage sensor module is a resistive voltage divider circuit-based 0-25 DC voltage sensing device. It multiplies the input voltage signal by 5 and provides an analog output voltage in response. This is why you can use the 5V analog pin of any microcontroller to test voltages up to 25V. In this blog, we will learn how to interface a 0-25V DC Voltage Sensor with an Arduino to measure DC Voltages.

We will first connect the voltage sensor module to the Arduino and measure the various battery voltages in this project. The output voltage will then be monitored using a small 0.96′′ I2C OLED Display. You can use this voltage measurement circuit to detect under or over-voltage issues in electrical circuits because it is tiny and portable.

Hardware Required

  • Arduino Nano Board Atmega328
  • 0-25V Voltage Sensor Module
  • 0.96″ SSD1306 I2C OLED Display
  • Male-to-Male Jumper Wires
  • Breadboard

0-25V Voltage Sensor Module

A voltage sensor is a conventional method used to determine, monitor, and measure the supply of voltage in a device. Voltage sensors can sense both AC and DC voltages. Voltage sensors are highly precise sensors that work on the principle of the potential divider rule. As a result, it reduces the input voltage by a factor of 5. This allows us to use the analog input pin of microcontrollers to observe the voltage above the threshold level. With a small compact device, both voltage and current measurement are combined into a single physical device. For 0-5v analog input, the output measured up to 25v. A voltage sensor consists of 5 pins in which two of which are on the two-pin screw terminal and three are male header pins.

PIN DESCRIPTION

  •  VCC: Positive terminal of the voltage to be measured (0-25V)
  •  GND: Negative terminal of the voltage to be measured
  •  S: Analog Input of Arduino
  • +: Not connected (N/C)
  •  : GND of Arduino

.

The Interfacing of a voltage sensor with Arduino or any other microcontroller is quite simple. The VCC and GND of the voltage source are connected to the screw terminals of the voltage sensor. And the S and – (GND) pins are connected to the Analog pin and GND of Arduino respectively. Moreover, the screw terminals present in the module provide an easy and secure connection to a wire.

Features:

  • Input voltage: 0-25v
  • Divider ratio: 5:1
  • Resistor Tolerance: 1%
  • Resistor Value: 30K/7.5K Ohm
  • Voltage detection range: 0.02445-25
  • Analog voltage resolution: 0.00489v
  • Wide operating range
  • No external components required
  • Compact size and high accuracy
  • Weight: 4gm
  • Dimension: 4*3*2cm

Voltage Sensor Module Design & Construction

The Voltage Sensor is essentially a voltage divider made up of two resistors with resistances of 30K and 7.5K, resulting in a voltage divider of 5 to 1. As a result, for each input voltage, the output voltage is lowered by a factor of 5. The Voltage Sensor Module’s internal circuit schematic is shown below.

The analog input pin on the Arduino may handle voltages of up to 5V. As a result, you can easily utilize this module with Arduino. If the controller has 3.3V systems, the input voltage should not be greater than 3.3Vx5=16.5V.

Since Arduino AVR chips have a 10-bit AD, this module mimics a resolution of 0.00489V (5V/1023), resulting in a minimum voltage of 0.00489Vx5=0.02445V for the input voltage detection module.

SSD1306 I2C OLED Display

The OLED module depicted in the above image is one of the most widely used on the market. There are several various versions of this module on the market, with differing resolutions, connection protocols, and pixel colors.

SSD1306 IC, a driver IC for 128×64 Dot Matrix OLED segments, is used to power these OLED modules. The SSD1306 has its own controller and can communicate via both SPI and I2C protocols. As a result, there are a variety of OLED modules on the market, some of which only support SPI communication, some that only support I2C communication, and still others that support both I2C and SPI communication. (Each module has a different number of pins.)

Since the driver, IC provides 128×64 resolution, other variations, such as 128×32, have a lower resolution. Colors such as blue, yellow, and white are supported by different modules. Some modules also allow for the use of numerous colors. 

Pin Description

OLED I2C Module Pin Description
  • VCC: This is the power pin for the module. A supply of 3.3V or 5V can be provided to this pin to power the display.
  • GND: This is the ground pin for the module.
  • SCL and SDA: These are the serial clock and serial data pins for I2C communication.

Interfacing 0-25V DC Voltage Sensor Module with Arduino

Let’s look at how to connect a Voltage Sensor Module to an Arduino. The following is a circuit schematic.

Connect the Voltage Sensor’s Signal (S) and Negative (-) pins to Arduino A0 and GND, 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);
}

Here, we use three different types of batteries to test the sensor’s functionality and monitor the voltage on the Serial Monitor.

The sensor was first tested with a standard 3.7V Lithium-Ion battery.

The Serial Monitor showed the correct reading as per the voltage of the Battery.

Similarly, testing the sensor with a 9V battery yielded satisfactory results.

When tested with a discharged 3S Lithium-Ion battery, the voltage sensor detected a reading of roughly 5V.

Making Portable Voltage Detector with OLED Display

Let’s build a portable DC Voltmeter that can measure voltages between 0 and 25 volts.  We will now use a 0.96-inch OLED display.

The Interfacing Voltage Sensor Module & OLED Display with Arduino Board connection diagram is shown below.

The voltage sensor module is connected to Arduino in the same way as before. However, an OLED display necessitates four connections. Connect the OLED’s VCC and GND pins to the Arduino’s 3.3V and GND pins. Connect the OLED’s SDA and SCL pins to the Arduino’s SDA and SCL pins, i.e. A4 and A5.

Source Code/Program

For OLED Display, the code requires two libraries. Download the libraries from the following link and place them in the Arduino’s Library Folder.

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 128×64, 0x3C for 128×32
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();

}

The OLED will display 0V output if no voltage source is connected to the voltage input terminal.

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

So that’s how you can combine an Arduino and a 0-25V DC Voltage Sensor to construct your own DC Voltmeter.

Designing own Voltage Sensor Board with Arduino Microcontroller

You can create your own portable voltage sensor board with an Arduino ATmega328 microcontroller instead of utilizing the preceding arrangement. The project’s schematic is shown below.

Voltage Sensor Arduino Schematic

The schematic has been designed using EasyEDA online Circuit Schematics & PCB designing tool.  A PCB is created from the schematic. The PCB appears as seen below.

Below is the Gerber File for the PCB. Simply download the Gerber File and place an order for the PCB. from https://www.nextpcb.com/

Download Gerber File: Voltage Sensor PCB

Now you can visit the NextPCB official website by clicking here: https://www.nextpcb.com/. So you will be directed to the NextPCB website.

You can now upload the Gerber File and place an order on the website. The PCB quality is excellent. That is why the majority of people entrust NextPCB with their PCB and PCBA needs.

Conclusion:

I hope all of you understand how to Interface 0-25V DC Voltage Sensor with Arduino. We MATHA ELECTRONICS will be back soon with more informative blogs.

Leave a Reply

Your email address will not be published.