Other Arduino Codes and Videos by Robojax

Display Potentiometer Voltage as bargraph on LCD

دروس آردوینو به فارسی

Ultrasonic Sensor distance as bargraph

This video explains how to dispaly input voltage at A0 pin as bargraph on LCD1602-I2C and LCD2014-I2C display..
  1. Robojax LCD Bargraph Libaray (zip file)
  2. I2C Scanner
  3. Introduction to LCD1602-I2C with code
  4. Introduction to using Potentiometer with Arduino
  5. Arduino You Know Course on Udemy

 * This Arduino sketch display input voltage as bargraph on LCD1602-I2C
 * Original library was taken from https://playground.arduino.cc/Code/LcdBarGraph/
 * Modified by Ahmad Shamshiri on May 25, 2019 at 19:43 in Ajax, Ontario, Canada
 * Visit http://robojax.com/learn/arduino for other Arduino codes
 * Watch video instruction for this code: https://youtu.be/gLtVRcyOXaU
 * Robojax Arduino Course on Udemy where  you get Schematic Diagram of this sketch 
 * and many other robotics related lectures and codes. Purchase the course here: http://bit.ly/rj-udemy
 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LcdBarGraphRobojax.h>

byte lcdNumCols = 16; // -- number of columns in the LCD
byte lcdLine = 2; // -- number of line in the LCD
byte sensorPin = 0; // -- value for this example

LiquidCrystal_I2C lcd(0x3f,lcdNumCols,lcdLine);  // -- creating LCD instance
LcdBarGraphRobojax lbg(&lcd, 16, 0, 0);  // -- creating 16 character long bargraph starting at char 0 of line 0 (see video)
void setup(){
  // -- initializing the LCD
  lcd.setCursor (0,1); //  
  lcd.print("voltage Bargraph"); 
  // -- do some delay: some time I've got broken visualization

void loop()
  lbg.clearLine(1);// clear line 1 to display fresh voltage value
  int inpuValue = analogRead(sensorPin);
  // -- draw bar graph from the analog value read
  lbg.drawValue( inpuValue, 1024);
  // -- do some delay: frequent draw may cause broken visualization
  float voltage = inpuValue * (5.0 / 1023.0);
  lcd.setCursor (0,1); //
  lcd.setCursor (8,1); //
  lcd.print(voltage); // print
  lcd.setCursor (12,1); //  


If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal