Interactive Flappy Bat With Distance Sensor
by Jallson S in Circuits > Arduino
2915 Views, 20 Favorites, 0 Comments
Interactive Flappy Bat With Distance Sensor
In this project, we will make another version of Flappy Bird that was quite popular some time ago. So the goal is to avoid the Bat from falling or hitting an obstacle (cave stalactite and stalagmite). To control the movement of the bat's height, we move our palms on the distance sensor device mounted on the Arduino. This project will be programmed with the mBlock5 (based on Scratch3), this program can use hardware extensions such as Arduino, Micro:bit, and directly interact with characters (Sprites).
Supplies
1x Arduino UNO R3
1x Sharp Infrared Proximity Distance Sensor
1x Playdough or bluetack (optional)
3x Dupont 2.54 - male jumper pin / wire connector (optional)
Tool:
Crimping tool (optional)
Software:
TinkerCAD website: tinkercad.com/dashboard (for simulation purpose)
mBlock V5.4.0 (download from mblock.cc/download)
Simulate
Before making this project; to get the idea how it works, I want to simulate a simple version of this project—from analog input (potentiometer) to pwm output (LED)— We can use TinkerCAD software, with circuit design and block code capabilities. For more details, check the following video.
Prepare
Attach and crimp male connector to sensor cables end. Then insert it in A0, GND, and 5V Arduino UNO pins as described.
Connect
This step connects our Arduino to the mBlock software so it can interact directly.
Download and install mBlock V5.4.0.
Then, connect Arduino Uno with Proximity Sensor to your laptop/computer.
On Devices tab click +add, and click OK.
Choose LIVE, click Connect and tick “Show all connectable devices”, choose highlighted device (eg. COM…in Windows, or dev/tty.usb.… in Mac)
After that, choose Update, Update Firmware then click OK, and try to connect once again.
After “Connected”, you’re ready to the next step.
Draw
From Sprite tab delete Panda, then click + (add), choose sprite with multiple costumes (for animation effect) or you can to draw your Sprite with clicking Paint icon.
You also need to draw Stalagmite and Stalactite with multiple costumes, check screenshots above, then you have to edit/draw for cave Backdrop.
Code
Here we will start by knowing the value of the Proximity/Distance Sensor installed at A0, then we will create a variable A0
Then create a series of block code as seen in screenshots above.
And run it by clicking on the flag icon. So on the left screen the value A0 will appear when we move our hand in front of the sensor (in my case the value range is 240 - 600), so we will use this as input where the output is the Y coordinate which value is 180 to negative 180 as shown in grid image above.
Then, create other variables: y, Score, dan Live.
Now it's time to make the Code for the Arduino Device. Follow each block code carefully. Here the calculation refers to my A0 input range which is 240 - 600 to be used as position y = ((A0-440)*-1). You can adjust the number depends on the input range you got.
Then follow block codes for Bat and Stalag:
In these two block codes, you can add a sound effect of bumping (ough) in the Bat block as well as add music in the Stalag block.
To complete the “touching color” in the Bat block code, you need to choose the Stalag color by directing it to the sprite.
Play
Now, time to test! Standby your hand in front of the sensor.
Click on the fullscreen icon and on the flag to get started. Move your hand to control.
Yay, It works!
You can add to the excitement by adding game levels, changing speed, and adding obstacles. Be creative!