Volt meter LCD decimal. HELP PLEASE!!

I am new to Arduino and I need to get a volt meter to display its readings on my HITACHI LCD in decimal form. I can't get how to do it. This is what I have so far...
#include <LiquidCrystal.h>

const int numRows = 2;
const int numCols = 16;
const int analogPin = 3;

const int maxVal = 1024;
const float maxVoltage = 5;

int val = 0;

float voltage = 0;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(numRows, numCols);
}

void loop() {

lcd.clear();
val = analogRead(analogPin);

voltage = val * maxVoltage * 100 /maxVal;

lcd.print(voltage, DEC);

delay(200);

}

See the stopwatch sketch in the learning section - you may have to poke around there a bit.

It should give you some idea how this would be done.

paulb

The problem here is with your circuit for a volt-meter. You are 1) Measuring voltage with respect to ground (always). Depending how you are wiring this voltmeter to your circuit, you may be getting bad readings because of KCL and KVL.

The proper way to do this is using TWO analog pins, not one. Say, pin 1 and 2. Take the difference between them, which is your potential, and convert to a 5V scale.

Remember however, you are scaling from a max of 1023 to a max of 5. If you do this operation using int, you will extremely bad precision, which, by the way, your statement

voltage = val * maxVoltage * 100 /maxVal;

may be doing... You may be storing the value in a float, but your arguments are still of type int. You should cast them to float before doing that operation.