Introduction
This tutorial is an open source arduino project that teaches how to make a BIG digit numbers displaying on 16X2 i2c type Liquidcrystal display and i am going to control nmbers up and down using the push buttons, the possible purpose of this lesson is you can make an analog 7 segment display using LCD and I am going to show you how to make a counter using this components.

#### What Will I Learn?
Write here briefly the details of what the user is going to learn in a bullet list.
<li>how to make a Big numbers display using LCD 16X2</li>
<li>how to make an Digital counter using LCD</li>
<li>how to program a code on arduino Desktop IDE</li>
<li>how to connect all the components connection using diagram</li>
### HARDWARE
- Step 1: Gather all the Requirements
#### Requirements
- 16X2 LCD with IIC backpack
- Push buttons
- Breadboard
- jumper wires
- Type B usb cable
- Arduino UNO R3 board
- PC
#### Difficulty
- Basic arduino Project
#### Tutorial Contents
- Information about the 3 main components

Anything cool has buttons, the Momentary Push Button Switch a 12mm Square like what you see on the image above, These buttons gives a nice soft click every time it's pressed so you know that you've definitely activated it. great for building your own homemade button pad. it also make a good reset switch or user feedback for a microcontroller circuitry.

The 16x 2 LCD with I2C module you will be able to connect the LCD with Arduino board with only two Data cables! The i2c module has a built in potentiometer bakpack for contrast adjustment. The 16x2 display is the set up LCD number of columns and rows ( 16 columns, 2 rows Display ).
The arduino UNO R3

<blockquote>has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. 32k Flash Memory</blockquote> <a href="https://store.arduino.cc/usa/arduino-uno-rev3">source</a>
codes and programs can be uploaded on to it from the easy Arduino computer program. which makes it a very easy way to get started working with embedded electronics. The name R3 is the third, and latest version of Arduino Uno Board
#### Experimental Procedures
- Step 2: Build the circuit
The 16X2 LCD display interfaces has 4 build in backpack pins (1) VCC it refers to the power signal of the LCD typically connected to 5volts, (2)GND or sometimes zero voltage, It is also the common connection of the LCD must connect to in one way or another path in order to complete the circuit. (3) SDA and (4) SCL is the i2c serial bus pin it is used to synchronize all data transfers over the I2C bus from the 16 pin of the normal LCD, Both SCL and SDA are connected to analog pin ouputs of the arduino beacasue i2c lines are open drain drivers, means is that the chip can drive its output low.

<li>VCC - 5V</li>
<li>GND - GND</li>
<li>SCL - A4</li>
<li>SDA -A5</li>
The push buttons has built with 4 sets of pin we will use 2 set for the GNS and the digital in output on the arduino

#### SOFTWARE
- Step 3: Dowload the Software and Libraries
If you’re ready to get started, click on the link below then select the version with your operating system.
Dowload the arduino Desktop IDE: https://www.arduino.cc/en/Main/Software
When the download is finished, un-zip it and open up the Arduino folder to confirm that click yes, there are some files and sub-folders inside. The file structure is important so don’t be moving any files around unless you really know what you’re doing.
Download the liquidcrystal LCD library : https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library This library is a modified version of the H. Mario LiquidCrystal_I2C V.2.0 lib.
- Step 4: Include libraries to arduino IDE
Once installed the Arduino desktop IDE. open the software then locate the SKETCH tab at the top of the software, navigate ADD ZIP LIBRARY >> then look for the downloaded libraries in the download folder. SELECT the zip file then wait for the process. include all the libraries fo liquidcrystal display.

- Step 5: Programming
Add Libraries at the first line of the code define the components library for the liquidcrytal i2c library, the wire h file is build in config on the IDE.
<pre><code>#include <Wire.h>
#include <LiquidCrystal_I2C.h></code></pre>
include the type of LCD for 16X2 LCD with i2c backpack address is 0x27;
<pre><code>LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);</code></pre>
Define the push buttons pin to arduino
<pre><code>const int Up_buttonPin = 2; // the pin that the pushbutton is attached to
const int Down_buttonPin = 3; //</code></pre>
Build LCD Custom Character Generator using; http://maxpromer.github.io/LCD-Character-Creator/
it support character lcd and create code for Arduino. once you set the charcter it will generate a binary data type for adruino code. each set of binary codes is composed of number 0-9.

At the void setup() function write the command that starts serial connection this method is ran once at the just after the Arduino is powered up. The lcd.begin(16,2) command set up the LCD number of columns and rows. For example, if you have an LCD with 20 columns and 4 rows (20x4) you will have to change this to lcd.begin(20,4). the possition of the digits col=5 wich means the dit is at the center of the lcd.


- Step 6: Upload the code to arduino board
Connect the arduino board to type B usb cable on your computer make sure you choose the correct port and board type on the tools section of the software.
SOURCE <a href="http://jume-maker.blogspot.com/2018/01/arduino-counter-big-digits-with-lcd.html">CODE</a>
<pre><code>#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int counter = 0;
const int Up_buttonPin = 2; // the pin that the pushbutton is attached to
const int Down_buttonPin = 3;
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int up_buttonState = 0; // current state of the up button
int up_lastButtonState = 0; // previous state of the up button
int down_buttonState = 0; // current state of the up button
int down_lastButtonState = 0; // previous state of the up button
bool bPress = false;
byte LT[8] =
{
B00111,
B01111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte UB[8] =
{
B11111,
B11111,
B11111,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte RT[8] =
{
B11100,
B11110,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte LL[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B01111,
B00111
};
byte LB[8] =
{
B00000,
B00000,
B00000,
B00000,
B00000,
B11111,
B11111,
B11111
};
byte LR[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11110,
B11100
};
byte MB[8] =
{
B11111,
B11111,
B11111,
B00000,
B00000,
B00000,
B11111,
B11111
};
byte block[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
void setup()
{
pinMode( Up_buttonPin , INPUT_PULLUP);
pinMode( Down_buttonPin , INPUT_PULLUP);
lcd.begin(16,2); // initialize the lcd
lcd.createChar(0,LT);
lcd.createChar(1,UB);
lcd.createChar(2,RT);
lcd.createChar(3,LL);
lcd.createChar(4,LB);
lcd.createChar(5,LR);
lcd.createChar(6,MB);
lcd.createChar(7,block);
// Print a message to the LCD.
lcd.backlight();
lcd.clear();
displayNumber();
}
void printNumber(int val){
int col=5;
if( val >= 10){
printDigits(val/10,col);
printDigits(val%10,col+4);
}
else{
printDigits(val,col);
}
}
void loop()
{
checkUp();
checkDown();
if( bPress){
bPress = false;
displayNumber();
}
}
void displayNumber(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Vol:");
printNumber( buttonPushCounter);
}
void custom0(int x){
lcd.setCursor(x,0);
lcd.write((byte)0);
lcd.write(1);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(4);
lcd.write(5);
}
void custom1(int x){
lcd.setCursor(x,0);
lcd.write(1);
lcd.write(2);
lcd.print(" ");
lcd.setCursor(x,1);
lcd.write(4);
lcd.write(7);
lcd.write(4);
}
void custom2(int x){
lcd.setCursor(x,0);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(4);
lcd.write(4);
}
void custom3(int x){
lcd.setCursor(x,0);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(4);
lcd.write(4);
lcd.write(5);
}
void custom4(int x){
lcd.setCursor(x,0);
lcd.write(3);
lcd.write(4);
lcd.write(7);
lcd.setCursor(x, 1);
lcd.print(" ");
lcd.print(" ");
lcd.write(7);
}
void custom5(int x){
lcd.setCursor(x,0);
lcd.write(3);
lcd.write(6);
lcd.write(6);
lcd.setCursor(x, 1);
lcd.write(4);
lcd.write(4);
lcd.write(5);
}
void custom6(int x){
lcd.setCursor(x,0);
lcd.write((byte)0);
lcd.write(6);
lcd.write(6);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(4);
lcd.write(5);
}
void custom7(int x){
lcd.setCursor(x,0);
lcd.write(1);
lcd.write(1);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.print(" ");
lcd.print(" ");
lcd.write(7);
}
void custom8(int x){
lcd.setCursor(x,0);
lcd.write((byte)0);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.write(3);
lcd.write(4);
lcd.write(5);
}
void custom9(int x){
lcd.setCursor(x,0);
lcd.write((byte)0);
lcd.write(6);
lcd.write(2);
lcd.setCursor(x, 1);
lcd.print(" ");
lcd.print(" ");
lcd.write(7);
}
void printDigits(int digits, int x){
// utility function for digital clock display: prints preceding colon and leading 0
switch (digits) {
case 0:
custom0(x);
break;
case 1:
custom1(x);
break;
case 2:
custom2(x);
break;
case 3:
custom3(x);
break;
case 4:
custom4(x);
break;
case 5:
custom5(x);
break;
case 6:
custom6(x);
break;
case 7:
custom7(x);
break;
case 8:
custom8(x);
break;
case 9:
custom9(x);
break;
}
}
void checkUp()
{
up_buttonState = digitalRead(Up_buttonPin);
// compare the buttonState to its previous state
if (up_buttonState != up_lastButtonState) {
// if the state has changed, increment the counter
if (up_buttonState == LOW) {
bPress = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
up_lastButtonState = up_buttonState;
}
void checkDown()
{
down_buttonState = digitalRead(Down_buttonPin);
// compare the buttonState to its previous state
if (down_buttonState != down_lastButtonState) {
// if the state has changed, increment the counter
if (down_buttonState == LOW) {
bPress = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter--;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
down_lastButtonState = down_buttonState;
}
</code></pre>
note; if you want to copy the code from the link on the code, i have make some changes of the skectch code beacause the original code is not working with my components wich may not work with yours too, change the code ```lcd.init();``` to ```lcd.begin(16,2)``` at the void set up to initialize the lcd. change the ```lcd.write(0);``` into ```lcd.write((byte)0);``` on the custom0. not changing that codes you will get an error message when compiling the sketch.
- Now, you can see the value of current counter digit displaying on the 2 row of the LCD, control the volume of the number by up and down 0-99 using the push buttons.
https://media.giphy.com/media/52Fc9DQjzh2b3mjSE3/giphy.gif
I hope this Tutorial might help you on your future activity. thank you.
<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@lapilipinas/control-vol-of-numbers-on-lcd-using-push-buttons">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>