Remote-controlled RGB mood light
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Shop by category
Shop all componentsCollect votes for three candidates, guard against double-counting from a single press, and show the result on demand. A mechanical button does not close cleanly, its contacts bounce for a few milliseconds, and a fast Arduino can read that as five or six separate presses. Waiting 50 ms after the first LOW and then waiting for release is the simplest reliable debounce, and in a voting machine it is the difference between one vote and six. The tallies themselves are just integers being incremented, one per candidate.
Every part for this build comes in the Geekobot Explorer Kit box, a Geekobot exclusive, together with the parts for all 61 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
The brain of every Explorer Kit project
Male-to-female and female-to-female leads for the modules
16x2 LCD with I2C backpack: four wires, two lines of text
Nano I/O shield from the kit: every pin has its own S, V, G header, so modules plug in with jumpers
Follow the colours: red is power, dark grey is ground, blue is a signal.
explorer_kit_53_voting_machine.inoVerify & upload in Electrolark#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int votePins[3] = {2, 3, 4};
int resultPin = 5;
int buzzer = 8;
String candidates[3] = {"CANDIDATE A", "CANDIDATE B", "CANDIDATE C"};
int votes[3] = {0, 0, 0};
int totalVotes = 0;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void beep(int ms)
{
digitalWrite(buzzer, HIGH);
delay(ms);
digitalWrite(buzzer, LOW);
}
void showPrompt()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Cast your vote");
lcd.setCursor(0, 1);
lcd.print("Total: ");
lcd.print(totalVotes);
}
void showResult()
{
int winner = 0;
for (int i = 1; i < 3; i++)
{
if (votes[i] > votes[winner])
{
winner = i;
}
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("A:");
lcd.print(votes[0]);
lcd.print(" B:");
lcd.print(votes[1]);
lcd.print(" C:");
lcd.print(votes[2]);
lcd.setCursor(0, 1);
if (totalVotes == 0)
{
lcd.print("No votes yet");
}
else
{
lcd.print("Lead: ");
lcd.print(candidates[winner].substring(10));
}
beep(300);
delay(5000);
showPrompt();
}
void setup()
{
for (int i = 0; i < 3; i++)
{
pinMode(votePins[i], INPUT_PULLUP);
}
pinMode(resultPin, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
lcd.init();
lcd.backlight();
showPrompt();
}
void loop()
{
for (int i = 0; i < 3; i++)
{
if (digitalRead(votePins[i]) == LOW)
{
delay(50); // Debounce
if (digitalRead(votePins[i]) != LOW)
{
continue;
}
votes[i] = votes[i] + 1;
totalVotes = totalVotes + 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Vote recorded");
lcd.setCursor(0, 1);
lcd.print(candidates[i]);
beep(120);
Serial.print("Vote for ");
Serial.println(candidates[i]);
while (digitalRead(votePins[i]) == LOW) // Wait for release
{
delay(10);
}
delay(800);
showPrompt();
}
}
if (digitalRead(resultPin) == LOW)
{
delay(50);
showResult();
}
}
Use the kit's mini-USB cable, install the CH340 driver on Windows if no port appears, pick Tools > Board > Arduino Nano and try Tools > Processor > ATmega328P (Old Bootloader) if the upload times out.
The sketch uses INPUT_PULLUP, so one leg goes to the pin and the other to GND. Use two legs on opposite sides of the button.
The active buzzer has a + leg: it goes to the pin, the other to GND. Peel off the sticker on top if it has one.
Turn the small contrast pot on the back of the I2C board. If still blank, change 0x27 in the sketch to 0x3F.
A mechanical button does not close cleanly, its contacts bounce for a few milliseconds, and a fast Arduino can read that as five or six separate presses. Waiting 50 ms after the first LOW and then waiting for release is the simplest reliable debounce, and in a voting machine it is the difference between one vote and six. The tallies themselves are just integers being incremented, one per candidate.
LCD shows Cast your vote / Total: 0. Press a candidate button: Vote recorded / CANDIDATE A with a short beep. The total climbs by exactly one per press, however long you hold it.
Yes. It is project 53 of 61 in the Geekobot Explorer Kit, in level 9 (Interactive games). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Explorer Kit project is wired on the Nano I/O shield and the breadboard with jumper wires.
7 parts: Generic Nano CH340 Development Board (Soldered), USB Cable, Dupont Jumper Wires (40 pcs), 4 × Tactile Push Button Switch, PCB Mounted Active Buzzer Module, LCD1602 16x2 Character LCD Display and Arduino Nano IO Expansion Shield (328P Compatible). On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 1 hour. The build on this page has 6 steps.
No. This page has the complete, tested code (explorer_kit_53_voting_machine.ino).
About ₹586 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Button debouncing in software; Incrementing counter variables; Finding the largest value in an array; Separating data entry from result display.
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Press to roll: the pips tumble and slow down before landing on a number.
Wait for the light, hit the button: how many milliseconds can you beat?
A bright 4-digit clock that keeps time through power cuts.
Learning project. Check every circuit and the datasheet of each part before you power it up.