Skip to content

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

Cart

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.

  1. Connect 5V and GND rails to breadboard.
  2. Connect LCD to Arduino (refer to LCD datasheet for pins).
  3. Connect keypad columns to Arduino pins 6-9.
  4. Connect keypad rows to Arduino pins 10-13.
  5. 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.

  1. Open Arduino IDE.
  2. The code asks for a 4-digit password and time limit at startup.
  3. During gameplay, user enters the password on keypad.
  4. Timer counts down. Game ends if password is correct or time expires.
cpp
#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.

  1. Set a password at startup.
  2. Watch the countdown timer.
  3. Try entering wrong codes.
  4. Enter the correct code to defuse.
  5. 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.

  1. Add red LEDs that flash faster as time runs out.
  2. Add buzzer for countdown beeps.
  3. Add green LED that lights when bomb is defused.
  4. 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.