Defuse the Bomb Game
Build a bomb defusal game using Arduino with a keypad and LCD for entering passwords and countdown timer.
- Arduino
- Advanced
- 120 minutes
- 4 steps
Shop this project
CartYou'll need
Prices from vilros.com. Tax and shipping at checkout.
Before you start, you'll need
- Arduino Uno
- 16×2 LCD display
- 4×4 membrane keypad
- Breadboard
- Jumper wires (11+)
- 4× 10kΩ resistors
Connect keypad and LCD
About 30 minutes
Wire all components to Arduino.
- Connect 5V and GND rails to breadboard.
- Connect LCD to Arduino (refer to LCD datasheet for pins).
- Connect keypad columns to Arduino pins 6-9.
- Connect keypad rows to Arduino pins 10-13.
- Add 10kΩ pull-down resistors from each row pin to GND.
You should see
LCD powers on and keypad is wired.
Upload bomb defusal code
About 60 minutes
Program the game logic.
- Open Arduino IDE.
- The code asks for a 4-digit password and time limit at startup.
- During gameplay, user enters the password on keypad.
- Timer counts down. Game ends if password is correct or time expires.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int rows[4] = {13, 12, 11, 10};
const int cols[4] = {9, 8, 7, 6};
char keypad[4][4] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
char password[4];
char userInput[4];
int inputIndex = 0;
int timeLimit = 0;
unsigned long startTime = 0;
bool gameActive = false;
void setup() {
lcd.begin(16, 2);
for (int i = 0; i < 4; i++) {
pinMode(rows[i], INPUT);
pinMode(cols[i], OUTPUT);
}
lcd.print("Enter 4-digit");
lcd.setCursor(0, 1);
lcd.print("password then #");
delay(2000);
// Get password from user
inputIndex = 0;
while (inputIndex < 5) {
char key = readKeypad();
if (key) {
password[inputIndex] = key;
lcd.print(key);
inputIndex++;
delay(300);
}
}
// Get time limit
lcd.clear();
lcd.print("Time (min) + #");
delay(2000);
// Simplified: assume 3 minutes
timeLimit = 180;
lcd.clear();
lcd.print("Defuse bomb!");
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(timeLimit);
lcd.print("s");
startTime = millis();
gameActive = true;
}
void loop() {
if (!gameActive) return;
int elapsed = (millis() - startTime) / 1000;
int remaining = timeLimit - elapsed;
if (remaining <= 0) {
lcd.clear();
lcd.print("BOOM!");
lcd.setCursor(0, 1);
lcd.print("You lose!");
gameActive = false;
return;
}
lcd.setCursor(6, 1);
lcd.print(" ");
lcd.setCursor(6, 1);
lcd.print(remaining);
lcd.print("s");
char key = readKeypad();
if (key) {
userInput[inputIndex] = key;
inputIndex++;
if (inputIndex == 4) {
bool correct = true;
for (int i = 0; i < 4; i++) {
if (userInput[i] != password[i]) {
correct = false;
break;
}
}
if (correct) {
lcd.clear();
lcd.print("Bomb Defused!");
lcd.setCursor(0, 1);
lcd.print("You win!!");
gameActive = false;
} else {
lcd.clear();
lcd.print("Wrong code!");
delay(1000);
lcd.clear();
lcd.print("Defuse bomb!");
inputIndex = 0;
}
}
delay(300);
}
}
char readKeypad() {
for (int c = 0; c < 4; c++) {
digitalWrite(cols[c], HIGH);
for (int r = 0; r < 4; r++) {
if (digitalRead(rows[r])) {
digitalWrite(cols[c], LOW);
return keypad[r][c];
}
}
digitalWrite(cols[c], LOW);
}
return 0;
}Simplified version. Full version includes time input parsing.
You should see
Game runs: enter password, then defuse before time expires.
Play test the bomb game
About 10 minutes
Verify all game mechanics work.
- Set a password at startup.
- Watch the countdown timer.
- Try entering wrong codes.
- Enter the correct code to defuse.
- Test time expiring (BOOM!).
You should see
Game works: timer counts down, correct password wins, timeout loses.
It didn't work
Keypad reads multiple presses.
Increase delay after key read (300ms or more). Add debouncing logic.
Enhance the game (optional)
About 20 minutes
Add LEDs and sound effects.
- Add red LEDs that flash faster as time runs out.
- Add buzzer for countdown beeps.
- Add green LED that lights when bomb is defused.
- Program LED patterns for BOOM and WIN states.
You should see
Enhanced game has visual and audio feedback.
What to do next
Stuck? Contact Vilros Support with your board model and what you see on screen.