Introduction: Arduino OLED Calculator

A simple Calculator build with an Arduino.

The project is intended to be a learning tool for kids to understand several aspects of product development. It combines the physical, electrical and programing aspects to build an everyday use item that we now take for granted.

Step 1: Parts List

Step 2: Putting It Together


The keypad has 8 wires, corresponding to the columns and rows of the buttons. These need to be wired to pins D2 through to D9.

OLED Display

The Oled Display has 4 wires, 2 for power and 2 for the I2C interface. The display can run from DC power 3.3v-6v, connect it to the ground and 5v pins of the arduino. Connect SDA to arduino A4 and SCL to Arduino A5.

Step 3: Firmware Code

GitHub Repository

I have uploaded the firmware and the Fritzing file to GitHub but I will briefly go through some of the code to explain the concepts.

OLED Display

The OLED display is controlled through the use of the Adafruit GFX and SSD1306 libraries. If you are using the Yellow blue OLED display the top rows of pixels are yellow and the rest are blue. In my code I use this to my advantage and use this part of the display to show the selected operator for the calculation (+, -, x, /).

---- code example ---

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) showSplash();




--- end of code example ---

The code above is from the setup function of the sketch, the first line initializes the display and sets the I2C address. Note I am using a clone display module and using the 0x3D address, you may have to tweak this if you get your module from somewhere else.

The third line sets the text size, the fourth clears the display and the fifth actually updates the display. Nothing will change until the display.display() method is called.

4x4 Keypad

The following lines setup the keypad configuration

---- code example ---

char keymap[numRows][numCols]=


{'1', '2', '3', '+'},

{'4', '5', '6', '-'},

{'7', '8', '9', 'x'},

{'C', '0', '=', '/'}


---- end of code example ---

This creates a mapping for each of the key of the membrane keyboard, the actual character used is arbitrary but will need to match what is used to identify the key in the rest of the program.

The following lines of code associate the arduino pins to the pins from the keypad.

---- code example ---

byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3

byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

---- end of code example ---

Step 4: The Final Product

Using the calculator

In this implementation we are able to perform addition, subtraction, multiplication and division of integer and floating point numbers, however there is no way of keying in a floating point number directly. Watch the video for a better explanation.

The result from & operation automatically becomes the first operand of the next number unless the clear button is pressed. Buttons A, B, C and D are used for addition, subtraction, multiplication and division respectively. # is used to get the result and * is used to clear the result and display.

Further improvements

Since this project was intended to be a learning tool, I started with a much simpler implementation and made the modifications and the modification process a learning exercise with my students. Further improvements could be made by allowing the user to enter a floating point number and adding memory functions etc.