# Display sensor reading as decimal number on LCD

I would like to know if someone could provide me with some links or code for making a simple volt meter. I just want to display a sensor reading from an ADC input on an LCD display, to two decimal places precision (ie. 1.23). I can work out how to do the units, however, not the hundredths, or tenths.

I have got the Hello World and other LCD routines working. I have a pot connected on Analog In 0.

A Google search comes up with 100s of results!

Thanks.

The value read from the analog pin will be an integer value, in the range 0 to 1023. To convert that to a meaningful float, you need to know the value of VRef when the pin is read. Do you know that value? Typically, it's 5V, on a 5V board.

float pinFloat = pinInt * 5.0 / 1023.0; (where pinInt is the value read from the pin).

Then, you can print pinFloat on the LCD, using lcd.print. The overloaded method, in 0018, for floats allows you to specify the number of decimal places to show.

Thanks PaulS! I never knew it would be so simple. It works great.

In terms of VRef, I don't have it connected to anything (I am meaning the AREF pin (next to Digital I/O pin 13)). I measured it, and it is 5V.

I have found a small problem. I have times the sensor value by 30 instead, so the reading can go up to 30.00. However, when I print a “V” (for volts) next to the sensor figure, when only three numbers are displayed (when the reading is less than 10.00), a “V” remains in the same position on the display, along side the newly printed “V”.

Is there a way to move the cursor to the next column (after the “V”) automatically to clear that segment?

Below is my code:

#include <LiquidCrystal.h>
int sensor1Pin = 0;
int sensor1Value = 0;

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

void setup() {
lcd.begin(16, 2);
}

void loop() {