#include <LiquidCrystal.h>
#define pot A0
// declaring LCD pins
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
pinMode(pot,INPUT); // pin A0 as Input pin
//Start serial
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
// Read from pin A0
int reading = analogRead(pot);
float read = (float)(reading / 1023.0) * 5.00; //analog read gives integer value in range 0-1023 we need to convert to float value in range 0-5 to represent voltage
// Set the cursor to column 0, line 0
// Note: line 1 is the second row, since counting begins with 0
lcd.setCursor(0,0);
if ((int)(read*10) %10 ==0) //Logic for checking if there is decimal place in read if no decimal place the decimal is not printed
{lcd.print((int)read);}
else {lcd.print(read,1);} // If there is decimal place the read is printed with only one decimal place
lcd.print("V"); //Prints "V" after read prints
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
int star = (read / 5.00) * 16; //converts read in range 0-5 to range 0-16
//prints * in for loop
for(int i=0;i<star;i++){
lcd.print("*");
}
delay(180);
lcd.clear();
}