loading
hi, this is a simple instructable that shows you how to use an analog input (potentiometer) and display that in percentage form on a 16X2 LCD character display




thanks for looking!



Step 1: Parts Needed

what you will need:
1x arduino
1x 10K pot (for LCD contrast)
1x 100k pot (you may need to modify the code as my pot wasn't exactly 100k, so any pot you have around will do)
1x 6X2 character LCD
a breadboard and wires 

Step 2: The Code

paste in arduino compiler:


/* hey, this is a simple code to make your arduino read
the value of a potentiometer and display it in percentage form on
a 16 X 2 LCD screen. I am pretty new at this so sorry if this code
is terrible or if i have no idea what i'm talking about in the
comments.

the circuit(pasted from examples):

* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* Potentiometer attached to analog input 0

* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V

*/
#include <LiquidCrystal.h> // include the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int potPin = A0; //Potentiometer input pin
int potValue1 = 0;
int potValue2 = 0; // final display variable
void setup() {
    lcd.begin(16, 2); // lcd rows and columns
    lcd.print("Potentiometer"); // title of sorts
}

void loop() {
// read then divide the input(max 1020 in this case) by 10
    potValue1 = analogRead(potPin) / 10;
// divide by 1.02 to get percentage
    potValue2 = potValue1 / 1.02;
// set cursor to second row, first column
    lcd.setCursor(0, 1);
//display final percentage
    lcd.print(potValue2);
//print the percent symbol at the end
    lcd.print("%");
//wait 0.1 seconds
    delay(100);
//wipe the extra characters
    lcd.print(" ");
    delay(1);
<p>I used two 10K potentiometers. It worked great.</p>
<p>nice idea! try make my LCD shield for this project, that would be cool! :)</p>
Excelent! works great! thanks!
Excelent! works great! thanks!
this is brilliant. thanks so much for sharing.
Works fine here, uploaded it and I could adjust exacly as I wanted it to...<br>Thank you Tesla Warrior...
nevermind, I got it
I did this exactly how its posted and I couldnt get it to work. Any suggestions and I used two 10k pots. It just shows underlines with one underline flipped up,lol

About This Instructable

45,960views

53favorites

License:

More by TheTeslaWarrior:Arduino analog input display cap bank vs. coke can my tesla coil 
Add instructable to: