Activity 2. LCD 16x2 and push-buttons
In this activity the Arduino Uno reads 2 push-buttons. One push-button hides the text written on a liquid crystal display, while the other push-button reappears the text. (50 minutes)
Activity 2
The text on the LCD is not erased. The text is displayed or not by the display() and noDisplay() functions.
Step 1. Draw the circuit in Tinkercad.
Step 2. Study the code and write it on the microcontroller:
/* LCD display() / noDisplay()
Circuit Connections: ** LCD
Ground => Gnd
Power => Vcc
Contrast => Potentiometer
RS => PIN_0
RW => Gnd
E => PIN_1
DB0 => Gnd
DB1 => Gnd
DB2 => Gnd
DB3 => Gnd
DB4 => PIN_2
DB5 => PIN_3
DB6 => PIN_4
DB7 => PIN_5
LED Anode => Vcc
LED Cathode => Resistor 220Ω => Gnd
** Potentiometer
Terminal 1 => Gnd
Wiper => LCD_Contrast
Terminal 2 => Vcc** PIN_8 (built-in pullup) => Push-button1 => Gnd ** PIN_9 (built-in pullup) => Push-button2 => Gnd */
//include the library #include <LiquidCrystal.h>
#define RS 0 //give the name "RS" to PIN_0
#define EN 1 //give the name "EN" to PIN_1
#define DB4 2 //give the name "DB4" to PIN_2
#define DB5 3 //give the name "DB5" to PIN_3
#define DB6 4 //give the name "DB6" to PIN_4
#define DB7 5 //give the name "DB7" to PIN_5#define pb1 8 //give the name "pb1" to PIN_8 #define pb2 9 //give the name "pb1" to PIN_9
//configure the library with Arduino Uno - LCD interface
LiquidCrystal lcd(RS, EN, DB4, DB5, DB6, DB7);//The setup() function initializes and sets the initial values //It will only run once after each powerup or reset void setup() { //Configure the PIN_8 to behave as input with pull-up resistor pinMode(pb1, INPUT_PULLUP); //Configure the PIN_9 to behave as input with pull-up resistor pinMode(pb2, INPUT_PULLUP); //configure the LCD's columns and rows lcd.begin(16, 2); //print a message lcd.print("can you see me?"); }
//This function loops consecutively void loop() { //check the push-button1 if(digitalRead(pb1)==false){ //pb1 is pressed delay(25); //wait for debouncing while(digitalRead(pb1)==false){;} //until pb1 is released lcd.noDisplay(); //the text is disappeared } //check the push-button2 if(digitalRead(pb2)==false){ //pb2 is pressed delay(25); //wait for debouncing while(digitalRead(pb2)==false){;} //until pb2 is released lcd.display(); //the text is appeared } }
Step 3. Run the simulation and check the correct operation of the circuit
Step 4. Suggested modifications and discussion:
Instead of two, could the application work with one push-button?
Add a switch. When the switch is open, the text on the LCD can be hidden by the corresponding push-button. When the switch is closed, the text on the LCD will be displayed whether a push-button is pressed or not.
Write the appropriate code and run the simulation