Introduction: 2-Button Quadratic Equation Solver


welcome to my first instructable!

I started this project to extend my programming knowledge. Often, you just merge different source code to create the program you need. My goal was to write my own program code for interacting with a tool. I liked to create a simple tool for calculating. Some month ago, I supported a friend to solve quadratic equation.

Bazinga! this is the use case!

I reused an old metal box. I prefered the minimalistic look and interface of tools. that is reason why I just want to use 2 buttons for giving input. The contend will be shown by a simple LCD display.


material list:


2 button --> Arcade style

Arduino Nano, or similar

LCD display 1602 with I2C adapter

on/off switch


2x 10k Ohm resistor

battery 9v block

connector for 9v battery


miscellaneous (piece of wood, metal angle, cable ties, screw, washers)



soldering iron

drilling machine

computer for programming

Step 1: ​Mathimatical Backround

Mathimatical backround

The 2-button quadratic equation shows the values where the quadratic function crosses the X-axis. A quadratic function can cross X-axis never, once or twice.

There are different ways to calculate these values. For my tool, I use the PQ-formula (I am not sure, whether this expression will be used all over the world).

A quadratic equation has the form:


To calculate the crossing points, divide the form by a --> x²+px+q=0 with p= b/a; q=c/a

the PQ Formula:

x1 = -p/2 + sqrt((p/2)²-q)

x2 = -p/2 - sqrt((p/2)²-q)

The result x can get 0, 1 or 2 values. That depends on the value under the square root.

Is the value > 0, then the PQ-Formula has two solutions.

Is the value = 0, then the PQ-Formula has one solution

is the value < 0, then the PQ Formula has no solution. The function does not cross the X-Axis.

Step 2: Software


For programming I used the official Arduino IDE. My target was to create my own software program. My interface should have two buttons. One button to step between different levels, the second button to change the values in the different levels.

To solve the PQ-Formula, I create the structure above:

For sure, I do not reinvent the wheel. For creating the code, I used the module:

- debounce

- display

Following points were the biggest challenges:

- How can I choose the sign? I solved this challenge with the function modulo (link). The code divides the input by 2. Is the input an odd number, the value gets negative, otherwise the number is positive.

- After running through all levels, I have to declare all values to 0.

- The displayed text just erases the send characters. If the codes send a word with 4 characters, just these 4 characters will be reloaded. If the word before had more characters, the characters will stay. To fix that, the displayed text will be filled up with blanks. All 16 characters in a row will be reloaded.

The final code is attached.

Step 3: Hardware


The parts are listed in above. For this project, the hardware is simple. I just need an Arduino microprocessor, 2 button and a display. Okay, if you like to put in a box, you need a box and power supply as well.

I reuse an old metal box. I drilled a hole into the button for plug in the switch for power supply. The box cover got 3 holes. I drilled two holes for the big buttons and cut a window for the display. I stick a small piece of wood behind the cover to have more stuff to fix display and buttons. To upgrade the look the box got stickers.

For power supply, I recommend rechargeable 9V block batteries. I connect the battery via power switch to the Arduino. The battery is fixed to the box with a small metal angle. The connector for the battery is just fixed by cable ties.

The microprocessor is a clone of an Arduino nano. For this use case, the performance is sufficiently. An Attiny 85, for example a Digispark microprocessor, was rejected. The Arduino is "bread boarded" next to the display.

The display is a 1602 LCD display. you can use 16 characters in two rows. You can find this display in many different machines an tools. There are two different ways to use this display. You can connect the display directly to the controller or you can use an add-on for communicate to the display via I2C. I2C is a standard protocol. I used it, because it is easier to connect the display to the controller. You just need 4 cables instead of 16, VCC to 5V, GND to GND, SDA to A4, SCL to A5. The display is fixed by screws to the box cover.

The buttons are huge! they have the typical arcade game style. I like it! The buttons are connected to digital pin 4 and 7. Please do not forget the 10K Resistors!

To open the cover, for example to exchange the battery, I used longer cables plugged onto the breadboard.

Step 4: Wiring

Step 5: Future Improvement

Future Improvement

After finishing a project, you always find bugs or features for improvement. In this project, I am happy to just find a few of points, I would improve for future.

For next time, I would improve the exploitation in the box. I fixed the display, the power switch, and the buttons at the beginning of this project. At the end, I got a bit trouble to find enough space for the battery and the microprocessor in the box. When I put the button and the display more outside, I would not have any trouble with the space for the parts inside the box.

At the moment I do not have a use case for solving quadratic equation. To improve the tool, I would like to expand the tool with further mathematical things, for example basic calculus or formulas like binominal formula or sentence of the Pythagoras.

Made with Math Contest

Participated in the
Made with Math Contest