Simple Arduino Calculator

by Progetto Company in Circuits > Arduino

561 Views, 1 Favorites, 0 Comments

Simple Arduino Calculator

calculator_thumbnail.jpg
Simple Arduino Calculator
PXL_20210702_200436176.jpg

DISCLAIMER: CERTAIN COMPONENTS USED IN THIS TUTORIAL ARE FOR SALE BY THE AUTHOR

During this tutorial, you'll create a simple Arduino calculator with basic arithmetic operators and support for numbers with decimals. However, this calculator does have other limitations, to simplify the code, this calculator evaluates the result from left to right, without regard for the order of operations. It also has no support for negative numbers. However, feel free to implement this yourself as a coding challenge. Be sure to see the video above for a demo!

Supplies

To build this calculator, you'll need:

- An Arduino microcontroller of some flavour, preferably with a 5V operating voltage as the 16x2 I2C LCD is a 5V component, though it can be adapted using a logic level converter like this one: https://www.tindie.com/products/Progetto/4-channel-bidirectional-logic-level-converter/

- 2 male to male and 7 male to female jumper wires

- A breadboard (any of the 3 most common sizes will do)

- An I2C 16x2 LCD like this: https://www.tindie.com/products/Progetto/16x2-lcd-display-with-pre-soldered-i2c-backpack/ (either colour will work, though I used the green version with black text)

- A One Pin Keypad module and a 4x4 Keypad: https://www.tindie.com/products/Progetto/one-pin-keypad/ (make sure you include the keypad using the product option)

- Optional: supplies to make stickers for the keypad buttons

Familiarize Yourself With the Components

PXL_20210702_195004307.jpg
PXL_20210702_194313418.jpg

This tutorial assumes you have set up your One Pin Keypad using this tutorial: https://www.instructables.com/Meet-One-Pin-Keypad/ having already installed the One Pin Keypad library and have access to your array of calibrated thresholds.

This tutorial also assumes you have followed this amazing tutorial by Last Minute Engineers https://lastminuteengineers.com/i2c-lcd-arduino-tutorial/ so you know your LCD's I2C address and can wire it to your Arduino.

(Optional) Decorate Your 4x4 Keypad

PXL_20210702_195145717.jpg
PXL_20210702_195504733.jpg

How you decide to do this is up to you, but I used masking tape and a sharpie to indicate which button on the keypad represents each calculator operation. See the image above for reference.

Wiring

calculator_schematic.png
PXL_20210702_195055546.jpg

Having followed the tutorials in the previous step, your calculator should already be wired correctly. But I have included a schematic above just in case. As for power, this project runs fine powered through the Arduino's USB port.

Upload the Code

code.JPG

Get the project's code from here: https://github.com/ProgettoCompany/Simple_Arduino_Calculator

Make sure to change the myThresholds array (see line 124) to your calibrated values from the One Pin Keypad tutorial linked in step 2.

If the LCD isn't working:

Double-check your wiring, your LCD's I2C address and that you've adjusted the contrast of the display correctly.

If the keypad isn't working:

Double-check your wiring, that you've calibrated the One Pin Keypad correctly and replaced the myThresholds array as described above.

Conclusion

calculator_conclusion.jpg

Congratulations, you have created your own calculator! Feel free to remix and improve this project to your heart's content, maybe add a case, battery power, support for negative numbers, or order of operations!

If you have any questions, comments or concerns, feel free to email me at progettocompany@gmail.com

Happy hacking!

John Wolf

Progetto Company