Ultrasonic Arduino Game - Lott Davidson
Ultrasonic Arduino Game - Lott Davidson
2. The game is played with 2 or more people and you rotate turns. Anj LED indicates when
a player starts their turn by turning on. The player must find the correct distance to place
their hand away from the sensor and when they find it a light turns on Indicating they
may now shoot the ping pong ball. A servo motor is activated indicating which cup the
player must go for and each cup has different point values. The game can go for 3-10
rounds. The player at the end with the most points wins the coin.
3. The range for the player to find with the ultrasonic sensor is random between 1-20 and is
mapped to the 180 degrees of the servo motor that determines which cup you can shoot
for.
4.
5.
#include <Servo.h>
Servo myservo;
int level = 1;
long targetDist ;
int pos = 0;
bool called = false;
int timer = 0;
bool timesup = false;
long degree;
void setup() {
// put your setup code here, to run once:
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
myservo.attach(10);
digitalWrite(5, LOW);
myservo.write(0);
Serial.begin(9600);
timer = 0;
timerstuff();
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
//Serial.print(inches);
//Serial.print("in, ");
//Serial.print(cm);
//Serial.print("cm");
//Serial.println();
if (level == 1 && !called) {
delay(100);
}
void servostuff() {
called = true;
// in steps of 1 degree
myservo.write(degree)
Serial.println("Called");
}
void timerstuff() {