0% found this document useful (0 votes)
17 views

Measuring Voltage With Arduino

Ongoing donations help support the website. Users can donate by clicking the Donate button. The website thanks all past donors, including a recent $10 donation from S.K. The website provides tutorials and articles about electronics projects using Arduino.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Measuring Voltage With Arduino

Ongoing donations help support the website. Users can donate by clicking the Donate button. The website thanks all past donors, including a recent $10 donation from S.K. The website provides tutorials and articles about electronics projects using Arduino.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Ongoing donations help keep the site running.

Contribute to this website by clicking the Donate


button. Many thanks to all who have donated.

You can now support us via Starting Electronics at


Patreon

Recent Donors:
X
Thanks S.K. for your $10 donation

Home Beginners Projects Tutorials Articles Reviews Software

Search...

Blog YouTube Donate

Home Articles Arduino Measuring Voltage With Arduino

Measuring DC Voltage using Arduino Articles


Arduino
Created on: 23 May 2013 Articles

Arduino analog inputs can be


used to measure DC voltage Arduino Articles

between 0 and 5V (on 5V


Arduinos such as the Arduino Arduino Ethernet
Board
Uno when using the standard Programming
5V analog reference voltage). and Using

The range over which the


Arduino can measure voltage Arduino Ethernet
Shield –
can be increased by using two Connecting &
DiY Online Shop resistors to create a voltage Testing
divider. The voltage divider
Shop für OpenSource-
decreases the voltage being Arduino Ethernet
Shield – SD Card
Hardware & DIY measured to within the range Testing
of the Arduino analog inputs.
Elektronik
Code in the Arduino sketch is
Battery Powering
Arduino Uno
then used to calculate the actual voltage being measured.
Connecting a
This allows voltages greater than 5V to be measured. Buzzer to an
Arduino Uno
This video shows the Arduino being used to measure various
voltages:
Measuring
Voltage with
Measuring Voltage using Arduino Arduino

PCF8563 (RTC) /
Arduino Testing

Arduino Web
Page Button and
Push Button LED
Control

Differences
Between Arduino
Revision 2 and 3

Difference
Between Arduino
Can't see the video? View on YouTube → and ATmega328

WeMos SAMD21
Arduino M0
Principle of Operation Quick Start
Tutorial
Input Impedance
A digital multimeter set to measure DC voltage will typically have an Choosing an
Arduino for
input impedance of 10MΩ or greater. Beginners
What this means is that the resistance between the two multimeter
probes is 10MΩ or more.

A high input impedance for a voltmeter (or multimeter on the


voltage scale) is desirable as the higher the input impedance, the
less likely the multimeter will influence or change the circuit being
measured.

Measuring voltage across a component in a circuit with a


multimeter that has an input impedance of 10M ohms, is the same
as connecting a 10M ohm resistor across the component.
If a voltmeter has a low input impedance, say 10kΩ and a voltage
across a 10kΩ resistor is being measured, the multimeter is
effectively changing the resistor value to 5kΩ (two 10k resistors in
parallel = 5k resistance). The multimeter therefore has changed the
circuit and possibly the voltage being measured.

So a high input impedance is desirable in our voltage divider circuit


if the impedance of this "voltmeter" is going to influence the circuit
being measured.

As a general rule though, a high input impedance device will


generally pick up more noise or interference (EMI) than a low input
impedance device.

Voltage Divider Circuit


A voltage divider circuit consisting of two resistors in series will
divide the input voltage to bring it within the range of the Arduino
analog inputs.

The circuit shown below will divide the input voltage by 11 (from
the battery as the example input voltage being measured).

The circuit with the particular values shown has an input


impedance of 1MΩ + 100kΩ = 1.1MΩ and is suitable for measuring
DC voltages up to about 50V.

Arduino Voltage Divider Circuit Diagram

Precautions
Common Ground Shop Related
Products
If the Arduino is powered from an external power supply or a USB
cable (i.e. not powered by a isolated battery or other isolated power
supply) the circuit may share a common ground or 0V connection
with the circuit under test.

If the GND connection of the Arduino is connected to any other part


of the circuit under test except GND, then this is the same as E-Projects E-Projects
$5.60
25EP51410… $6.42
100EP5121…
shorting that part of the circuit to GND. 10k Ohm 10k Ohm
Resistors, Resistors,
The GND of the Arduino is like the negative or common (COM) lead 1/4 W, 5% 1/2 W, 5%
(111) (102)
of a multimeter, except that it should be considered to be (P… (Pa…

permanently connected to the GND of the circuit under test for


safety, unless the Arduino or the circuit under test is completely
isolated and "floating".

Input Protection
The resistor values in the circuit diagram above provide some over-
$8.99
AUSTOR 925 StarTech.c…
voltage protection when measuring low voltages such as 5V, 9V or $13.99
Pieces 37 2 Port Native
12V. So if a voltage of say 30V is accidentally measured, it will not Values 5% $89.99
PCI Express
blow the Arduino analog input pin. Carbon Film RS232 Serial
Resistors …
(192) Adapt…
(73)
Any voltage higher than about 55V could damage the Arduino. The
Ads by Amazon
point on the resistor divider network connected to the the Arduino
analog pin is equivalent to the input voltage divided by 11, so 55V ÷
11 = 5V. In other words, when measuring 55V, the Arduino analog
pin will be at its maximum voltage of 5V.

Providing this basic over-voltage protection is at the expense of not


using the full 10-bit range of the analog input ADC if only lower
voltages are to be measured, but changes of about 0.054V can still
be measured.

No other protection for voltage spikes, reverse voltage or voltages


higher than 55V is shown in the circuit.
SPONSORED SEARCHES

arduino code to measure voltage

arduino voltage measurement

circuit board

schematic diagram

electronic circuit

Arduino Voltage Measuring Sketch


The sketch below reads the value on pin A2 of the Arduino. It
provides some simple filtering by adding up 10 analog values from
pin A2 sampled at 10ms intervals.

After taking 10 samples, the voltage is calculated using the average


of the 10 sample values and sent out of the serial port for display
on the Arduino Serial Monitor window.

Note that calibrated values are used in this sketch – these will
need to be changed for your particular reference voltage and
actual resistor division factor, explained below.

/*---------------------------------------------------------
Program: volt_measure

Description: Reads value on analog input A2 and calculat


the voltage assuming that a voltage divider
network on the pin divides by 11.

Hardware: Arduino Uno with voltage divider on A2.

Software: Developed using Arduino 1.0.5 software


Should be compatible with Arduino 1.0 +

Date: 22 May 2013


Author: W.A. Smith, http://startingelectronics.org
-----------------------------------------------------------

// number of analog samples to take per reading


#define NUM_SAMPLES 10

int sum = 0; // sum of samples taken

How the Code Works


Ten analog samples are taken using the following code:

while (sample_count < NUM_SAMPLES) {


sum += analogRead(A2);
sample_count++;
delay(10);
}

The sum or total of all 10 values added together are stored in sum.
The variable sample_count keeps track of the number of samples.

Both variables are reset after calculating and displaying the voltage:

sample_count = 0;
sum = 0;

The number of samples taken can be changed at the top of the


sketch:

#define NUM_SAMPLES 10

Don't make this value too high or the sum of all the samples will be
too big to fit in the sum variable.

The voltage is calculated using:

voltage = ((float)sum / (float)NUM_SAMPLES * 5.0) / 1024.0;

A calibrated value is used in place of 5.0 in the above sketch –


calibration is explained later.

The 10 samples (sum) is divided by 10 (NUM_SAMPLES) to get the


average value read.
5.0 is the 5V ADC reference voltage. 1024.0 is the maximum value
that the ADC can have plus 1 (1023 + 1 or 2 to the power of 10 plus
1) 1023.0 can also be used here.

This calculates the divided voltage – i.e. the voltage on the A3 pin.

The actual voltage is calculated by multiplying the divided voltage


by the division factor from the voltage divider network:

Serial.print(voltage * 11.0);

The above line of code calculates the actual voltage and then sends
it out the serial port for display in the serial monitor window.

The sketch uses a calibrated value instead of 11.0 as shown here.

Amazon.com Amazon.co.uk

1280pcs 64 Amprobe AM-


Values 1 ohm... 500 Digital...
$9.89 $38.09

Shop now Shop now

Fluke 87-V Fluke 287 True-


Digital... RMS Stand...
$365.00 $494.99

Shop now Shop now


Calibrating the Arduino and Circuit
A more accurate voltage could be obtained by using a precision
reference voltage for the ADC and using 1% tolerance resistors or
better.

Another way to obtain a more accurate reading is to calibrate the


circuit. Calibration can be done by measuring the actual value of the
reference voltage and the actual values of the voltage divider
resistors. These values can then be used in the calculations in the
Arduino sketch code.

Each Arduino and set of resistors would need to be individually


calibrated because the voltage from the 5V regulator and the
resistance of the voltage divider resistors will probably be slightly
different for each Arduino and set of resistors.

Performing the Calibration


To perform the calibration, you will need a multimeter.

Calibrating the ADC Reference Voltage


First measure the 5V on the Arduino from the regulator (found on
the Arduino 5V pin). This voltage is used for the Arduino ADC
reference voltage by default.

Now put the measured value into the sketch as follows.

voltage = ((float)sum / (float)NUM_SAMPLES * 5.015) / 1024.

In the above example, the voltage measured on the 5V Arduino pin


was 5.015V.
SPONSORED SEARCHES

arduino code to measure voltage

arduino voltage measurement

electronic circuit

how to read battery voltage with arduino

electrical cable size calculator

Calibrating the Resistor Network


Connect a stable power supply, such as a 9V battery across the
resistor network. Measure the voltage across both resistors
together i.e. measure the battery voltage.

Now measure the voltage across the 100k resistor (R2) i.e. between
Arduino pin A3 and GND.

The voltage divider factor is calculated by dividing the first voltage


by the second voltage or:

dividing factor = input voltage ÷ output voltage

For example, if the first or input voltage measured is 10.02V and the
second or output voltage is 0.9V, then the division factor is:

10.02 ÷ 0.9 = 11.133

Now use this value in the Arduino sketch code:

Serial.print(voltage * 11.133);

If calibration is used, then 5% tolerance resistors can be used for


the voltage divider.
Digitizer - FPGA
U5310A ADC card/Digitizer, 10
GS/s or 5 GS/s, PCIe.
Acqiris SA

Comments Login

There are no comments posted yet. Be the first one!

Post a new comment


Enter text right here!

Comment as a Guest, or login:

Name Email Website (optional)

Displayed next to your comments. Not displayed publicly. If you have a website, link to it here.

Subscribe to None Submit Comment

Arduino Pinout About Contact Donate Privacy Policy Amazon Adverts

© 2012 – 2020, Starting Electronics

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy