Ömüşiki
Published © MIT

Simple CS:GO Bomb With Arduino Uno

A DIY replica of the CS2 bomb timer using Arduino, an I2C LCD, a 4x4 keypad, and a buzzer. Fun gaming gadget project for makers!

IntermediateShowcase (no instructions)1 hour5
Simple CS:GO Bomb With Arduino Uno

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED (generic)
LED (generic)
×1
5 mm LED: Green
5 mm LED: Green
×1
Resistor 330 ohm
Resistor 330 ohm
×2
Breadboard (generic)
Breadboard (generic)
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
4x4 Membran Keypad
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

cs2bomb_oZhHrdRRZs.PNG

Code

CS2Bomb.ino

C/C++
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>


LiquidCrystal_I2C lcd(0x27, 16, 2);


const byte ROWS = 4; 
const byte COLS = 4; 
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; 
byte colPins[COLS] = {5, 4, 3, 2}; 
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

const int buzzerPin = 10;
const int redLed = 11;
const int greenLed = 12;

String secretCode = "7355608";
String inputCode = "";
int countdown = 20;
bool bombPlanted = false;
unsigned long previousMillis = 0;
int beepInterval = 1000;

void setup() {
  lcd.init();
  lcd.backlight();
  pinMode(buzzerPin, OUTPUT);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  
  showIdleScreen();
}

void loop() {
  char key = keypad.getKey();

  if (key) {
    tone(buzzerPin, 2000, 50);
    if (!bombPlanted) {
      handlePlanting(key);
    } else {
      handleDefusing(key);
    }
  }

  if (bombPlanted) {
    updateCountdown();
  }
}

void showIdleScreen() {
  lcd.clear();
  lcd.print("ENTER CODE:");
  inputCode = "";
}

void handlePlanting(char key) {
  if (key == '#') { 
    if (inputCode == secretCode) {
      plantBomb();
    } else {
      lcd.setCursor(0, 1);
      lcd.print("WRONG CODE!");
      delay(1000);
      showIdleScreen();
    }
  } else {
    inputCode += key;
    lcd.setCursor(0, 1);
    lcd.print(inputCode);
  }
}

void plantBomb() {
  bombPlanted = true;
  countdown = 40;
  lcd.clear();
  lcd.print("BOMB PLANTED!");
  delay(1000);
}

void updateCountdown() {
  unsigned long currentMillis = millis();
  
  if (countdown > 20) beepInterval = 1000;
  else if (countdown > 10) beepInterval = 500;
  else if (countdown > 5) beepInterval = 250;
  else beepInterval = 125;

  if (currentMillis - previousMillis >= beepInterval) {
    previousMillis = currentMillis;
    
    tone(buzzerPin, 1500, 100);
    digitalWrite(redLed, HIGH);
    delay(50);
    digitalWrite(redLed, LOW);

    static unsigned long lastSec = 0;
    if (currentMillis - lastSec >= 1000) {
      lastSec = currentMillis;
      countdown--;
      lcd.setCursor(0, 0);
      lcd.print("DETONATION IN: ");
      lcd.setCursor(0, 1);
      lcd.print(countdown);
      lcd.print("s    ");
    }
  }

  if (countdown <= 0) {
    explode();
  }
}

void handleDefusing(char key) {
  if (key == '#') {
    bombPlanted = false;
    lcd.clear();
    lcd.print("BOMB DEFUSED!");
    digitalWrite(greenLed, HIGH);
    noTone(buzzerPin);
    delay(5000);
    digitalWrite(greenLed, LOW);
    showIdleScreen();
  }
}

void explode() {
  bombPlanted = false;
  lcd.clear();
  lcd.print("TERRORISTS WIN!");
  tone(buzzerPin, 100, 2000);
  for(int i=0; i<10; i++) {
    digitalWrite(redLed, HIGH);
    delay(100);
    digitalWrite(redLed, LOW);
    delay(100);
  }
  delay(3000);
  showIdleScreen();
}

Credits

Ömüşiki
3 projects • 0 followers

Comments