Basically what I did in this project is that I modified a classic flappy bird game & made the bird fly with inputs from an ultrasonic sensor
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
flappy_eg.pdeProcessing codepde - 3.00 kB - 12/30/2019 at 07:29 |
|
|
flappy.inoArduino codeino - 1008.00 bytes - 12/30/2019 at 07:28 |
|
The reason we used the ultrasonic sensor here is to get the distance data between our hand and the sensor and use those values to adjust the height of the moving bird. The game is created in Processing and the Arduino communicates with it using the serial port. I have linked few images of the game above so take a look at them in order to get some idea about this project. SPONSOR LINK - UTSource.net.
First connect the SR-04 sensor to the Arduino board. As there is just one sensor to interface I won't add a circuit diagram for this project. The connections are as follows -
SR-04 >> Arduino Uno
Vcc >> 5V
Gnd >> Gnd
Trigger Pin >> Digital pin 11
Echo Pin >> Digital pin 10
That's it the connections are done.
Now time to upload the code to your Arduino board.
Copy the code from below.
Before uploading the code make sure to select the proper com port and baud rate as we will be using it for sending data to the game.
const int trigPin=11; //DECLARE TRIG PIN AT D11
int echoPin=10; //DECLARE ECHO PIN AT D10
int safezone=10;
void setup()
{
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
Serial.begin(9600);
}
void loop()
{
long duration,cm; //DECLARE VARIABLES TO STORE SENSOR O/P
digitalWrite(trigPin,LOW); //MAKE THE TRIG PIN LOW
delayMicroseconds(2); //WAIT FOR FEW MICROSECONDS
digitalWrite(trigPin,HIGH); //NOW SET THE TRIG PIN
delayMicroseconds(5); //WAIT FOR FEW MICROSECONDS UNTIL THE TRIG PULSE IS SENT
digitalWrite(trigPin,LOW); //MAKE THE TRIG PIN LOW AGAIN
duration=pulseIn(echoPin,HIGH); //MAKE ECHO PIN HIGH AND STORE THE BOUNCED PULSE IN VARIABLE DURATION
cm=microsecondsToCentimeters(duration);
long inch= cm/2.54;
Serial.println(cm);
}
long microsecondsToCentimeters(long microseconds) //SPEED OF SOUND IS 29 uSEC PER CM
{
return microseconds/29/2; //THE PULSE TRAVELS FROM THE SENSOR AND AGAIN COMES BACK SO WE DIVIDE IT BY 2 TO TAKE ONLY HALF OF THE TOTAL DISTANCE
}
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates
I like your idea. I want to run the similar program for my Zalo PC program, you can see here about it https://thezalopc.com/