0 ratings 0% found this document useful (0 votes) 44 views 14 pages Analogue Sensor, Sensing Physical Object's
This document provides a tutorial on interfacing a voltage sensor with an Arduino Uno, explaining how to measure voltages up to 25V using a voltage divider circuit. It details the hardware setup, including the pinout and connections, as well as a sample Arduino code to read and calculate the input voltage from the sensor. The tutorial emphasizes the simplicity of using a voltage sensor compared to building a voltage divider from discrete resistors.
AI-enhanced title and description
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
Save Analogue sensor, sensing physical object's For Later
Interfacing Voltage Sensor with Arduino
OF eNEERS om
The Arduino Uno, like many microcontrollers, has a built-in Analog to Digital Converter
(ADC) that can convert an analog voltage on a pin to a digital number. However, the
maximum analog input pin voltage is limited to 5V. You may find this limit inconvenient if
your project requires measuring voltages exceeding SV. In such cases, you could create a
voltage divider using discrete resistors.But there's an easier way to measure voltages, especially if they're lower than 25V: use
a Voltage Sensor. It is a pre-made voltage divider circuit that uses precision resistors to
provide accurate readings.
In this tutorial, we'll explore how to use a voltage sensor with your Arduino to make your
voltage measuring tasks simpler and more efficient. Let's get started!
Hardware Overview
The Voltage Sensor, in essence, is a simple voltage divider circuit composed of two resistors~
nothing fancy.
7.5KO
The schematic of the Voltage Sensor is illustrated in the following image.Vin —
RI
RZ
GND
20K
t—* Vour
75K
There are two resistors in this circuit. The resistor (R1) closest to the input voltage, has a
value of 30 KQ, and the resistor (R2) closest to ground, has a value of 7.5 KQ. The voltage
drop across R2 is our divided voltage. This signal is broken out to a header pin labeled S.This simple circuit divides the input voltage by a factor of 5. That's why this voltage sensor
can help you measure voltages that are less than 25 volts with an Arduino.
Reading the Voltage Sensor
Reading the voltage sensor or any voltage divider, for that matter, is very easy. We can use
the voltage divider equation.
Vn
RI
RZ
GND
The voltage divider equation assumes that you know three values of the above circuit: the
input voltage (Vin), and both resistor values (R1 and R2). Given those values, we can use this
equation to find the output voltage (Vout):- _y Pa
out — Yin Rl+ R2
However, in our case, we will be measuring the output voltage (Vout) from the voltage
divider circuit using Arduino's ADC. Therefore, the value we do not know is Vin.
Let's rearrange the above equation to solve for the input voltage (Vin).
. _«, R1i+R2
Vin = Vout —5
R2
This equation tells us that the input voltage (Vin) is the output voltage (Vout) divided by the
fraction of the second resistor’s resistance (R2) over the total resistance (R1 + R2) in the
circuit.Voltage Sensor Pinout
Now let's have a look at the pinout.
o— a7 Sa
om
o— 5 EEL
Pinout SP ENE con
Input Terminal
Vcc is connected to the positive terminal of the voltage source you want to measure. The
recommended voltage range for this pin is 0 to 25V.
‘0 is connected to the negative terminal of the input voltage source.Output Header
is the signal output pin of the voltage sensor module. It provides an analog voltage that
is proportional to the input voltage level. It's usually connected to one of the analog input
pins on the Arduino.
is not connected to anything
is the common ground pin.
Hardware Hookup
Connecting a voltage sensor to an arduino is a breeze.
To begin, connect the voltage source that you want to measure to the input screw terminal.
Then, connect the 'S' pin on the voltage sensor to the ‘A0' analog pin on the Arduino and the
‘pin to ground.
The image below shows how to connect everything.DC Voltage <25V
ay est Minute
PP ENGINEERS con
Arduino Example Code
Here is a simple sketch that reads the analog voltage on the analog pin AQ, calculates the
input voltage using voltage divider equation and prints the results to the Serial Monitor.
// Define analog input
define ANALOG_IN PIN AG
// Floats for ADC voltage & Input voltage
float adc_voltage = @.05
float in_voltage = 0.0;
// Floats for resistor values in divider (in ohms)
float R1 = 3000.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);void loop(){
// Read the Analog Input
adc_value = analogRead(ANALOG_IN_PIN);
Upload the sketch to your Arduino and observe the results.
To verify the accuracy, measure the actual voltage using your digital multimeter. The value
displayed on the multimeter should match the reading shown on the serial monitor.
The following result is obtained when 5V is applied to the voltage sensor:© coms - oOo x
[ | [sea]
Taput Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
205
205
5.03
Input Voltage = 5.10
208
Input Voltage
Ej Atoncel [show timestamp ‘Newine seodbad | Clareuiput |
And when 12V is applied:
© coms - ao x
[ | s=4]
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Input Voltage
Imput Voltage
[Z Autoscral [] shon timestamp [Newline
Code Explanation:
This is a fairly simple sketch, so you should have no trouble following it. The sketch begins
with the definition of a few global variables that will be used throughout the programThe first line defines the analog input pin on the Arduino that we are using to read the
voltage from the voltage divider circuit. In this case, we are using pin AO.
define ANALOG_IN_PIN A@
Next, two floats, adc_voltage and in_voltage , are defined to store the voltage readings
at the ADC and the input of the voltage divider, respectively.
float adc_voltage = 0.0;
float in_voltage = 0.0;
The R1 and R2 variables store the resistance values for the voltage divider. If you're using
a different set of resistors to make your own voltage divider, you'll need to change them.float R1
float R2
30000.0;
7500.03
ref_voltage is the reference voltage for the ADC, typically 5V for an Arduino Uno.
float ref_voltage = 5.0;
The last variable adc_value is used to store the raw digital value read from the ADC.
int adc_value = 0;
In the setup0, we set up the serial communication at a baud rate of 9600.
void setup(){
Serial. begin(9600);
In the loop(), the analogRead() function is used to read the voltage on the AO pin. The
returned value is stored in the variable adc_valueadc_value = analogRead(ANALOG_IN_PIN)
This value is then converted to a voltage ( adc_voltage ) by multiplying with the reference
voltage and dividing by 1024 (as the Arduino has a 10-bit ADC, hence 2410 = 1024 different
values).
adc_voltage = (adc_value * ref_voltage) / 1024.0;
The input voltage to the voltage divider is then calculated using the formula for a voltage
divider:
Ri+ R2
Vin = Vout —p5
in_voltage = adc_voltage*(R1+R2)/R2;Finally, the calculated input voltage is printed to the Serial Monitor, displaying up to 2
decimal places. After this, the Arduino waits for 500 milliseconds before repeating the loop.
[Link]("Input Voltage =
Serial.print1n(in_voltage, 2);
delay (580);
SHARE
Disclaimer Privacy Policy About Contact Us
Copyright © 2025 [Link]. All rights reserved.