University-Level of eLearning in ASEAN Motion Detection Implementation on a Game Using Raspberry Pi Sisforma vol.3 no.2 November 2016 : 58 Motion Detection Implementation on a Game Using Raspberry Pi Gunawan Putra Gozali Unika Soegijapranata Jl.Pawiytan Luhur IV, Semarang, Indonesia Gunawanputra20@gmail.com Abstract— Along with the development of advanced gaming technology, we can play the game with so many tools or platforms such as console games, PC games, mobile games and handheld games. The disadvantage of those games is the difficulty to connect additional sensors to the PC computer. Large power requirements will also be a constraint. Besides, the size of the PC could be a weakness that makes it difficult to carry and play anytime. Raspberry is a small computer that can be added with motion detection sensors. By using the raspberry, the researchers managed to create a game "Crows Adventure" that uses motion detection sensor as the controller. Some of the sensors used in the game are UDS Sensor (Ultrasonic Sensor distance)and touch sensors which are applied to smarthphone to control the game. This allows the use of sensors in making more varied games by using raspberry devices. Keywords— Console, Raspberry, game, sensor ultrasonic. I. INTRODUCTION Along with the de velopment of t he game technology game, we can play the game with a t ool or pl atform t hat assortment, such as console game, PC games, mobile games and handheld game. Console g ame i s a s eparate device t hat is us ually as sociated with a monitor or t elevision to display. As mentioned i n ht tp://tvtropes.org/ [1] occurrence P S4 a nd X box O ne s tarted the 8th generation of t he console g ame. Moreover, t here i s a de velopment of ot her game c onsoles, s uch a s N intendo, S ega. P C games r equires a p ersonal computer or laptop to play. Mobile games are games that we pl ay on m obile phone s s uch a s Android and I -phone. Handheld g ame or c ommonly called portable g ame cons ole i s a t ype of game that is smaller in size that has a s creen and can be played anytime. There are al so games that r equire additional s ensors t o play. S uch as games that we have encountered in Gamefantasia or Timezone. There is a game that uses sensors shaped like a g un, and there are g ames l ike DDR ( Dance D ance R evolution) as the sensors a re stepped on. The w eakness of the games a bove is difficult to c onnect t he additional s ensor to t he P C c omputer. PC computer al so has a probl em be cause i t requires large power. In addition, the size of the P C be comes a w eakness t hat makes i t difficult to use in a game that can be carried and played at anytime. Raspberry i s a s mall com puter ha s advantage which is able t o be adde d b y motion d etection s ensors. A ccording to www.opensource.com [2] e ven though s mall sized Raspberry is often usedfor projects that require the ability P Cs a nd re quires a detection s ensor s uch a s robot ics. Gamescreated by using python programming language and scratch can be run on Raspberry a nd pl ayed us ing LCD m onitors or televisions. II. LITERATUR REVIEW There are a f ew games that use sensors to play., such as "Ultrasonic Sensor Game" [3], the game that uses two sensors UDS to play. After bot h pl ayers ha nds get cl oser t o the sensor, the distance will be measured and the shortest di stance t o the s ensor will win t he game.Unlike " Ultrasonic S ensor G ame", researchers us e these s ensors i nto a g ame, which the s ensor w ill be us ed to control t he game. Researchers are eager t o examine t he advantages and the di sadvantages of s ensor UDS com pared with IR s ensor t hat applied Motion Detection Implementation on a Game Using Raspberry Pi Sisforma vol.3 no.2 November 2016 : 59 in a g ame and what f actors ar e l ikely t o influence t he f eedback results obtained from each s ensor, s o t hat t he us e of a s ensor i n a game can be us ed opt imally i n accordance with needs. III. RESEARCH METHODOLOGY 3.1 Design of Prototype In this phase, the game and game consoles will be designed and manufactured using the Raspberry as t he main board. I n the processof designing the game, game engi ne is ne eded as w ell as i mage pr ocessing applications in order to get programming and graphics t hat c an s upport the c reation o f a game. Fig.3.1Circuit of Work Figure 3.1 is a circuit of work that creates a mini console. After the buttons on existing applications on the de vice i s pr essed, the value will be sent via Bluetooth and accepted by Arduino. I n A rduino, values w ill be processed a nd be used as a controller connected via U SB t hat is being pl ugged i n the Raspberry. 3.2 Prototype Design of Mini Console Raspberry Pi This prototype uses Raspberry pi 2 a s the main board. Ra spberry pi i s us ed be cause of its abi lity i n the process of com puting l ike a computer bu t only need a s mall resources and have a small-sized board. Fig 3.3Design Prototype When the design is completed, the circuit will be paired and arranged in a box. Like in Figure 3.3, there are several components that are de signed and laid into the box l ike Raspberry Pi 2, A rduino L eonardo P ro micro, HC SR-04 UDS, IR SHARP 2Y0A02, and H C - 05 B luetooth M odule. F igure 3.4 and Figure 3.5 is t he pictures of R aspberry and Arduino circuit t hat h ave been made i n order t o receive t he di stance de tection sensors. Fig 3.4Circuit of Raspberry Fig 3.5Circuit of Arduino 3.3 Gameplay game “Crows Adventure” This g ame us es 2 -dimensional i mages with pixel art theme. At the beginning of the game t here will be only t he title game and a moving ba ckground. After a player pre sses the "Shoot" button, the game begins. The g ame us es aut o runner as t he gameplay, w here t he cr ow as t he m ain character w ill fl y nons top a nd m ust a void several obstacles, such as other birds. Motion Detection Implementation on a Game Using Raspberry Pi Sisforma vol.3 no.2 November 2016 : 58-62 60 3.4 Control Game “Crows Adventure” The g ame us es t he andr oid as t he media controller that w ill be conne cted via Bluetooth b y us ing Arduino which w ill be processed and then will be sent to Raspberry. The m ovement would use t he UDS t o set the height of the character, and to move right and l eft us ing t he a pplication on A ndroid. Figure 3.7 is a sketch of the controller. Fig 3.7Sketch of the Controller IV. RESULTS AND DISCUSSION 4.1 Android-Based Controller Controller of g ame i s v ery i mportant, because t he player should be a ble to control the cha racters eas ily. This appl ication t o control t he g ame i s created by using w eb- based engine calledAppInventor. Fig 4.1Visual ProgramingKontroler Figure 4.1 i s a visual programming of t he application. At this stage, the program serves as the sender, and when the buttons that have been made arepressed a s a n e xample of " 1" that shot is pressed, then the application will send the value "s" to be captured by Arduino and will be processed in the Arduino. 4.3 Programing onthe Arduino Code 4.1 i s a program of A rduino, w here the v alue obt ained will be r ead and processed. Once t he v alue ha s b een processed, program w ill execute the command which will be conne cted to the device Raspberry as control of the game. char val; #include ; int x = 0; char ir = ‘n’; void setup() { Serial.begin(9600); Serial1.begin(9600); Keyboard.begin(); } If ( Serial1.available() ) { Val = Serial1.read(); If ( val == ‘y’ ){ ir = val; } else if ( val == ‘n’ ){ ir = val; } Keyboard.press(val); } else { Keyboar.releaseAll(); } Code 4.1Code on theArduino 4.4 Programming on the Raspberry A. Main Menu Figure 4.2 i s a view of t he g ame "Adventure C rows". The cr ow i s a cha racter that can be p layed by a pl ayer, where t he player m ust av oid eagle attack in orde r t o continue t he g ame and get t he cor n t o increase the score. Fig 4.2Game Interface Motion Detection Implementation on a Game Using Raspberry Pi Sisforma vol.3 no.2 November 2016 : 58-62 61 B. Programmingof the “Crows Adventure” Figure 4.3 i s a pro gram i n Scratch to control t he g ame “Crows Adventure". T he values received by Raspberry will be used by the crow to move vertically. Fig 4.3Programming on the Scratch 4.5 Measurements of the UDS and IR Sensor Because prototypes using multiple sensors such a s ul trasonic a nd infrared, t he researchers want to take measurements to see how w ell e ach of t he s ensors c an be us ed i n the manufacture of a game. By u sing t he A rduino t o m easure, researchers ca lculate the di stance f rom e ach sensor b y seeing and observe the results that be read on s erial monitor of s ensors plugged into the pins on the Arduino. Table 4.1 is t he r esult of t he U DS t est sensor and IR sensor to determine the sensor sensitivity i n measuring t he d istance. UDS sensors us ed in testing i s U DS se ries H SR- 04, w hile t he I R s ensor us ed i s a s eries SHARP 2Y0A02. Tabel 4.1 Distance Result Distance Sensor to Device Results that be read on UDS Results that be read on IR 15 cm 16 5 14 cm 15 6 13 cm 14 7 12 cm 13 8 11 cm 12 9 10 cm 11 10 9 cm 10 9 8 cm 9 8 7 cm 8 7 6 cm 7 6 5 cm 6 5 4 cm 5 4 3 cm 4 4 2 cm 3 4 1 cm x x Researchers al so test each s ensor t o determine t he pros a nd c ons of e ach s ensor. Some of t he tested things are the ability of a sensor to receive and capture value when the distance of the de vice is l ess t han 1cm t o sensors, what ha ppens i f the de vice i s t ilted and not a ligned w ith t he s ensor, how the results w ere ob tained when the f ield device is i n solid bl ack, how t he re sponse t ime of each sensor and what h appens w hen getting interference l ight s ensor on t he l ocation of the g ame. Table 4.2 shows t he r esults obtained at the time of testing. Tabel 4.2 Result of testing The things that are tested UDS IR Sensitivity in measuring distance v X Distance of the device is less than 1cm x X Device is tilted and not a ligned with the sensor Not Accurate Not Accurate The field device is in solid black v X Response time Slower then IR Faster Interference l ight sensor on t he l ocation of the game x V V. CONCLUSIONS The conclusion of t his r esearch ar e as follows: Motion Detection Implementation on a Game Using Raspberry Pi Sisforma vol.3 no.2 November 2016 : 58-62 62 1. Game " Crows A dventure" uses sensors i n the de vice as a con troller Raspberry. S ome of t he s ensors us ed in the g ame ar e U DS s ensors, IR sensors a nd t ouch s ensors. T he sensors can be added to the device by plugging pi n Ra spberry e xisting on the s ensor i nto t he G PIO pi n contained in the raspberry. 2. Game " Crows A dventure" is designed using Scratch. To play t he game, i t requires app lication on Android de vices m ade by s oftware AppInventor t o m ove l eft, ri ght a nd shoot. While t he di stance de tection sensor is u sed to set up a nd do wn on the characters in the game. 3. The s ensors t ested are U DS s ensor and I R s ensor. UDS sensors u se sound a s a m edium, w hile t he I R sensor us es i nfrared l ight a s a medium. A fter re searchers conduct a study t o determine t he f actors t hat influence t hese s ensors i n a g ame, researchers g et t he r esult t hat ea ch sensor ha s i ts adv antages and disadvantages. UDS s ensor i s m ore sensitive t o distance t han the I R sensor, but to the response time of IR sensors i s f aster. It i s be cause t he I R sensor uses l ight as a m edium. Other factors affecting t hese s ensors i n a game are the color of the back side of the us ed device. If t he ba ck side of the device has a solid black color, IR sensor has difficulty in measuring the distance, es pecially w ith the l ight around will also affect the d istance measurements pe rformed b y IR sensor. REFERENCES [1] T. T ropes, “The Eighth Generation of Console V ideo Games” [Online]. Available: http://tvtropes.org/pmwiki/pmwiki.php/ UsefulNotes/TheEighthGenerationOfC onsoleVideoGames. [Accessed 16-Jan- 2016 6:05PM]. [2] Opensource, ” What i s Ra spberry PI”. [Online]. Available: https://opensource.com/resources/what- raspberry-pi. [Accessed 15-Jan-2016 02:30PM]. [3] MOTIVECODEX. “ Ultrasonic S ensor Game”. [Online]. Available: https://www.youtube.com/watch?v=M TdbShnXB5k. [ Accessed 25 -Jul-2016 18:30PM]. https://www.youtube.com/channel/UC2Gsk9YPzk_3XmnqpwNSUhg� Main Menu Programmingof the “Crows Adventure”