Build it step by step
0 of 7 doneFind the keypad pins
With a multimeter in continuity mode.
Wire the keypad
Rows to D2 to D5, columns to D6 to D9.
Wire the OLED
SDA to A4, SCL to A5, 5V and GND.
Upload the sketch
The screen asks for the bill.
Type 1000 and press A
Then 4 people and A, then 10 for the tip and A.
Read the result
275.00 each.
Press D
To start again.
How do you build a restaurant bill splitter?
Type the bill, the number of people and a tip percentage on a keypad, and the screen shows each person's share. A handy school maths project that practises reading numbers from a keypad and doing sums on a small chip. You need Arduino Nano, 4x4 matrix keypad (membrane), SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 70 minutes.
- Level
- Beginner
- Time
- About 70 min
- Parts
- 5
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Keypad row pins 1 to 4 | Nano D2, D3, D4 and D5 | Find rows and columns with a multimeter on continuity first |
| Keypad column pins 1 to 4 | Nano D6, D7, D8 and D9 | Same check |
| OLED SDA and SCL | Nano A4 and A5 | I2C data and clock |
| OLED VCC and GND | Nano 5V and GND | Power for a 0.96 inch module |
Code
A 4 by 4 membrane keypad is sixteen switches in a grid of four rows and four columns, and the Keypad library finds which key is pressed and returns it as a character. The sketch collects what you type into three small text fields, one for the bill, one for the number of people and one for the tip percentage, using the star key as a decimal point and the hash key to clear a field. Pressing A moves on to the next field, and after the third it shows the result: the total with tip, and what each person pays, to two decimal places. The tip is added as a percentage, so a bill of 1000 with a 10 percent tip becomes 1100, and for four people each pays 275. D starts again. Keypad connectors are not standard, so find the row and column pins first: with a multimeter in continuity mode, press key 1 and see which two pins beep together, then key 2 and so on. If keys come out wrong, swap the pin lists in the sketch. Install "Keypad" by Mark Stanley, "Adafruit SSD1306" and "Adafruit GFX" from the Library Manager. Try adding a round-up option, or a different share for one person.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Libraries: Keypad by Mark Stanley, Adafruit SSD1306 and Adafruit GFX.
#include <Wire.h>
#include <Keypad.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const byte ROWS = 4, COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8, 9};
Keypad pad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const char *PROMPTS[3] = {"Bill (Rs)", "People", "Tip %"};
char buf[3][9]; // text typed for each field
uint8_t field = 0;
bool showResult = false;
void clearAll() {
for (uint8_t f = 0; f < 3; f++) buf[f][0] = 0;
field = 0;
showResult = false;
}
void draw() {
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(1);
oled.setCursor(0, 0);
if (!showResult) {
oled.print(PROMPTS[field]);
oled.print(F(":"));
oled.setTextSize(2);
oled.setCursor(0, 16);
oled.print(buf[field][0] ? buf[field] : "_");
oled.setTextSize(1);
oled.setCursor(0, 48);
oled.print(F("A=next *=point #=clear"));
} else {
float bill = atof(buf[0]);
int people = atoi(buf[1]);
float tip = atof(buf[2]);
if (people < 1) people = 1;
float total = bill * (1.0 + tip / 100.0);
oled.print(F("Total with tip: "));
oled.print(total, 2);
oled.setCursor(0, 14);
oled.print(F("Each of "));
oled.print(people);
oled.print(F(" pays:"));
oled.setTextSize(2);
oled.setCursor(0, 28);
oled.print(total / people, 2);
oled.setTextSize(1);
oled.setCursor(0, 54);
oled.print(F("D = start again"));
}
oled.display();
}
void setup() {
Serial.begin(9600);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
clearAll();
draw();
}
void loop() {
char k = pad.getKey();
if (!k) return;
uint8_t len = strlen(buf[field]);
if (k >= '0' && k <= '9' && !showResult) {
if (len < 8) { buf[field][len] = k; buf[field][len + 1] = 0; }
} else if (k == '*' && !showResult) { // a decimal point, once
if (len < 8 && !strchr(buf[field], '.')) { buf[field][len] = '.'; buf[field][len + 1] = 0; }
} else if (k == '#' && !showResult) { // clear this field
buf[field][0] = 0;
} else if (k == 'A' && !showResult) { // next field, then the result
if (field < 2) field++; else showResult = true;
} else if (k == 'D') {
clearAll();
}
draw();
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Bill 1000, 4 people, tip 10 | 275.00 each |
| Bill 840.50 with * as the point | Decimals accepted |
| Hash | Clears the current field |
| A on the third field | Shows the result |
| D | Starts again |
If it does not work
Keys come out in the wrong order
Swap the row and column pin lists.
Nothing appears
Check the OLED wires and try address 0x3D.
Decimal point twice
The sketch allows only one in a field.
Share looks wrong
Check you pressed A after each field.
Library not found
Install Keypad by Mark Stanley.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the restaurant bill splitter?
Arduino Nano, 4x4 matrix keypad (membrane), SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the restaurant bill splitter take to build?
About 70 minutes for a beginner maker, in 7 steps.
How do I know the restaurant bill splitter works?
Bill 1000, 4 people, tip 10: 275.00 each. Bill 840.50 with * as the point: Decimals accepted. Hash: Clears the current field.
Keys come out in the wrong order: what should I check?
Swap the row and column pin lists.
Nothing appears: what should I check?
Check the OLED wires and try address 0x3D.
Decimal point twice: what should I check?
The sketch allows only one in a field.
Share looks wrong: what should I check?
Check you pressed A after each field.
