Introduction: Stone Paper Scissors
We all have played 'Stone Paper Scissors' quite a lot times. This Instructable will guide you in making electronic 'Stone Paper Scissors' game that will ensure that there is no cheating and also that you have fun while learning new things .
Hope you have a great time making this project!
Step 1: Prerequisites:
For this Instructable, you need to have a basic knowledge of Arduino, LEDs and push buttons.
You can read about these from the given links:
https://www.arduino.cc/en/Guide/HomePage
https://www.arduino.cc/en/tutorial/pushbutton
https://www.arduino.cc/en/Tutorial/Blink
And you can download the Arduino software from:
Step 2: Compenets Required:
Following are the components that are required for this project:
1. Arduino Uno
2. Bread-board
3. 6 Led (2 Red, 2 Green, 2 Yellow)
4. Two push buttons
5. 7 resistors( 2.2 k ohms)
6. Jumper wires
7. One Piezo Buzzer
Step 3: Connections:
In this game, I have assumed GREEN LED to be ROCK, YELLOW LED as PAPER and GREEN LED as SCISSORS.
A buzzer is used to make sound whenever the two buttons are pressed. You can modify the code as per requirements.
Step 4: Coding Time!
Having done all the connections, we now write the code for our game which is as follows:
int button1=7;
int led1=1;
int led2=2;
int led3=3;
int buttonstate1=0;
int button2=10;
int led4=4;
int led5=5;
int led6=6;
int buttonstate2=0;
int buzzer=8;
void setup()
{ // put your setup code here, to run once:
randomSeed(analogRead(0)); //seed the random number
for(int i=1, j=4;i<4 && j<7;i++, j++) //defining the output pins
{ pinMode(i, OUTPUT);
pinMode(j, OUTPUT); }
pinMode(buzzer,OUTPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT); }
void loop()
{
int r1, r2;
buttonstate1=digitalRead(button1); //to read input
buttonstate2=digitalRead(button2);
r1=random(1,4); //generating random numbers between 1 and 3
r2=random(4,7); //generating random numbers between 4 and 6
digitalWrite(r1, HIGH); // output to the matching LED on digital pin 1-3
digitalWrite(r2, HIGH); // output to the matching LED on digital pin 1-3
if(buttonstate1==LOW && buttonstate2==LOW )
{
delay(50); digitalWrite(buzzer,LOW);
}
while(buttonstate1==HIGH && buttonstate2==HIGH)
{
digitalWrite(buzzer,HIGH); //setting buzzer to high on pressing the button
if(buttonstate1==LOW && buttonstate2==LOW)
{
break;}
buttonstate1=digitalRead(button1);
buttonstate2=digitalRead(button2);
}
digitalWrite(r1, LOW);
digitalWrite(r2, LOW); }
Attachments
Step 5: Let's Play!
You can now play 'Stone-Paper-Scissors' with your friends. You can add more push buttons to make it a multi player game.
Happy playing!