Project tutorial
Laser Game

Laser Game © CC BY-NC-SA

I decided to build a laser gun to compete with my friends a little. As I decided I did.

  • 4,234 views
  • 0 comments
  • 12 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

"Star Trek", "The Terminator", "Star Wars" or "The Avengers" - in each of these films technology was on a cosmic (literally) level. The heroes used laser weapons, which always fascinated me. I decided to build a laser gun, but I would not use it to kill people or aliens, but to compete with my friends a little. As I decided I did. Now I will show you how to make it.

Step 1: Desinging

I started by designing the gun in Fusion 360. I divided it into two parts, which can be screwed together with three screws. In the bottom part, I made space for PCB, holes for USB socket, reload button, laser, buzzer and cables. I made a case for Laser Shield, added some corrections and the files were ready to print.

Step 2: Electronics

The electronic part of this project is very simple. It consists of: battery charging module, microcontroller module, programming module, laser, two buttons and buzzer. At the buzzer signal input I placed pads that you do not need to solder if you do not want the buzzer, it will save some battery. It was easier with the Shield because I used ready-made modules to make it. Then I sorted all the elements on the boards and exported them as Gerber files.

Step 3: PCB Ordering

Step 4: Folding

I put solder paste on each soldering pad and put all the elements for soldering with hot-air on it. I installed the largest diameter nozzle, set the temperature to 300 degrees and the airflow to almost the smallest. Using a regular soldering iron, I corrected imperfections and soldered the rest of the elements. Finally, I cleaned the board with isopropyl alcohol and a toothbrush.

On the board from Laser Shield I started by soldering goldpin from Arduino Nano, then button, charging module, photoresistors and other small elements. I will leave soldering the led strip and display for later. I put all the components in the right places and glued the reload button and laser. In the upper part of the shield housing, I placed an element that will allow access to the button. I haven't screwed the housings together yet, because I have to program the boards first.

Step 5: Programming and Rules of the Game

The program responsible for working of the game works as follows:

You press the trigger button and the laser turns on for 100 milliseconds. You can repeat the shot 7 times and you need to press the reload button, which lasts two and a half seconds. To start a new game you must press the button on the Shield. After pressing, you have ten seconds to settle in and get ready. When the countdown ends, a random LED will light up every second -left, middle or right. If the left is displayed, for a shot at two photoresistors on the left you get 30 points, in the middle two 10 points, and in the right two 5 points. A similar situation occurs if the diode in the centre or on the left lights up. You have a minute to collect as many points as you can. They are displayed during the game and 3 seconds after its end. You can also restart the game by pressing the button during the game.

Now I could screw together two parts of the housing for the shield and the gun and solder the display and led strip to the Shield board.

Step 6: Summary

The rules of the game are clear, you can adapt them to your needs or add additional functions.

REMEMBER ABOUT YOUR SAFETY AND PEOPLE NEAR YOU! NEVER POINT IN THE EYES!

I will definitely make another version of this project, improve the gun model and significantly increase the shield. You can also put little converted sensors on your clothes and play a shooter with your friends in real life, not in front of the computer! Next project - battery powered soldering iron!

If you have any questions, write to me:

My YouTube: YouTube

My Facebook: Facebook

My Instagram: Instagram


Code

Laser Shield Arduino
#include <SPI.h>
#include <Wire.h>
#include <FastLED.h>
#include <avr/power.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_NeoPixel.h>
#define PIN 10
#define NUMPIXELS 3
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);

int ldr1;
int ldr2;
int ldr3;
int ldr4;
int ldr5;
int ldr6;
byte button;

unsigned long minutes;
unsigned long prevMinutes;

int ran;
int points;
int timeLeft = 60;
int timeLeft2 = 10;
int state = 0;
int a;

void setup() {
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(A6, INPUT);
  pinMode(A7, INPUT);
  pinMode(9, INPUT);
  pixels.begin();
  pixels.clear();
  Serial.begin(9600);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  display.clearDisplay();

}

void loop() {

  minutes = millis();

  display.setTextSize(1); // Draw 2X-scale text
  display.setTextColor(SSD1306_WHITE);
  button = digitalRead(9);

  if (state == 0)
  {
    pixels.clear();
    pixels.show();
    timeLeft = 60;
    display.setCursor(30, 16);
    display.setTextSize(1);
    display.println(F("PRESS BUTTON"));
    display.display();
  }

  if (button == LOW)
  {
    delay(50);
    pixels.clear();
    pixels.show();
    display.clearDisplay();
    display.display();
    timeLeft = 60;
    points = 0;

    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(10, 10);
    display.println(F("GET READY"));
    display.display();
    delay(3000);
    display.clearDisplay();

    for (a = 10; a > 0; a--)
    {
      display.clearDisplay();
      display.setCursor(60, 10);
      display.println(timeLeft2);
      display.display();
      timeLeft2--;
      delay(1000);
    }
    timeLeft2 = 10;
    display.setTextSize(1);
    state = 1;
  }

  if (state == 1)
  {
    game();
  }

  if (timeLeft == 0)
  {
    pixels.clear();
    pixels.show();
    display.clearDisplay();
    display.setCursor(40, 10);
    display.println(F("GAME OVER"));
    display.display();
    delay(3000);
    display.clearDisplay();
    display.setCursor(40, 10);
    display.println(F("POINTS:    "));
    display.setCursor(100, 10);
    display.println(points);
    display.display();
    delay(3000);
    display.clearDisplay();
    state = 0;
  }
  delay(20);
}

void game()
{
  if (minutes - prevMinutes >= 1000)
  {
    ran = random(1, 4);
    display.clearDisplay();
    display.setCursor(10, 0);
    display.println(F("points:"));
    display.setCursor(100, 0);
    display.println(points);
    display.setCursor(10, 20);
    display.println(F("time:"));
    display.setCursor(100, 20);
    display.println(timeLeft);
    display.display();
    timeLeft--;
    prevMinutes = minutes;
  }

  if (ran == 1)
  {
    pixels.setPixelColor(0, pixels.Color(30, 0, 0));
    pixels.show();
    reading();
    LDR12();
  }

  if (ran == 2)
  {
    pixels.setPixelColor(1, pixels.Color(30, 0, 0));
    pixels.show();
    reading();
    LDR34();
  }

  if (ran == 3)
  {
    pixels.setPixelColor(2, pixels.Color(30, 0, 0));
    pixels.show();
    reading();
    LDR56;
  }
  display.clearDisplay();
  pixels.clear();

}

void reading()
{
  ldr1 = analogRead(A0);
  ldr2 = analogRead(A1);
  ldr3 = analogRead(A2);
  ldr4 = analogRead(A3);
  ldr5 = analogRead(A6);
  ldr6 = analogRead(A7);
  delay(50);
}

void LDR12()
{
  if (ldr1 > 800)
  {
    points = points + 30;
  }

  if (ldr2 > 800)
  {
    points = points + 30;
  }

  if (ldr3 > 800)
  {
    points = points + 10;
  }
  if (ldr4 > 800)
  {
    points = points + 10;
  }

  if (ldr5 > 800)
  {
    points = points + 5;
  }

  if (ldr6 > 800)
  {
    points = points + 5;
  }
}

void LDR34()
{
  if (ldr1 > 800)
  {
    points = points + 5;
  }

  if (ldr2 > 800)
  {
    points = points + 10;
  }

  if (ldr3 > 800)
  {
    points = points + 30;
  }
  if (ldr4 > 800)
  {
    points = points + 30;
  }

  if (ldr5 > 800)
  {
    points = points + 10;
  }

  if (ldr6 > 800)
  {
    points = points + 5;
  }
}

void LDR56()
{
  if (ldr1 > 800)
  {
    points = points + 5;
  }

  if (ldr2 > 800)
  {
    points = points + 5;
  }

  if (ldr3 > 800)
  {
    points = points + 10;
  }
  if (ldr4 > 800)
  {
    points = points + 10;
  }

  if (ldr5 > 800)
  {
    points = points + 30;
  }

  if (ldr6 > 800)
  {
    points = points + 30;
  }
}

void serial()
{
  Serial.print("S1: ");
  Serial.println(ldr1);
  Serial.print("S2: ");
  Serial.println(ldr2);
  Serial.print("S3: ");
  Serial.println(ldr3);
  Serial.print("S4: ");
  Serial.println(ldr4);
  Serial.print("S5: ");
  Serial.println(ldr5);
  Serial.print("S6: ");
  Serial.println(ldr6);
  Serial.print("button: ");
  Serial.println(button);

  delay(500);
}
Laser PistolArduino
int shoot;
int reload;
int bullets = 7;
int sw1 = 5;
int sw2 = 13;
int piezo = 9;
int laser = 11;

void setup()
{
  pinMode(laser, OUTPUT);
  pinMode(piezo, OUTPUT);
  pinMode(sw1, INPUT);
  pinMode(sw2, INPUT);
  Serial.begin(9600);
}

void loop()
{
  shoot = digitalRead(sw1);
  reload = digitalRead(sw2);
  Serial.print("shoot: ");
  Serial.println(shoot);
  Serial.print("reload: ");
  Serial.println(reload);
  if (bullets > 0)
  {
    if (shoot == LOW)
    {
      tone(piezo, 5000);
      delay(100);
      digitalWrite(laser, HIGH);
      delay(50);
      digitalWrite(laser, LOW);
      bullets--;
      delay(100);
    }
  }
  if (bullets <= 0);
  {
    if (shoot == LOW)
    {
      tone(piezo, 2500, 30);
      delay(100);
      tone(piezo, 450, 30);
    }
  }


  if (reload == LOW)
  {
    delay(2000);
    bullets = 7;
    tone(piezo, 100, 100);
    delay(100);
    tone(piezo, 150, 100);
    delay(100);
    tone(piezo, 190, 100);
    delay(100);
    tone(piezo, 250, 100);
  }
}

Custom parts and enclosures

lpistolbot_DENDE7TfC8.stl
lpistolup_H4eamKnhDS.stl
shield_b_b_GzSdCwUOtL.stl
shield_b_t_bO67lh0ifA.stl
shield_body_pPhTxypj7L.stl
shield_top_YMoBdiIMmF.stl

Schematics

Laser Shield
laser_shield_mnx4pp3zC1.brd
Laser Pistol
laser_pistol_JSgLinEm0L.sch

Comments

Similar projects you might like

Laser Shooting Game (Star Wars)

by Barqunics

  • 11,806 views
  • 9 comments
  • 33 respects

Arduino Pocket Game Console + A-Maze - Maze Game

Project tutorial by Alojz Jakob

  • 19,906 views
  • 9 comments
  • 48 respects

Space Trash Game using Arduino and OLED Display

Project tutorial by Pi BOTS MakerHub

  • 8,376 views
  • 3 comments
  • 15 respects

T-Rex-duino - Arduino Clone of Chrome T-Rex Game

Project tutorial by Alexander Blk

  • 11,842 views
  • 14 comments
  • 74 respects

Arduino Gyroscope Game with MPU-6050

Project tutorial by Mirko Pavleski

  • 7,105 views
  • 5 comments
  • 20 respects

DIY Arduino 1D Pong Game with WS2812 LED Strip

Project tutorial by Mirko Pavleski

  • 5,920 views
  • 10 comments
  • 17 respects
Add projectSign up / Login