Los Electrofaster
Published © GPL3+

Graduated scale of the value of a potentiometer using a 16x4

Graphic representation of a potentiometer reading.

BeginnerFull instructions provided1 hour2,162
Graduated scale of the value of a potentiometer using a 16x4

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LCD 16x4
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×7
LCD I2C PCF8574 Interface Adapter
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit diagram

Code

Potentiometer scale value using a 16x4 LCD

Arduino
Using the LCD 16x4 to represent a scaling for a potentiometer value.
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,4);

byte b1[] = { B00000, B00000, B00000, B00000, B00000, B00000, B00000, B11111 } ;
byte b2[] = { B00000, B00000, B00000, B00000, B00000, B00000, B11111, B11111 } ;
byte b3[] = { B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 } ;
byte b4[] = { B00000, B00000, B00000, B00000, B11111, B11111, B11111, B11111 } ;
byte b5[] = { B00000, B00000, B00000, B11111, B11111, B11111, B11111, B11111 } ;
byte b6[] = { B00000, B00000, B11111, B11111, B11111, B11111, B11111, B11111 } ;
byte b7[] = { B00000, B11111, B11111, B11111, B11111, B11111, B11111, B11111 } ;
byte b8[] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 } ;

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.createChar(0,b1);
  lcd.createChar(1,b2);
  lcd.createChar(2,b3);
  lcd.createChar(3,b4);
  lcd.createChar(4,b5);
  lcd.createChar(5,b6);
  lcd.createChar(6,b7);
  lcd.createChar(7,b8);
}

void loop() {
  int value = analogRead(A0); // read of potentiometer value
  int level = map(value, 0, 1000, 0, 15);
  if (level<9){
    for (int i=0;i<level;i++){
      lcd.setCursor(i, 1);
      lcd.write(i);
    } 
  } else {
    for (int i=0;i<8;i++){
      lcd.setCursor(i, 1);
      lcd.write(i);
    }
    for (int i=0;i<level-8;i++){
      lcd.setCursor(i+8, 0);
      lcd.write(i);
      lcd.setCursor(i+8, 1);
      lcd.print(char(255));
    } 
  }
  
  lcd.setCursor(0,2);
  lcd.print("Value:");
  lcd.setCursor(1,3);
  lcd.print(value);

  delay(200);
  lcd.clear();
}

Credits

Los Electrofaster

Los Electrofaster

8 projects • 7 followers

Comments