Rock Paper Scissors
This will show you a step by step process of how to make an interactive game of rock paper scissors
Materials
Distance sensor
Arduino Uno
Bread Board
Tower pro Servo motors x3
Buzzer (not necessary)
Popsicle sticks to use as arms for rock paper scissors
Small box that can be used to package the project
LED x3 (not necessary)
330 resistor x3 (not necessary)
How much will it cost?
Distance sensor: $3.90
Arduino Uno: $11.60
Buzzer: $7.98 - not necessary
Bread Board with wires: $9.98
Tower Pro servo motor x10: $17.99
Popsicle sticks: $6.99
Small cardboard: $13.89
LED x300: $12.99 not necessary
Resistors: $9.99 not necessary
Total : $95.32
How It Will Work
In this project the user will play rock paper scissors against the computer. The user will gesture their hand that they want to play on top of distance the sensor(rock, paper, scissors). Once they place their hand over the sensor, the program will randomly initiate one of the three servo motors (which are assigned value as either rock paper or scissors) to play its hand against the user. Additionally whenever the user places their hand over the sensor a buzzer will go off to let the user know that they have gestured their hand over the sensor. As an add on, if the computer plays rock a red LED will go off, if the computer plays paper a yellow LED will go off, and green for scissors.
Although the LED in not shown to be wired just wire an LED as you normally would. After connect the cathode leg to one of the pins on the arduino, preferably 1,2, and 0. If you choose another pin just change the integer value of led on the code to the pin you set
Coding the Project
Make sure your pins match the pins on the code otherwise the program will not work.
#include
volatile long A;
const int led1 =1; const int led2 =2; const int led3 =0; //Ignore if not using LED
float checkdistance_11_10() {
digitalWrite(11, LOW);
delayMicroseconds(2);
digitalWrite(11, HIGH);
delayMicroseconds(10);
digitalWrite(11, LOW);
float distance = pulseIn(10, HIGH) / 58.00;
delay(10);
return distance;
}
Servo servo_3;
Servo servo_6;
Servo servo_9;
void setup()
{
pinMode (led1,OUTPUT); pinMode (led2,OUTPUT); pinMode (led3,OUTPUT); //Ignore if not using LED
A = 0;
pinMode(11, OUTPUT);
pinMode(10, INPUT);
pinMode(12, OUTPUT);
servo_3.attach(3);
servo_6.attach(6);
servo_9.attach(9);
}
void loop()
{
if (checkdistance_11_10() < 20) {
A = random(0, 4);
switch (A) {
case 1:
tone(12,131);
delay(100);
noTone(12);
digitalWrite(led1,HIGH); //Ignore if not using LED
digitalWrite(led2,LOW); //Ignore if not using LED
digitalWrite(led3,LOW);//Ignore if not using LED
servo_3.write(179);
delay(1000);
servo_3.write(90);
delay(500);
break;
case 2:
tone(12,131);
delay(100);
noTone(12);
digitalWrite(led2,HIGH); //Ignore if not using LED
digitalWrite(led1,LOW); //Ignore if not using LED
digitalWrite(led3,LOW);//Ignore if not using LED
servo_6.write(179);
delay(1000);
servo_6.write(90);
delay(500);
break;
case 3:
tone(12,131);
delay(100);
noTone(12);
digitalWrite(led3, HIGH);//Ignore if not using LED
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);//Ignore if not using LED
servo_9.write(179);
delay(1000);
servo_9.write(90);
delay(500);
break;
}
}
}
Setting the Arms
Now that you have wired and coded this project, it's now time for you to add the arms (popsicle sticks) on the servo motors. Through the help of glue, attach the Popsicle sticks onto the servo motors . Once completed you should assign each servo a value (rock , paper , scissors) by attaching a piece of paper on each arm that says the value. The last thing you want to do now is set the arm to 90 degrees on the motor so that the arm is standing straight up.
Putting It All Together
The final step now is placing the breadboard into the cardboard box. This will help hide the wires and make your project look neater. After you place the bread board in the cardboard box cut 2 holes for the distance sensor and three holes enough to fit the wires for the three servo motor. Now place, the distance sensor and the servo motor wires through the holes, so they are sticking out of the box. As for the LCD display, you can just leave it outside but still attached to the Arduino. The buzzer will stay inside the box.