0:00
Welcome back to our channel. Today we're diving into an exciting Arduino project
0:04
We'll be creating a menu system controlled by a push button and displaying the menu on an i2c LCD
0:09
Let's get started. Here's what you'll need for this project. An Arduino Uno, a push button, a 16x2 i2c LCD
0:21
display, a breadboard and some jumper wires, a 10k ohm resistor. First, let's connect everything
0:30
Here's the circuit diagram. Connect the push button to digital pin 2 on the Arduino
0:35
One side of the push button goes to 5v and the other side connects to ground through a 10k ohm
0:40
resistor. The same side that goes through the resistor also connects to digital pin 2
0:45
Next, connect the i2c LCD. The SDA pin connects to A4 and the SCL pin connects to A5 on the Arduino
0:52
Connect VCC to 5v and GND to GND. Here's how I assembled this circuit
1:58
Now let's dive into the code. We'll be using the liquidcrystal underscore i2c library to control
2:02
the LCD. To install it, you need to download it first. I'll be posting the link to the library
2:08
in the description. After downloading, open your Arduino IDE, go to sketch, include library
2:13
add zip library, locate the downloaded zip file and click open to install. With the library
2:19
installed, it's time to write some code. Let's break down the code. First, we include the
2:23
necessary libraries, wire.h for i2c communication and liquidcrystal underscore i2c.h for controlling
2:30
the LCD. We define the LCD object with the specific pins connected to the i2c module
2:36
We also define the button pin and create variables to track the button state and the current menu
2:40
In the setup function, we initialize the LCD with lcd.begin 16 2 to set it up as a 16 by 2 display
2:48
We also turn on the backlight with lcd.backlight and set the button pin as an input
2:52
The loop function reads the button state with digital read x. If the button is pressed
2:57
we increment the led underscore num variable to cycle through the menu options. Here's an
3:01
important part of the code. When the button is pressed, digital read x will return a value of 1
3:06
This condition checks if the button is pressed. If true, we increment the led underscore num
3:11
variable by 1. This variable keeps track of the current menu mode. Every button press advances
3:16
led underscore num to the next value. The button is pressed when the button is pressed
3:21
We increment the led underscore num to the next mode. Depending on the value of led underscore num, we clear the LCD and display the corresponding mode
3:30
When led underscore num reaches 3, it resets to 0 to start the cycle over. The delay 300 function
3:37
ensures a 300 millisecond pause between readings to debounce the button and avoid multiple triggers
3:42
from a single press. Now let's upload the code to the Arduino and see it in action
3:51
Now let's see how we can use this menu system in a practical application
3:59
Imagine we're creating a simple lighting control system with different modes. In mode 1, the led is off. In mode 2, the led is on. In mode 3, the led blinks. Let's update
4:09
our code to include these functionalities. In this updated code, we added an led connected
4:16
to pin 13. In mode 1, the led is off. In mode 2, the led is on. In mode 3, the led blinks 5 times
4:23
before resetting back to mode 1. Let's see it in action. When you press the button, the menu
4:27
options cycle through and the led responds according to the selected mode
4:46
This demonstration shows just one example of how you can use a simple menu system for practical
4:51
applications. Feel free to customize and expand it further to fit your specific projects
4:56
Thanks for watching! If you enjoyed this video, give it a thumbs up and subscribe for more Arduino
5:00
projects. Don't forget to hit the bell icon to get notified of our latest uploads. Happy building