LCD Programming with Arduino

arduinoi2clcd

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);
}

Best Answer

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;

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

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

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