Build it step by step
0 of 7 doneWire the buttons
D2, D3 and D4 each to GND through a button.
Wire the display
5V or 3V3, GND, SDA to A4, SCL to A5.
Install the libraries
Adafruit SSD1306 and GFX.
Upload the sketch
The display shows three zero counts.
Press each button a few times
The counts and percentages change.
Unplug and plug in
The counts are still there.
Hold happy and sad together
After three seconds the counts clear.
How do you build a feedback smiley button box?
Three buttons labelled happy, so-so and sad count the opinions of visitors at a stall or in a class, and a Nano shows the totals on an OLED and keeps them in memory through a power cut. You need Arduino Nano, Tactile push button 6 mm × 3, SSD1306 OLED Display, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 7 steps and about 100 minutes.
- Level
- Beginner
- Time
- About 100 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 |
|---|---|---|
| Happy button | Nano D2 and GND | Counts a happy vote |
| So-so button | Nano D3 and GND | Counts a so-so vote |
| Sad button | Nano D4 and GND | Counts a sad vote |
| OLED VCC | Nano 5V | Power (check your OLED accepts 5 V, otherwise use 3V3) |
| OLED GND | Nano GND | Common ground |
| OLED SDA and SCL | Nano A4 and A5 | I2C, address 0x3C |
Code
This is a tiny feedback terminal. Each button is wired to a pin that is held high by the board's internal pull-up and pulled low when the button is pressed, and the program counts each press once, ignoring any repeat within a quarter of a second so a bounce or a long press does not count twice. The three counts are shown with their share of the total on the OLED. They are also saved in the Nano's EEPROM, a small memory that keeps its data without power, so a power cut or an unplugged cable does not lose the votes. EEPROM can only be rewritten about a hundred thousand times, which is plenty for a day's use at a stall, but this is not meant for millions of presses. To clear the counts, hold the happy and sad buttons together for three seconds. Only the three totals are stored, with no names, no times and nothing about who pressed. Put clear labels or pictures on the buttons, and tell people what the box is for. Stick the buttons and the board to a card so they do not move when pressed.
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).
#include <Wire.h>
#include <EEPROM.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const uint8_t PINS[3] = { 2, 3, 4 }; // happy, so-so, sad
const char* NAMES[3] = { "Happy", "So-so", "Sad" };
unsigned int counts[3];
bool last[3] = { HIGH, HIGH, HIGH };
unsigned long lastPress[3] = { 0, 0, 0 };
unsigned long bothSince = 0;
void save() {
for (int i = 0; i < 3; i++) EEPROM.put(i * 2, counts[i]); // two bytes per count
}
void draw() {
unsigned long total = (unsigned long)counts[0] + counts[1] + counts[2];
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(1);
oled.setCursor(0, 0);
oled.print("Feedback total ");
oled.print(total);
for (int i = 0; i < 3; i++) {
oled.setCursor(0, 16 + i * 16);
oled.setTextSize(2);
oled.print(counts[i]);
oled.setTextSize(1);
oled.setCursor(60, 20 + i * 16);
oled.print(NAMES[i]);
oled.print(" ");
if (total > 0) oled.print(counts[i] * 100UL / total);
else oled.print(0);
oled.print("%");
}
oled.display();
}
void setup() {
for (int i = 0; i < 3; i++) pinMode(PINS[i], INPUT_PULLUP);
Wire.begin();
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
for (int i = 0; i < 3; i++) {
EEPROM.get(i * 2, counts[i]);
if (counts[i] == 0xFFFF) counts[i] = 0; // a fresh chip reads as all ones
}
draw();
}
void loop() {
for (int i = 0; i < 3; i++) {
bool now = digitalRead(PINS[i]);
if (now == LOW && last[i] == HIGH && millis() - lastPress[i] > 250) {
lastPress[i] = millis();
counts[i]++;
save();
draw();
}
last[i] = now;
}
// Hold the happy and sad buttons together for three seconds to clear the counts
if (digitalRead(PINS[0]) == LOW && digitalRead(PINS[2]) == LOW) {
if (bothSince == 0) bothSince = millis();
if (millis() - bothSince > 3000) {
for (int i = 0; i < 3; i++) counts[i] = 0;
save();
draw();
bothSince = millis();
}
} else {
bothSince = 0;
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Start (new board) | 0, 0, 0 |
| Press happy three times | Happy 3 and 100 percent |
| Press sad once | Sad 1, shares change |
| Unplug and plug in | Counts kept |
| Hold happy and sad for 3 seconds | All zero |
If it does not work
Counts jump
Check the button wires and the common ground.
Counts do not stay
Check the sketch saves to EEPROM and that you have not reset it.
Display blank
Check the OLED address 0x3C and the I2C wires.
Two counts per press
Press and release cleanly, or lengthen the 250 ms wait.
Strange numbers at first
Clear the counts once with the two-button hold.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the feedback smiley button box?
Arduino Nano, Tactile push button 6 mm × 3, SSD1306 OLED Display, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.
How long does the feedback smiley button box take to build?
About 100 minutes for a beginner maker, in 7 steps.
How do I know the feedback smiley button box works?
Start (new board): 0, 0, 0. Press happy three times: Happy 3 and 100 percent. Press sad once: Sad 1, shares change.
Counts jump: what should I check?
Check the button wires and the common ground.
Counts do not stay: what should I check?
Check the sketch saves to EEPROM and that you have not reset it.
Display blank: what should I check?
Check the OLED address 0x3C and the I2C wires.
Two counts per press: what should I check?
Press and release cleanly, or lengthen the 250 ms wait.
