Interactive Flappy Bat With Distance Sensor

by Jallson S in Circuits > Arduino

2772 Views, 19 Favorites, 0 Comments

Interactive Flappy Bat With Distance Sensor

0_HERO.JPG
Interactive Flappy Bat with Arduino and 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

3_Supplies.JPG

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

TinkerCAD Simulation - Arduino UNO, Potentiometer, and LED

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

4a_Crimping.JPG
4b__Crimping.JPG
5_Wiring.JPG
6_Diagram_Uno_ProximitySensor.png

Attach and crimp male connector to sensor cables end. Then insert it in A0, GND, and 5V Arduino UNO pins as described.

Connect

7_SS_Download_mBlock540.png
8_SS_ChooseUNO_devicelibrary.png
9a_SS_live_connect.png
9b_SS_show_all_connected.png
10a_SS_live_update.png
10b_SS_Firmwareupdate.png
10c_SS_Firmwareupdate_finished.png

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

12a_SS_Choose_Spritewithmultiplecostumes.png
12b_SS_Choose_Bat_Sprite.png
12c_SS_Draw_yourself_Bat.png
13_SS_draw_Stalag.png
14_SS_DrawRectanglenFillColor_Backdrop.png

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

16a_SS_Makevariable.png
16b_SS_MakeVAriableA0.png
17_SS_CodeToTest_A0_value_with_variables.png
18_SS_MakeOtherVariables_komplit.png
19_SS_code_Devices_Arduino.png
20_SS_code_Bat.png
22_SS_code_Stalag_stalac.png
23a_SS_record_Sound.png
23b_SS_record_Sound.png
21_SS_touchingColor.png

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

24_Fullscreen_Play.png
25_Mainkan.JPG

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!