Using precisely calculated resistors and a stable power supply, Arduino can be used to work as a voltmeter.
Below is the schematic
Though I used an Arduino Uno, but any Arduino can be used. (If the 3.3v versions are used then calculations will have to be done accordingly).
The resister for voltage divider has been chosen such that at 20 volts (measurement) supply the voltage at Arduino input pin is 5.0v. Greater than 5v at the input pin can damage the pin.
Here is the code
#define READINGS 5 int sensorPin = A0; short int readingsTaken = 0; float voltage = 0.0, readingTotal = 0.0; void setup() { // put your setup code here, to run once: pinMode(sensorPin, INPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: readingTotal = 0.0; readingsTaken = 0; // we will take 5 readings at 1 sec interval and then do an average of that while(readingsTaken < READINGS) { readingTotal += analogRead(sensorPin); readingsTaken++; delay(1000); //at every 1 second interval } voltage = (readingTotal/READINGS) * (5.0/1024); // the value in voltage at this point is what Arduino read based on input from voltage divider network. Need to calculate the original // 5.0 - is the ref voltage used by ADC. It is the default configuration and uses the voltage supplied to the board. To change the ref voltage/source please see this article voltage = (20/4.992) * voltage; //unitary method to calculate the actual voltage that is read. When voltage read is 4.922 (or 5.0v), the input is 20v. With the resistor divider at the input, the voltage at I/O will be 4.992 Serial.println(voltage); }
This is a simple and basic way. Where the precision will not be very good. Because the reference voltage being used by the ADC, which is actually the supply voltage can vary depending on the load to the circuit. To make it more precise an external reference voltage can be supplied to the Arduino. How to use an external reference voltage and the use of the AREF pin has been described in this article