//***************************************************************************************************************************
// DVM - Simple Arduino DVM
// Gary C. Sutcliffe
// Version 1.00
// March 2012
//
//This program is a simple Digital Volt Meter using an Arduino. It measures the voltage on analog pin A0.
// The results are shown on a Unified Microsystems ATS-1 Terminal Shield. www.unifiedmicro.com
///DVM Program by Gary C. Sutcliffe is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
//
// **** IMPORTANT: Don't apply more than 5V to the analog input pin or you may damage the Arduino! ****
//
//Updates:
//***************************************************************************************************************************
int analogPin = 0; //The voltage is connected to Analog pin 0
#define CLS 0x01 //Character to send to the ATS-1 to clear the LCD and home the cursor
#define SCALE_FACTOR .00488 //the voltage difference to change the 10 bit Arduino A/D reading by one
#define TRUNC_VAL 4 //divisor for truncating lower bits. 2 will truncate LSB, 4 lowest 2 bits, 8 lowest 3 bits
void setup()
{
Serial.begin(4800); // opens serial port, sets data rate to 4800 baud to LCD display
}
void loop()
{
float voltage;
int rawAD; //raw A/D reading value
rawAD = analogRead(analogPin);
voltage = (float)rawAD * SCALE_FACTOR; //convert the A/D reading to a type float and multiply by scaling factor
Serial.write(CLS); //Clear the LCD screen
Serial.print("Voltage: ");
Serial.print(voltage); //note that Serial.print defaults to two digits after the decimal point.
delay(250); //put in a short delay between readings
}