Table of Contents
Overview:
In this Arduino Project, you will learn how to build an Arduino voltage sensor which can measure the DC voltages ranging from 0 to 25 Volts. This works as a DC voltmeter with maximum 25V.
As you all know Arduino and few other microcontroller can measure up to 5V directly from the analog pins, but if you want to measure the voltage beyond 5V, it is not possible and even if you connect more than 5V the chip may get damaged or burnt. So, with the help of this Voltage sensor we can measure up to 25V from Arduino Analog pins.
So, in this article we teach you, the principle of this voltage sensing module, how it works and how to interface it with Arduino and display the voltage values on 16X2 LCD display with I2C adapter and where it is useful.
Required components:
- Arduino Microcontroller
- Voltage sensor module
- 16X2 LCD display with I2C
- Few connecting wires
Voltage Detection sensor Module overview:
This Voltage sensor is small and low cost module whose principle is based on Resistive voltage divider circuit. With the help of it the voltage is divided by 5. Which makes the voltage 5 times smaller, 25/5=5 thus with this we can measure up to 25V.
Arduino AVR chips have 10-bit ADC, so this module simulates a resolution of 0.00488V (5V/1024), so the minimum voltage of input voltage detection module is 0.00488Vx5(for 25v)=0.02440V.
- For 5V systems the input voltage should not be greater than 25V
- For 3.3V system the input voltage should not be greater than 16.5v as 3.3X5=16.5.
Related: Measure AC current by interfacing ACS712 sensor with ESP32
Technical specifications:
- Voltage input range: DC 0-25V
- Voltage detection range: DC 0.02440V-25V
- Output signal type: Analog
- Voltage Analog Resolution: 0.00489V
Voltage sensor module pinout:
From the above pinout diagram we can notice there are 5 pins to voltage sensor module. 3 pins are male head connectors which are to be connected to Arduino and other 2 pins has a plastic screw pin terminals where the voltage to be measured is connected.
- VCC: Positive terminal for the external voltage source (0-25v)
- GND: Negative terminal for the external voltage source (0-25v)
- S: signal pin or Analog output pin
- +: Not connected
- -: Ground pin
Build Own voltage sensor using below Schematic diagram:
As we already discussed this sensor works with the principle of voltage divider circuit. we can even build the circuit by our own with a very few components as 2 resistors 7.5KΩ and 30KΩ. This circuit reduces the voltage by 5 times. Follow the below schematic diagram to build own voltage sensor with range 0-25V DC.
As you can see from the above 2 resistors are connected in series and signal pin is connected between them.
Circuit Diagram to interface voltage sensor with Arduino
Connect all the required components according to the below circuit diagram.
As you can see from the above circuit diagram the voltage detection sensor module signal pin S is connected to Analog pin A0 of Arduino. The – pin of sensor is connected to GND pin of Arduino. On the other side the voltage to be measured whose +ve and -ve pins are connected to VCC and GND respectively.
The LCD display has 4 pins 2 pins for power and 2 pins for communication. The power pins VCC and GND of LCD display are connected to 5V and GND of Arduino. The communication pins SDA and SCL are connected to A4 and A5 of Arduino respectively.
Not only Arduino UNO microcontroller but also you can use Arduino NANO, etc.,
Thats it for connection, If you want to interface this with LCD display with out I2C adapter refer this article: Interfacing LCD Display with Arduino in detail.
If you want to display the output on the OLED display refer this article: Interfacing SSD1306 OLED display with Arduino.
Now its time to upload the code
Program code for Arduino Voltage sensor
Now its time to upload the code. connect Arduino to a PC where Arduino IDE is installed. Choose the board as Arduino UNO or which ever you use and select the correct port from the Tools menu. Install required libraries from the built in Library manager or you can download the latest version from the below links
Required Libraries:
- Download LiquidCrystal_I2C – Link
Next copy the below code and paste it in IDE workspace and press upload button. That’s it the code will be uploaded.
// Tested and compiled with no errors // measuring DC Voltage using Arduino and voltage sensor up to 25Volts // source - www.circuitschools.com #include <Wire.h> #include <LiquidCrystal_I2C.h> // Define analog input #define SIGNAL_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; // Initialize the LCD library with I2C address and LCD size LiquidCrystal_I2C lcd (0x27, 16,2); void setup() { // Setup Serial Monitor Serial.begin(9600); Serial.println ("Voltage sensor Test"); // Initialize the LCD connected lcd. init (); // Turn on the backlight on LCD. lcd. backlight (); lcd.print ("ARDUINO"); lcd. setCursor (0, 1); lcd.print ("VOLTAGE SENSOR.."); delay(3000); lcd.clear(); } void loop() { // Read the Analog Input adc_value = analogRead(SIGNAL_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); lcd. setCursor (0, 0); lcd.print ("VOLTAGE MEASURED"); //Here cursor is placed on second line lcd. setCursor (0, 1); lcd.print (in_voltage, 2); lcd.print (" volts"); Serial.println(" "); }
After uploading the code open serial monitor to check the values. The LCD display also shows the voltage values connected to the sensor.
Measuring Battery voltage using Voltage sensor with Arduino:
As an experiment lets connect a 12 volts battery from a bike and check the voltage of it. The voltage value is displayed on LCD display so this device can be portable.
Measuring Solar panel voltage using Voltage sensor with Arduino:
As an experiment lets connect a 12 volts battery from a bike and check the voltage of it.
If you like this project please subscribe to our YouTube Channel “Circuit Schools“ to encourage us to publish more interesting projects. If you have any doubts write to us from below comment section.
is it possible to measure millivolt with this module or arduino also?
I’m supposed to build a GSM based smart meter for minigrid load shedding project but the meter is not concerned with energy measurement but soly load shedding. I need you assistance in doing this project. Thank you.
How do you do Multiple Batteries in a bank ?
I just tried and blew everything up when I connected to the second battery
I have 4x 12v batteries in series and 4x voltage dividers , I had all the Ground pins on the sensor side going to a common Ground and all the Sensor pins going to their own adc pins , connected first 12v battery it showed exactly /5th the voltage , awsome , connected the second voltage divider to the next battery magic smoke everywhere
Divider1- \ -+/ Divider1+ ___ Divider2- \ -+/ Divider2+___ Divider3- \ -+/ Divider3+ ___ Divider4- \ -+/ Divider4+
I really liked your tutorial, thank you for all the details which you mentioned. I used this to measure analog reading from a sensor which has output up to 9v.