create account

control vol of numbers on LCD using push buttons by lapilipinas

View this thread on: hive.blogpeakd.comecency.com
· @lapilipinas · (edited)
$16.30
control vol of numbers on LCD using push buttons
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.

![20180224_145136.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519455705/fqmmyixbi4ljpbmx7kck.jpg)


#### 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

![20180224_145908.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519455772/gpl26nblpvp0u9ctbeqk.jpg)


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.

![20180221_143618.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519448861/d2mtgiaridfjykt8a7iy.jpg)


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

![20180222_151336.jpg](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519448896/uvejl0jcfkerzpwor5fh.jpg)


<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.

![U5dtqsMcFweBEB4pxkKhQ8g7Vs1gJBs_1680x8400.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519190723/wfnluiufjgh2ocnuomgm.png)

 <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 

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519451220/jz0liffojemcamiwabqi.png)


#### 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.

![add zip.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519193282/hkwzvsdhvc2l382tj2o3.png)

- 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 &lt;Wire.h>
#include &lt;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.

![ss.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519449008/oefyqhfbvg2jsdfvadom.png)

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.

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519449426/t9sipkfkprrhg7d9pfr2.png)

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519449479/a6mclzczqbqezprl9hlr.png)

- 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 &lt;Wire.h> 
#include &lt;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/>
👍  , , , , , ,
properties (23)
authorlapilipinas
permlinkcontrol-vol-of-numbers-on-lcd-using-push-buttons
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":919161,"name":"Arduino","full_name":"arduino/Arduino","html_url":"https://github.com/arduino/Arduino","fork":false,"owner":{"login":"arduino"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","arduino","tutorial","technology","philippines"],"links":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1519455705/fqmmyixbi4ljpbmx7kck.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519455772/gpl26nblpvp0u9ctbeqk.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519448861/d2mtgiaridfjykt8a7iy.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519448896/uvejl0jcfkerzpwor5fh.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519190723/wfnluiufjgh2ocnuomgm.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519451220/jz0liffojemcamiwabqi.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519193282/hkwzvsdhvc2l382tj2o3.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519449008/oefyqhfbvg2jsdfvadom.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519449426/t9sipkfkprrhg7d9pfr2.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519449479/a6mclzczqbqezprl9hlr.png"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1519455705/fqmmyixbi4ljpbmx7kck.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519455772/gpl26nblpvp0u9ctbeqk.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519448861/d2mtgiaridfjykt8a7iy.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519448896/uvejl0jcfkerzpwor5fh.jpg","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519190723/wfnluiufjgh2ocnuomgm.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519451220/jz0liffojemcamiwabqi.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519193282/hkwzvsdhvc2l382tj2o3.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519449008/oefyqhfbvg2jsdfvadom.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519449426/t9sipkfkprrhg7d9pfr2.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519449479/a6mclzczqbqezprl9hlr.png"],"moderator":{"account":"sdtyldz","time":"2018-02-24T20:44:16.318Z","reviewed":true,"pending":false,"flagged":false},"questions":[],"score":0}
created2018-02-24 07:05:00
last_update2018-02-24 20:44:18
depth0
children4
last_payout2018-03-03 07:05:00
cashout_time1969-12-31 23:59:59
total_payout_value11.423 HBD
curator_payout_value4.881 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length13,966
author_reputation45,447,398,124,687
root_title"control vol of numbers on LCD using push buttons "
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,028,371
net_rshares3,714,639,860,852
author_curate_reward""
vote details (7)
@arul01 ·
thank you for sharing. so increase my knowledge.
properties (22)
authorarul01
permlinkre-lapilipinas-control-vol-of-numbers-on-lcd-using-push-buttons-20180224t071336031z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-02-24 07:13:42
last_update2018-02-24 07:13:42
depth1
children0
last_payout2018-03-03 07:13:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length48
author_reputation2,317,991,190,493
root_title"control vol of numbers on LCD using push buttons "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,029,807
net_rshares0
@m-khan ·
Absolutely Very brilliant post thanks
properties (22)
authorm-khan
permlinkre-lapilipinas-control-vol-of-numbers-on-lcd-using-push-buttons-20180224t070751621z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-02-24 07:07:54
last_update2018-02-24 07:07:54
depth1
children0
last_payout2018-03-03 07:07:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length37
author_reputation29,593,083,027
root_title"control vol of numbers on LCD using push buttons "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,028,827
net_rshares0
@sdtyldz ·
Thank you for the contribution. It has been approved.

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authorsdtyldz
permlinkre-lapilipinas-control-vol-of-numbers-on-lcd-using-push-buttons-20180224t204424293z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-02-24 20:44:24
last_update2018-02-24 20:44:24
depth1
children0
last_payout2018-03-03 20:44:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation97,258,947,871
root_title"control vol of numbers on LCD using push buttons "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,178,438
net_rshares0
@utopian-io ·
### Hey @lapilipinas I am @utopian-io. I have just upvoted you!
#### Achievements
- Seems like you contribute quite often. AMAZING!
#### Suggestions
- Contribute more often to get higher and higher rewards. I wish to see you often!
- Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!
#### Get Noticed!
- Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!
#### Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
authorutopian-io
permlinkre-lapilipinas-control-vol-of-numbers-on-lcd-using-push-buttons-20180225t103833831z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-02-25 10:38:33
last_update2018-02-25 10:38:33
depth1
children0
last_payout2018-03-04 10:38:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,431
author_reputation152,955,367,999,756
root_title"control vol of numbers on LCD using push buttons "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,306,474
net_rshares0