Arduino/C2/Display-counter-using-Arduino/English-timed
Time | Narration |
00:01 | Welcome to the Spoken Tutorial on Display counter using Arduino. |
00:07 | In this tutorial, we will learn to:
connect an LCD and a Push button to Arduino board and write a program to increase the count whenever the pushbutton is pressed. |
00:22 | To follow this tutorial, you should have:
basic knowledge of electronics and basic knowledge of C or C++ programming language. |
00:34 | To record this tutorial, I am using:
Arduino UNO Board, Ubuntu Linux 14.04 operating system and Arduino IDE. |
00:47 | In an earlier tutorial, in this series, we had created a circuit using Arduino and LCD.
We will use the same circuit in this tutorial. |
01:00 | Here, we will add a pushbutton and make a simple counter. |
01:06 | We have already learnt about the working of pushbutton in an earlier tutorial. |
01:12 | Now, let us learn the connection circuit details. |
01:17 | A pushbutton is connected to a 100 ohm resistor. |
01:22 | The pushbutton is connected to pin number 7 and a 100 ohm resistor is connected to the ground. |
01:31 | All other connections are exactly the same as in our previous experiment. |
01:37 | This is the live setup of the connection as shown in the circuit diagram. |
01:44 | Now, we will write a program in the Arduino IDE. So, let’s switch to the Arduino IDE. |
01:54 | First, we need to include the Liquid crystal library. |
01:59 | Type the code as shown. |
02:02 | I have initialized a variable lcd of type LiquidCrystal. |
02:08 | Here, pin number 12 is initialized as Register Select and pin number 11 as Enable. |
02:19 | The next 4 parameters represent data lines of LCD. |
02:25 | In the void setup function, type: lcd.begin 16 comma 2 as shown.
This command initializes the LCD with rows and columns. |
02:41 | Next we will setup the pin number 7 as INPUT. Type the code as shown. |
02:49 | In another way, we can store the pin number in a variable pbutton.
Let us define the pbutton variable as shown. |
03:01 | Now we will write the code for void loop.
Whenever the pushbutton is pressed, one count is increased on the LCD. |
03:11 | We will write a simple 'if' statement to check whether the pushbutton is pressed or not. |
03:19 | Before displaying the count, let us check the status of the button. |
03:25 | This command will set the cursor position in the LCD.
lcd.print will print the message. |
03:35 | We will now compile and upload the program. Now, I will press the pushbutton. |
03:43 | Here, we see the message “button pressed” in the LCD.
It shows that the pushbutton is working successfully. |
03:54 | Next, we will modify the program to set a counter. |
03:58 | We need a variable for counter. Now, we will initialize the variable count to zero. |
04:08 | Modify the print statement as shown here.
count++ will increase the count by one, each time the button is pressed. |
04:21 | Let us now compile and upload the program. Now, I will press the pushbutton. |
04:29 | It didn't work as expected. We see a different count displayed here.
Why is this so? |
04:37 | This is because we specified the status for button pressed.
But we didn't mention the status for button released. |
04:46 | The output shows the incremented number based on the button pressed time. |
04:52 | So, we will write a 'while' statement as shown here. |
04:57 | This will display the count when the pushbutton is in pressed state.
That means the pin 7 is in HIGH mode. |
05:07 | When you release the button, the state is LOW and it will come out of the 'while' loop. |
05:14 | Let me explain the program. |
05:17 | The program starts with initialization of the LCD. We have the variable pbutton and count. |
05:26 | Inside the void setup function, we have initialized the LCD with 16 columns and 2 rows.
Then the pinMode is input for the pin number 7. |
05:42 | In the void loop function, we are checking the condition whether the pushbutton is HIGH or not. |
05:49 | When the pushbutton is pressed, the cursor is set to position zero comma zero. |
05:56 | The lcd.print statement will print the count value.
Initially count is zero. Count plus plus would be 1. |
06:09 | When the button is released, it will break the while loop and come out of the loop. |
06:15 | Again, if you press the button, the next iteration begins and it increases the count. |
06:23 | Let us compile and upload the program. |
06:27 | Now, I'll press the button once and release it. |
06:32 | Again I'll press and release the button. You can see that the count is increased whenever the button is pressed. |
06:42 | This brings us to the end of this tutorial. Let us summarize. |
06:47 | In this tutorial, we learnt to:
connect an LCD and pushbutton to Arduino board and write a program to display the count whenever the pushbutton is pressed. |
07:03 | Do the following assignment.
Change the same program to display the count as 2,4,6 and so on. Compile and upload the program. And, observe the count displayed in the LCD. |
07:21 | The video at the following link summarizes the Spoken Tutorial project. Please download and watch it. |
07:29 | The Spoken Tutorial Project tTeam:
conducts workshops and gives certificates. For more details, please write to us. |
07:38 | Please post your timed queries in this forum. |
07:42 | Spoken Tutorial project is funded by NMEICT, MHRD, Government of India. More information on this mission is available at this link. |
07:53 | This tutorial has been contributed by FOSSEE' and Spoken Tutorial Project, IIT Bombay'. Thanks for watching. |