# LCD Programming with Arduino

I'm trying to get my LCD to display "Voltage= (variable)". I have it programmed to write the text and I have a pot wired to my arduino and I'm trying to get a voltage number to come after the equals sign. How can I program it so when I turn the pot that the actual voltage will come after "Voltage="?

Here's my program

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
}
void loop()
{
lcd.init();
lcd.backlight();
int sensorPin = A0;
int sensorValue = 0;
sensorValue = 0.004882812 * analogRead(sensorPin) + 1;
lcd.print("Voltage=");
lcd.print(sensorValue);
}

• Who voted to close? Why? Apr 18, 2012 at 22:41
• @Rocketmagnet - When this question started out, it was in pretty poor shape. It looks a good deal better now. Still, if the reason isn't obvious, whoever's voting to close should leave a comment so the OP can fix the question. (Obviously, it wasn't me, as I can't cast an ordinary close vote.) Apr 19, 2012 at 2:08

This is what I ended up with.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

void setup() {}

void loop()
{ lcd.init();
lcd.backlight();

int VoltsInput = A0;
int VoltsRange = 0;
int VoltsPercent = 0;

VoltsPercent = (((5.0/1023.0) * analogRead(VoltsInput)) / 5) * 100;

lcd.print(VoltsRange);
lcd.print("V    ");

lcd.print(VoltsPercent);
lcd.print("%");}

• You may want to accept either answer so that we know the problem is solved. (you can accept your own answer, it just doesn't get you reputation) Apr 25, 2012 at 16:14
• Another option is to have decimal point Change: int VoltsRange = 0; To: Float VoltsRange = 0; Get more accurate voltage after decimal point.
– user33742
Dec 6, 2013 at 7:11
• This is more a different approach than a solution to the original question. Its not likely that this will help anyone in the future because it doesn't even state what was wrong in the first place.
– Rev
Dec 6, 2013 at 8:02

So the Arduino's ADC is 10-bits resolution, this means that analogRead will return a value between 0 and 1023 (2^10-1). You need to re-scale this to the range 0v - 5v.

You can do this simply by dividing by 1023, and multiplying by 5. I'm not totally familiar with the Arduino language, but I hear that it's quite like C. So this should probably work.

LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
lcd.init();
lcd.backlight();
int sensorPin = A0;
float sensorValue = 0;

• @Rocketmagnet - What do you expect to happen from lcd.print("Voltage=") + sensorValue; ? I'd expect the function call to return a number, which would get added to sensorValue, and then not assigned to anything. Instead, you want to do lcd.print("Voltage="); \n lcd.print(sensorValue, DEC); Apr 19, 2012 at 2:11