Rock-paper-scissors Robot

by Rosamking in Circuits > Arduino

4105 Views, 16 Favorites, 0 Comments

Rock-paper-scissors Robot

作品照片1.jpg

Hello, Everyone. This is a series of courses, I will share how to use cartons and arduino to make something interesting.Today, I'll show you how to make a Rock-paper-scissors robot.

You Need to Prepare These Materials

fc4a471f1587e8b6928f4b968bc8ffe.png

Circuit Diagram

13cc6e2a1771a7a1fc2738fb40a96a9.png

Assembly

612ab32ce9fd1d7430fa4d63968e80e.png
b87737f334cc31e1b432aab7bb8da9b.png
cbba797907424a2bf38e9ceb93430b7.png
1d6d27f069badf2f765033f5a14cead.png
96a73c29f3e4257cdcf46eef167e085.png
d0d2f47ebf88e6bf805a89f5477a8f5.png
277aab7c46f3d1d4f20d6fc8247106f.png
d4dcb9b2535796d11a48870638f15dc.png

Code

#include <Servo.h>

volatile long A;

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()

{

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);

servo_3.write(179);

delay(1000);

servo_3.write(90);

delay(500);

break;

case 2:

tone(12,131);

delay(100);

noTone(12);

servo_6.write(179);

delay(1000);

servo_6.write(90);

delay(500);

break;

case 3:

tone(12,131);

delay(100);

noTone(12);

servo_9.write(179);

delay(1000);

servo_9.write(90);

delay(500);

break;

}

}

}

GameRules

Rock-paper-scissors robot

The three servos represent the Rock paper and scissors respectively. When the hand is close to the SR04 module and the distance is less than 20cm, the buzzer makes a sound. According to the random function of the program, it randomly controls a servo changing angle to complete the game