Carnival ball game using Arduino
INTRODUCTION
We have all played the evergreen carnival games, who doesn't love them?! Now you can flaunt your skills among your friends by presenting an unmatched ball game. This blog has everything you need to do!
ABOUT THIS PROJECT
In this unbeatable game we control the motor on which the pinion and rack is placed using Ultrasonic sensors. As the ball approaches the sensors it detects it and makes the motor to rotate which displaces the rack on which the cup is placed, so that the ball never hits the cup.
COMPONENTS REQUIRED:
Arduino UNO
DC Motor
Rack and pinion
Motor driver
Ultrasonic sensors
How it looks;
CODE:
#define trigPin1 2
#define echoPin1 3
#define trigPin2 5
#define echoPin2 4
const int motorPin1 = 6; // Pin 14 of L293
const int motorPin2 = 7; // Pin 10 of L293
long duration, distance, RightSensor,LeftSensor;
void setup()
{
Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
}
void loop() {
SonarSensor(trigPin1, echoPin1);
RightSensor = distance;
SonarSensor(trigPin2, echoPin2);
LeftSensor = distance;
Serial.print(" LEFT ");
Serial.print(LeftSensor);
Serial.print(" - RIGHT");
Serial.println(RightSensor);
if (RightSensor< 50 || LeftSensor < 50){
Serial.println("Ball is inside the ring");
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
delay(500);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
delay(500);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
delay(500);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
}
else{
Serial.println("no ball");
}
}
void SonarSensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(1);
digitalWrite(trigPin, HIGH);
delayMicroseconds(5);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
}
After uploading the code to Arduino the desired output is obtained.
Refernces:
https://www.arduino.cc/en/software
https://www.theengineeringprojects.com/2015/02/interfacing-multiple-ultrasonic-sensor-arduino.html
Comments
Post a Comment