Introduction: Electronic Calculator Project - Jasdeep Sidhu

The Arduino is an easy and fun to use microcontroller that could be utilized in many different projects. Today we will be using the Arduino Microcontroller along with a 4x4 Keypad to create a basic calculator that can add, subtract, divide, and multiply! This project is very useful and could be used at home, school, or even at the workplace, it is very quick and efficient when It comes to solving small mathematical problems. I hope you learn and have fun while creating this calculator! Enjoy!

Firstly let's take a look at some of the supplies you will need to create this basic calculator!

Supplies

1. Arduino Microcontroller (1)

2. Keypad 4x4 (1)

3. LCD 16x2 (1)

4. 200Ω Resistor (1)

5. Wires (22)

Step 1: Materials Needed

There are some main components that are needed in order to create this project. Firstly we need one Arduino Microcontroller. The Arduino is the most important component in this circuit as it could be purchased by clicking this link.

Secondly, we will also need one 4x4 keypad. This will allow the user to enter their math problem into the calculator. This is also a very important component to create this project. This keypad could be purchased by clicking this link.

Thirdly, we will need one 16x2 LCD. This is the screen that will display the mathematical question and answer. This component can be purchased through this link.

Fourthly, we need one 200 Ω Resistor. Resistors are quite easy to use and are extremely important for this project. You could purchase these resistors from this link.

Lastly, we will need 22 wires to complete the circuit. These wires could be purchased from this link.

Step 2: Connect GND & 5V

After we gather all materials we must move to the next step. This step is connecting the 16x2 LCD to the Arduino. We must allow the LCD to obtain power and ground from the Arduino Microcontroller. In order to do this we will need 4 wires, one 200 Ω resistor, and the 16x2 LCD. Firstly, lets start by connecting the 5V pin on the Arduino to the VCC on the LCD. This will allow the LCD to obtain power from the Arduino as the VCC connector is also known as the Voltage Common Collector. The next step is to connect the ground pin (GND) on the Arduino to the ground connector on the LCD (GND). For the next step we will need one more wire and the 200 Ω resistor. This will allow us to connect the GND pin on the Arduino to the LED pin on the 16x2 LCD. We must use the resistor to reduce the current flow to the LCD as without the resistor the LCD would not work correctly as it would be getting too much current flow. Lastly, we must make one more GND connection, this will connect the GND pin on the Arduino to the V0, also known as the Contrast connection point.

After we have all 4 of these wires correctly connected we can move on to the next step.

Step 3: LCD Connections

For the third step, we must finish all of our LCD connections. We must properly and accurately connect each wire in order for the Arduino to be correctly linked with the LCD. In this step, we will need 6 more wires to connect the digital pins on the Arduino to the 16x2 LCD. The first connection we will make will connect digital pin 8 to DB7 (green wire). Next, we will connect pin ~9 to DB6 (turquoise wire), and also connect pin ~10 to DB5 (blue wire). Next, we must connect pin ~11 on the Arduino to DB4. Next, we must connect pin 12 to E on the LCD. The "E" connector on the LCD is also called the Enable. Lastly, we will connect pin 13 to the RS connector. The "RS" connector is also known as the Register Select.

After all of these connections are made, the circuit should look like the picture shown above. We are almost done!

Step 4: Finalize LCD Connections

This is a very simple but important step in this circuit. In the image above you will see one gray wire, this wire must be used in order to allow the LCD to look the best. When we connect the VCC connector to the LED connector it allows the LCD to become brighter, causing the screen to have better visibility. Although this is an optional connection (as the LCD works without it), it is a good addition to any calculator circuit as it allows the LCD to become much brighter as seen in the images above.

Step 5: Connect the 4x4 Keypad

Now we must connect the 4x4 keypad to the Arduino. We must connect digital pins 0 to 7 to the 8 different connectors on the keypad. Firstly, we must connect D0 on the Arduino to column 4 on the keypad. Next, we must connect D1 to column 3 on the keypad. Then we will attach D2 to column 2, and connect D3 to column 1. The pin D4 will be linked with Row 4 on the keypad, D5 will be connected with Row 3, D6 with row 2, and D7 with row 1.

After all these connections are made the 4x4 Keypad will be properly set up and will be ready to use. The keypad is so important as without it the user will not be able to type their mathematical problem into the calculator. As a result, make sure to carefully connect the keypad to the Arduino.

If the wires are incorrectly connected the formatting of the keypad will not make sense, causing the calculator to be extremely confusing to use.

After all of the wires are connected properly the circuit should look like the photos shown above.

Step 6: Let's Code!

Now that we have finished the hardware component of our project, let's move over to the software.

Firstly, let's take a look at the necessary libraries that we must incorporate into this code. We need two main libraries in order for this code to work. We need, Keypad.h, and LiquidCrystal.h. Each of these libraries may look confusing, however, they are very simple to understand and use. Keypad.h allows us to connect the keypad we used to row-column code, which allows us to code what each key on the keypad does. Next, LiquidCrystal.h allows the Arduino Microcontroller to properly use and control the LCD (Liquid-Crystal-Display).

Secondly, we can take a closer look at the keypad formatting (where they keypad.h library becomes important). We can use RowPins along with ColPins to allow the circuit to understand what digital pins are used as row pins and column pins. In this case RowPins are 7,6,5,4 while ColPins are 3,2,1,0.

Thirdly, in the void setup() function we can see what the start-up messages are. These messages are simply printed onto the LCD by using lcd.print.

Fourthly, we can see within the void loop() function there are many lines of code, and within these lines, I used a switch statement. This allows the circuit to understand that if -, +, /, or * is clicked then what they should do. It provides the circuit with a series of instructions depending on what button is clicked by the user.

After all these steps are done, the code should look like the photos above! This code may look complex but it is quite easy to understand and learn.

Step 7: Enjoy!

Now that we are done both the hardware and software components of this project we are officially done! Thank you for looking at my tutorial and I hope you enjoyed it!