How to display ADC voltage on LCD Display

Good Day All.

I am still very new to the Arduino microcontroller so please bear with me.

I have got a LCD connected to my Arduino UNO, and I would like to be able to display the raw ADC voltage on the LCD Display to three decimal places.

Could someone please give me an example code, or a link to a post that would help me on my way?

Thanks for your time.

Best Regards.

Without knowing what LCD you have or if you even have managed to wire it up. Here is a good starting point

Check the LiquidCrystal Library.

Cheers!

Sorry I should of been more clear :blush:.

I am using a VHX1620 16x2 LCD Display, it has 14pins on the back, and is compatible with the Hitachi HD44780.

I have already had the LCD Display connected, and working following the details here: http://arduino.cc/en/Tutorial/LiquidCrystal

What I would like to know is how to display the 0-1023 (1024 ADC) input as a voltage reading on the LCD display.

Best Regards.

  float voltage = analogRead (pin) * 5.0 / 1024 ;

Will be a start. Then find the right options to print the 3 dp's.

MarkT:

  float voltage = analogRead (pin) * 5.0 / 1024 ;

Will be a start. Then find the right options to print the 3 dp's.

That won't work right
Should be:

  float voltage = analogRead(pin) * 5.0 / 1024.0;

Note the .0 on the 1024 to force it to a float value.

Note the .0 on the 1024 to force it to a float value.

There was already a .0 in the statement, so the 1024 value was dividing a float by an int, which will operate as expected. It is not strictly necessary for all operands to be the same type.

PaulS:

Note the .0 on the 1024 to force it to a float value.

There was already a .0 in the statement, so the 1024 value was dividing a float by an int, which will operate as expected. It is not strictly necessary for all operands to be the same type.

Ambiguity is the devil's plaything. Mixing types in a mathematical calculation is a bad thing - regardless of what is "meant" to happen. If you have mixed types, ALWAYS cast them to the correct type. If you have mixed literals, ALWAYS caste them into the most precise / longest type (either with a .0 for floats, or with suffixes). It avoids both compiler issues with you assuming it will do one thing and the compiler doing another, and it also means you can instantly see what the operations are going to do.

Also, do not be afraid to use excessive numbers of brackets in your maths - it forces the order of precedence to be what you expect it to be, and a change in compiler version won't mean a chance change in calculation precedence breaking your code.