Introduction: ArDuell

A basic "1v1-shooting game" made in technology class using Arduino and Processing.
Compete against your friend in a one o one duel. After one is killed (i.e. hit by five bullets), a new harder round starts. Best out of three.


The characters are controlled in Y-direction with ultrasonic sensors.
Black player uses "Z" to shoot, white player "-".

To reset the game press "R".


Keep scrolling to see how the project was done :)

Step 1: Circuit Switching

Parts:
1x Arduino Uno
3x Breadboards
2x HC-SR04 Ultrasonic Sensors


Connect the Ultrasonic sensors as shown in the circuit switching image:

Sensor 1:
Echo -> Digital Input 2
Trig -> Digital Input 4
Gnd -> GND
Vcc -> 5V

Sensor 2:
Echo -> Digital Input 12
Trig -> Digital Input 13
Gnd -> GND
Vcc -> 5V


Later we built in the sensors in a simple box made of cardboard, and put the Arduino in an old VHS case.
All this is optional of course, but we wanted it to look nice and the sensors were easier to use when fixed to the cardboard box.

Step 2: Arduino Code

Now you will have to upload the Arduino code to your device.
The code is found in the "Arduino_ArDuell.ino" file at the bottom of the page, or here below:

const int trigPin = 13;
const int echoPin = 12;
const int echoPin2 = 2;
const int trigPin2 = 4;

void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(echoPin2, INPUT);
}

void loop() {
float duration, duration2, cm, cm2;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
cm = microsecondsToCentimeters(duration);
cm2 = microsecondsToCentimeters(duration2);

Serial.print(cm-1);
Serial.print(",");
Serial.print(cm2-1);
delay(50);
}

float microsecondsToCentimeters(float microseconds) {
return microseconds / 29 / 2; }

Step 3: Processing Code

When the Arduino code is uploaded to your device and you're getting values from the sensors (check the Serial Print), you are ready for the Processing code:

1. Create a folder called "Processing_ArDuell"
2. Download the Processing code. Either from the "Processing_ArDuell.pde" file at the bottom of this page or from https://www.dropbox.com/s/am6sml8ae9cwiyt/Processi.... Then put it in the folder you just created.

3. Download all pictures from https://www.dropbox.com/sh/6fq39x6ekqjs9r6/AABDyQ7... and put them in the same folder.







Step 4: Run the Game

Now open the .pde file with Processing and press play to run the game. Enjoy!

Note:
If the characters aren't moving you might need to do a minor change in the code. Find the following row and change the "2" to what usb port you're using:
myPort = new Serial(this, Serial.list()[2], 9600); //change the "2" to the usb port you're using


Made by Axel Holmqvist and Henrik Kockum at Polhemskolan, Lund (Sweden).
Mentor: Axel Månsson

Mail us at axel.holmqvist@hotmail.com if you have any questions.

Comments

author
MichalJ24 made it!(author)2017-07-05

Sir: can you reupload pictures ? link is not working

thanks a Lot !

author
nvmnvm made it!(author)2014-12-09

Sorry that I have problems with the part of arduino code:

Serial.print(RodKnapp);

Serial.print(",");

Serial.println(VitKnapp);

delay(50);

It was said that RodKnapp is not defined in the scope, and I guess its the same with VitKnapp.

May you please kindly offer the information about this? Is there anything missing in the code?

Anyway, its a good project, Thanks for your sharing :)

About This Instructable

1,558views

6favorites

License:

More by axelholmqvist:ArDuell
Add instructable to: