How To Push Button With LCD

Required Hardware

For users who do not have Hackerspace Karachi Arduino Kit v1.0

  • Arduino Board
  • Breadboard
  • Push-button
  • I2c LCD
  • Resistor 220 ohm
  • Hook-up Wires

Circuit

For users who do not have Hackerspace Karachi Arduino Kit v1.0

Schematic

Code

                    

1. /*
2. Push Button with LCD
3.
4. This example shows how to use Push Button with LCD
5.
6.
7. The circuit:
8. – LCD
9. SDA connected to analog pin A4.
10. SCL connected to analog pin A5.
11.
12. – Push Button
13. Anode connected to VCC.
14. Cathode connected to digital pin 2.
15. Cathode connected to GND through 220 resistor.
16.
17. http://hackerspacekarachi.org/
18. */
19. //Library version:1.1
20. #include <Wire.h>
21. #include <LiquidCrystal_I2C.h>
22.
23. LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2
line display
24.
25. void setup()
26. {
27. pinMode(2, INPUT); // declaration of input
28. lcd.init(); // initialize the lcd
29. lcd.init();
30. lcd.backlight();
31.
32. }
33.
34.
35. void loop()
36. {
37. int d = digitalRead(2); // read and store input
38.
39. if (d == 1)
40. {
41. lcd.setCursor(0, 0);
42. lcd.print(“BUTTON PRESSED”); // print push button state
43. delay(1000);
44. lcd.clear();
45. }
46.
47. }

1. /*