Introduction
This project was inspired by foosball table where two players on opposite side try to hit a goal using handles. In this project, I incorporated the same technique where two players on opposite direction will try to hit a goal and just like any other game whoever scores the most wins. This project is all about interaction and body movements, as the players would be constantly moving their hand in order to control the objects ( like: ball etc.) they'll also feel the interaction of their actions. For example: the game box turns green LED on when one strikes a goal, red if they miss it and yellow when the game is on and other two actions haven't been encountered, The LED's are being detected by the ultrasonic sensor. I have created one side of the game to show how it will actually work as a prototype.
Schematics/ Iteration Process
Arduino Code
const int sensePin = 13;
int inputPin = 12;
int range = 6;
int whiteLed = 3, redLed = 4, greenLed = 5;
void setup() {
int range = 6;
int whiteLed = 3, redLed = 4, greenLed = 5;
void setup() {
Serial.begin(9600);
}
void loop()
{
}
void loop()
{
float duration, cm;
pinMode(sensePin, OUTPUT);
pinMode(orangeLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(orangeLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
digitalWrite(sensePin, LOW);
delayMicroseconds(2);
digitalWrite(sensePin, HIGH);
delayMicroseconds(5);
digitalWrite(sensePin, LOW);
pinMode(inputPin, INPUT);
duration = pulseIn(inputPin, HIGH);
delayMicroseconds(2);
digitalWrite(sensePin, HIGH);
delayMicroseconds(5);
digitalWrite(sensePin, LOW);
pinMode(inputPin, INPUT);
duration = pulseIn(inputPin, HIGH);
cm = microsecondsToCentimeters(duration);
Serial.print(cm);
Serial.print("cm");
Serial.println();
Serial.print("cm");
Serial.println();
if (cm >= 0 && cm <= range)
{
digitalWrite(orangeLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
delay(500);
}
else if (cm >= range && cm <= 13)
{
digitalWrite(redLed, LOW);
digitalWrite(orangeLed, LOW);
digitalWrite(greenLed, HIGH);
delay(500);
}
else if (cm >= 13 && cm <= 18.8)
{
digitalWrite(orangeLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
delay(500);
}
else
{
digitalWrite(orangeLed, HIGH);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
}
delay(50);
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
{
digitalWrite(orangeLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
delay(500);
}
else if (cm >= range && cm <= 13)
{
digitalWrite(redLed, LOW);
digitalWrite(orangeLed, LOW);
digitalWrite(greenLed, HIGH);
delay(500);
}
else if (cm >= 13 && cm <= 18.8)
{
digitalWrite(orangeLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
delay(500);
}
else
{
digitalWrite(orangeLed, HIGH);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
}
delay(50);
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
Working Model