ksulamanidze
Published

Hit the Target Shooting Game

Simulate a shooting game using a laser gun and Arduino controlled targets.

IntermediateFull instructions provided2,422
Hit the Target Shooting Game

Things used in this project

Hardware components

Photo resistor
Photo resistor
×3
5 mm LED: Green
5 mm LED: Green
×1
9V battery (generic)
9V battery (generic)
×1
9V to Barrel Jack Connector
9V to Barrel Jack Connector
×1
Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×3
Breadboard (generic)
Breadboard (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×4
Jumper wires (generic)
Jumper wires (generic)
×30

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Code

Code

C/C++
// C++ code
#include <Servo.h>
byte phres[3]={A0,A1,A2};
 
int sensorValue = 0;
int index=0;
int score = 0;
 
Servo servo_A3;
Servo servo_A4;
Servo servo_A5;
Servo S[3]={servo_A3,servo_A4,servo_A5};
 
void setup()
{
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  servo_A3.attach(A3);
  servo_A4.attach(A4);
  servo_A5.attach(A5);
  pinMode(13, OUTPUT);
  S[0].write(0);
  S[1].write(0);
  S[2].write(0);
  Serial.begin(9600);
  randomSeed(analogRead(A3));
  index = random(0,3);
  rand_up(index);
}
 
void rand_up(int index){
  S[index].write(90);
}
 
void rand_down(int index){
  S[index].write(0);
}
 
void loop()
{
  sensorValue = analogRead(phres[index]);
  if(sensorValue > 150){
    digitalWrite(13, HIGH);
    rand_down(index);
    delay(1000);
    score = score + 1;
    Serial.print(score);
    digitalWrite(13, LOW);
    index = random(0,3);
    rand_up(index);
  }
  //Serial.print(sensorValue);  <-- for checking Photoresistor input
  delay(1000); // Wait for 1000 millisecond(s)
}

Credits

ksulamanidze

ksulamanidze

0 projects • 0 followers

Comments