Voltage sensor for Arduino.


I use these voltage sensors to monitor a battery pack used to power an Arduino. They are nothing more than two resistors wired as a voltage divider, but at less than £1 on eBay they are easy to use.

The Arduino Analogue inputs can take a voltage of up to 5 volts, these voltage sensors use a 5:1 voltage divider and this means that voltages up to 25 volts will be reduced to below 5 volts. All we have to do is measure the reduced voltage then multiply the result by 5 to get the original voltage. This means you can power the Arduino with a 9 volt battery and monitor the battery voltage.

The sketch shown below is a simple example of how voltage can be measured. Take care, there is no reverse protection, so if you connect the voltage incorrectly it may damage the Arduino. Make sure the voltage you are measuring is less than 25 volts.

Two factors effect the accuracy of the result. The sketch assumes the Arduino’s Vcc is 5 volts, check this with a volt meter and adjust the variable Vcc accordingly. The second factor is the actual division provided by the voltage divider. The voltage shield shown at the top of the page has a factor of 4.092. If you build your own divider from two resistors, I used 15k and 3k3, then calculate the factor by adding the two resistors together and dividing the result by the smallest value resistor. 

// Voltage Probe - Max input is 25v
// NO REVERSE PROTECTION. Make sure its wired up correctly!!!
// Uses 3.3k and 15k resitors in series (3.3k goes across A0/GND)

// The factor is (R1+R2)/R2
// Example R1 = 15k, R2 = 3.3k, factor is 18.3/3.3 = 5.54

double Vout; // voltage at pin A0
double Vin; // voltage being measured, max = 25v
double factor = 4.54;
double Vcc = 5.00; // this is the Arduino's Vcc, measure and adjust if necessary

void setup() {

void loop() {
Vout = analogRead(0); // read the adjusted voltage 0 to 1023
Vout =(Vout/1023)*Vcc; // convert to a voltage 0 - 5 volts
Vin = Vout * factor; // convert to the voltage being measured
Serial.print("Voltage= ");


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: