No this is not a DIY multimeter... sorry fellows! :) But in a way it's much more useful for the electronic interventionist. This is a small circuit that allows you to measure any input voltage with an ATmega168 (although it can be adapted to any microcontroller that has analog inputs and a reference voltage).
It uses a simple resistor bridge to bring the input voltage between 0 and 1.1V (the reference voltage on the ATmega168).
The code of the VoltageMeter class is provided in attachment to this post.
Note: If you want to measure the voltage from the ATmega168 itself (ie. AVcc) you can use the following code instead (no need to build a circuit).
R1 R2
GND ----/\/\/\----*----/\/\/\---- Vin
|
| Vout
|
ANALOG PIN
Choose R1 and R2 CAREFULLY according to the following rule:
R1 = R2 x 1.1 / (Vmax - 1.1) R2 = R1 x (Vmax - 1.1) / 1.1
A typical configuration is R1 = 1k and R2 = 4k. It assumes Vmax = 5.5V.
#include "VoltageMeter.h"
#define VOLTAGE_AIN 0
VoltageMeter meter(VOLTAGE_AIN, 5.5);
void setup() {
Serial.begin(9600);
}
void loop() {
float voltage = meter.voltage();
Serial.print((int)(voltage*1000), DEC); Serial.println(" mV");
}
| Attachment | Size |
|---|---|
| analog_reference.h | 2.65 KB |
| prescaler.h | 3.34 KB |
| VoltageMeter.h | 3.02 KB |