Building an Arduino DC Voltmeter

Building an Arduino DC Voltmeter
This sketch begins by initializing the serial port and declaring a few variables:

vPow – When powered over a USB cable, it is common for the Arduino’s 5V power supply to be a little less than that ideal.

r1 – the value (in ohms) of the first resistor in the circuit.

r2 – the value (in ohms) of the second resistor in the circuit.
  1. 10 KΩ
  2. 100 KΩ
float vPow = 4.7; float r1 = 100000; float r2 = 10000; void setup() { Serial.begin(9600); } void loop() { float v = (analogRead(A0) * vPow) / 1024.0; float v2 = v / (r2 / (r1 + r2)); Serial.print("volt: "); Serial.println(v2); delay(200); }