Arduino Code and Video for a Voltage Sensor Module
In this tutorial, we will explore how to utilize a voltage sensor module with an Arduino. This project allows you to measure input voltage and display it on the serial monitor, simplifying the process compared to using additional resistors. By the end of this tutorial, you will have a functional setup that reads voltage levels accurately.

As you follow along, you'll gain insights into both the hardware connections and the code necessary for this project. You can refer to the associated video at (in video at 00:00) for further clarification on each step.
Hardware Explained
The main component of this project is the voltage sensor module. It typically features three terminals: one for the signal output, one for the ground, and one for the positive voltage input. The signal pin connects to the Arduino's analog input, allowing it to read voltage levels. The module uses a voltage divider circuit, consisting of two resistors, to scale down the voltage to a safe level for the Arduino.
When measuring voltage, it's critical to connect the ground terminal of the sensor to the ground of the voltage source being measured. The positive terminal connects to the point of interest, ensuring accurate readings. This simple setup eliminates the need for additional wiring and components, making it user-friendly.
Datasheet Details
| Manufacturer | Generic |
|---|---|
| Part number | Voltage Sensor Module |
| Logic/IO voltage | 5 V |
| Supply voltage | 0–25 V |
| Input voltage range | 0–25 V |
| Output voltage range | 0–5 V |
| Input current | ≤ 20 mA |
| Package | Module |
| Notes / variants | May vary by manufacturer |
- Ensure correct wiring to avoid damage to the Arduino or sensor.
- Use a stable power supply to ensure accurate readings.
- Adjust the offset value in the code for calibration.
- Keep the input voltage within specified limits to prevent damage.
- For higher voltage measurements, use appropriate resistors as a voltage divider.
Wiring Instructions

To wire the voltage sensor module, start by connecting the ground terminal of the module to the ground of the voltage source you're measuring. Next, connect the signal terminal, labeled as S, to the Arduino's analog pin A0. Finally, connect the positive terminal to the voltage point you wish to measure. The negative terminal should also be connected to the ground to complete the circuit.
It's essential to ensure that the ground connections are consistent between the voltage source and the Arduino. This will help in achieving accurate voltage readings. If you need to measure voltages higher than 25 volts, additional resistors may be required to form a voltage divider, but for most applications, the basic setup will suffice.
Code Examples & Walkthrough
The code begins by defining an integer variable called offset, which is used to correct any discrepancies in the voltage reading. The setup function initializes the serial communication at a baud rate of 9600, which is essential for displaying the voltage readings on the serial monitor.
int offset = 20; // set the correction offset value
void setup() {
Serial.begin(9600); // Initialize serial communication
}
In the loop function, the code reads the analog voltage from pin A0 and maps the value from the range of 0 to 1023 to a voltage range of 0 to 2500, adding the offset. It then divides the voltage by 100 to get the appropriate decimal representation.
void loop() {
int volt = analogRead(A0); // read the input
double voltage = map(volt, 0, 1023, 0, 2500) + offset; // map and add offset
voltage /= 100; // divide by 100 to get the decimal values
Serial.print("Voltage: ");
Serial.print(voltage); // print the voltage
Serial.println("V");
delay(500); // Delay for half a second
}
This loop continuously reads the voltage and prints it to the serial monitor every half second. You can adjust the delay value to change the frequency of readings as needed.
Demonstration / What to Expect
During the demonstration, you will see that the maximum measurable voltage is 25 volts due to the design of the module. If you attempt to measure higher voltages, the readings will saturate at 25 volts plus any offset you have configured (in video at 08:00). The readings should be fairly accurate, and you can verify them against a multimeter for calibration purposes.
Things you might need
-
Amazon
-
eBay
-
AliExpressPurchase Arduino voltage sensor from AliExpresss.click.aliexpress.com
Resources & references
-
ExternalDocument shows how the resistor was calculated.docs.google.com
Files📁
Fritzing File
-
Voltage Sensor-25V- module
application/zip0.01 MB -
HC-SR501 Body Sensor Module
application/zip0.01 MB