My project is a maze game that is controlled using a joystick /APP and can move in the x-axis and the
y-axis , using two servo motors , one is placed on the side stand and the other is placed on the board wall, the idea of the game is that it can be played either by one player or by two players . The one player mode had five rounds each round displays a countdown timer for the player and his total score , if the player failed to score at all the lcd will display “GAME OVER LOSER” and an angry character made by me , if he got to score even one the lcd will display “ur score is … ” with a cute character made also by me .
in the two player mode : there are two rounds , the lcd whose turn it’s so that the score will be counted for each player correctly . Then when the time of the two rounds is up it displays whose is the winner or if neither it displays “BOTH OF You are losers ” I think this game is very engaging and entertaining as well it challenges you to be patient and try many times to score .
also I think the addition of the timer , keeps the player on his toes and makes the game more interesting and challenging . :)
The designing process for this project is divided into two parts :
- Maze board with the holder
- Assembly box that contains all the component
Maze board
First I drew a rectangle with dimensions 25X17 cm in a sketch then I made intersection lines by clicking (L) and moving the cursor until a triangle appears which indicates the middle of the line , then I made an offset(0.5) rectangle , the offset is need to draw the centre rectangles onto one line and the circle in the middle is later used for the t-slot , I make one side then mirror it into the opposing side by choosing the feature mirror in the tool box .
When I finish the sketch , I extruded the board by clicking (E) and selecting the sketch with 3mm thickness because that would be the thickness of the plywood used .
Inserting the ttp223 (touch sensor ) into the maze board
- I downloaded the ttp223 step file from grabcad , then I uploaded it into a file and from that file I chose (insert into current design which will put the component into your opened project) , because the component will be divided into random bodies make sure to select the bodies that you would want to move together and choose ( Rigid group )
- Make a joint between the ttp223 and the board and move the component to the desired place using the arrows .
Create sketch and click the upper surface of the board then short cut (p) , choosing the ttp223 surface , finish sketch and click ( e) to extrude cut this projected surface from the board .
Inner maze board sides :
The inner sides which will be used to rotate the board in x-axis has four sides
The 17cm sides :
I made a 17x4 cm rectangle then an offset (0.5) rectangle to create the two center rectangles on each side , then I created two extended rectangles and a t-slot to be inserted into the maze board
The sharp edges I removed by making a large fillet on the four corners which elevates the final prototypes look
Then the 20cm side were made in the same way the only difference is the dimension .
The outer maze board frame :
Because the outer frame has no base the two long sides have two centre rectangles on an offset and a circles 3.2 in the middle for the nut .
And the shorter sides have two extended rectangles and a t-slot in the middle on each side
You extrude all the files in the same way by short cut (e) and selecting the sketch (3mm thickness ) and ( choosing new component)
Then we click on joint (j) and join the four sides together .
The two sides
First I made a 20x15 rectangle then I choose a three point arc and made an arc from one top corner of the rectangle and another point before the end of the side , you trim the access part above , then you create another three point arc from that point to the end of the side below and then I mirrored the face and chose the mirror line the length first side of the rectangle
In order to ensure the stability of the board , I made four extended rectangles below and a t-slot .
Adding the components and mounts
The prototype has two servo motor and each servo motor has an opposing bearing to enable a smooth rotation of the board .
- I downloaded the servomotor step file from grab cad and inserted it in open design
- Make rigid group all the bodies expect for the shaft
- Make joint between the center of the servo and one outer side
- Create sketch on that side and project the servo motor rectangle onto the surface
- Make two 3.2 circle on distance 10mm from the rectangle
- Finish sketch and extrude cut
Servo mount
The servo mount is a small part we will make so that the servo will be sandwiched between two parts the mount and the outer frame .
The mount is simply made by first making a small rectangle 6x4 cm then make fillet on each corner and project the outer side onto it ( the side that has the servo projection and two nut circles)
The inner frame will stick to the servo motor by making two circles into the shaft ( 3mm screw) and projecting those circles onto the inner frame so that the screw will go through the frame and nut .
The assembly box
I wanted the box to have an angle so that the lcd will be better viewed for the user.
To have then angled shape I made a right angle triangle and I projected the Arduino ports on the side and the Arduino screw places on the bottom
I made a rectangle with open rectangles so that the sides can be inserted into it then I inserted the lcd and joystick into current design and made a joint between each component and the rectangle with the joint I adjusted the placement to my preference then I projected the components and extrude(e ) cut the projected parts
Clearance :
Because projection will give you the exact size you need to create an offset (0.1) that would make a difference later while cutting
The maze board walls and fittings were made using Laser-Cut Maze Designer website .
This website using gives you the board with the fitting and the walls separately with numbers engraved on the board and the walls to assemble it easily like a puzzle .
The website has some edits that you need to adjust to ensure a good result
1- Print mode : is either floor and wall which means it will give you fittings on the sides of the floor to put walls in it , put single sheet will have only fittings for the walls , in my case because I already have my own walls I chose single sheet
2- Number of rows & number of columns : is a personal preference and related to the level of difficultly of the maze also could relate to the overall size of the board sometimes
3- Wall height : The height of the walls from the floor of the maze. This should be tall enough so that a marble rolling through the maze won't bounce over the walls.
4- Material thickness : The thickness of the material being used to cut out the maze pieces because I’m using plywood the thickness is 3mm
5- Don’t forget to adjust the units
6- Hall width : space between walls. This should be at least as big as the diameter of a marble that would be rolling through the maze.
7- Printer configuration : needs to be adjusted based on the kind of laser cutter used in my case the laser cutter takes a sheet with width 500 X 300 mm
8- Rectangle configuration adjust it based on the size of the board that you want , I wanted the fittings inside a 25 x17 cm rectangle
9- Click generate , but note the downloaded file is SVG so you would need to convert it into DXF .
The numbers will be in colour red because it will be engraved into the board and walls not cut , I adjusted the speed to 300 and power 25
But everything else was colour black with speed 20 and power 65
My prototype was made using only laser cutting , so that means that each side needs to be turned into dxf .
- First I made a new component from Assembly
- Then I started making a sketch and clinking (p) project the component onto the sketch , It will give you an identical sketch of the final edits .
- Then after projecting (make sure projection link is not checked)
- you click finish sketch and save the sketch as dxf
- After making a dxf for all the components .
I started adjusting them into laser work , then you click download .
In the machine you choose file , and select your file then choose track-frame and adjust the sheet placement , after that you choose run and close the machine .
- The components used in the circuit are
· Two servo motors
· One touch sensor
· One joystick
· Lcd i2c
· Buzzer
The joystick and the touch sensor both are input components , the joystick is connected to analog pins and gives reading for both the x-axis / y-axis based on the joystick movement , the servo motors are action components that takes the mapped values of the joystick and moves to a certain angle based on the readings .
The touch sensor is also an input component it detect the placement of the ball on it and the lcd & buzzer are the action components , the lcd displays the player’s score and the buzzer emits sound .
Connections
1- First connect the ground of the Arduino to the common ground of the bread board
2- the vcc of the Arduino to the common vcc of the bread board
3- TTP223 has three pins one to the vcc of the breadboard , one to the GND , one i/o to digital pin 9
4- Joystick has five pins , one to the vcc of the breadboard , one to the GND, one VX which is for the x-axis to A1 , VY to A0 , SW for the pushbutton to pin 8
5- Servomotors have three pins , one to GND , one to vcc , one to pin 3 / pin 5
6- LCD I2c , has four pins , one to the GND , one to the VCC , SDA TO A4 , SLC TO A5
The Arduino is powered using a 5v volt adapter.
I chose the suitable adapter by looking into the needed voltage for each component in their data sheet and most of the used components needs only 5v or less , but for some reason using the 5v adapter wasn’t supplying enough current so I used the mobile charger with 5v output and it worked amazing
the code includes a lot of functions each function will be explained in order of it’s execution on the real simulation . the libraries used are metro library because I needed to have multiple actions execute at the same time , liquidcrystal _i2c for the lcd , varspeedservo it’s a new modified library so that I can control the speed of the servos as much as possible . below the libraries are declared variables that will be explained later on .
we named the two servomotors servo_yaxis &servo_xaxis , then in the void setup , the lcd is initialized , the attach function to declare pin 3 for yaxis servo and pin 5 for the xaxis servo
the pinmode for the joystick push (joy_button ) is input_pullup , but the input mode for the touch sensor is input only .
the function slowmove ( angle, speed) takes the first parameter as the angle and the second as the speed , we had initialized y_colevel = x_colevel = 90 & sp = 20 , this moves the servo motor to it’s start position .
Function initiate
In function initiate we display “MAZE GAME ” then move the cursor to the next line “BY NORHAN”
To scroll the written string to the left we call function lcd.scrollDisplayLeft() which only shifts by one position so in order to shift until the end of the lcd I did a for loop that counts 13 times , after it finishes , the same thing happens but to the right side by calling function lcd.scrollDisplayRight()
Function
Running_biss ()
This function is called after the initiate function , this function uses the custom character generator that turns the drawn character into a code by dividing each byte into 8 bits and declaring whether the bit is high or low based on the shape , but for this animation around 50 byte functions are executed after each other without any delay to create the illusion of movement .
Function two modes : it displays on the first line “PLAY VIA ” and on the second line “a) joystick b) app ” then it calls function game_mode() ;
Function game_mode()
First the code is stuck in this endless loop while the joystick button is not pressed , after it’s is pressed there are three options either the user moved to the right and pressed or to the left and pressed it will display his chosen mode , but if he pressed for example ate the center or up or down , the function will keep calling itself which is something called recursive function . but in case of joystick mode , variable mode will be 1 , incase app mode it will be 2 .
Function number _players displays the two options one / two then calls functions choose which has the same logic as game_mode ,
But in the one player mode it calls function player then function one_player
Function player displays a three second counter until the game starts
Function one_player displays the score of the player if first round then it’s already initialized as zero , if it’s two player with two rounds based on the round number (post ) he displays the player(1/2) score
Now the code has nothing to do but to go to the void loop ()
------
In void loop() we will be using metro functions so that we can have the lcd and the servo motors work at the same time , first condition is if mode == 1 (joystick mode) and the servo_delay .check()
Note that : servo_delay was initialized previously (pic)
Which is a function that when calls starts the counting( delay ) and after it finishes it returns one ,
When the condition is satisfied it enters the next condition which prevents the joystick from returning to it’s orginal position after moving the stick ( because the joystick has a self-centered retract ) it returns to the center position after moving which would be pointless in this game that’s why this condition only allows movement if the analog values are anywhere but the center , then it takes the reading and maps it from 10 to 1023 to an angle between -20 , 20 .
The same with the yaxis , after that function slowmove moves the board an angle +/- from the orginal position
If the mode = 2 ( app mode ) it has the same logic but here we use function Serial.parseINT that gives bytes and when stops returns \n , function constrain does the same as mapping but if the value is lower than min value it returns minimum value , if larger than max , it returns max , if in between it returns the same value
Then the next conditions are for the player/mode either num = 1 (one player ) or num = 2 ( two players )
For first condition , the number of rounds must not be zero and num = 1 function round_5 is called
The logic of function round_5 is that it checks if the senor is touched for at least half a second then it checks if the time between the last score and this score is more than 10 seconds to ensure that you went back to the start position if so it increments a score and buzzer emits a sound
at the same time I used another metro function that counts down a time and when this timer is up it displays the round number after the round_init ( round number reached = 5 ) it checks your score if higher than zero you did well and it displays your score with a cute character , if not it displays zero with an angry character
___________________
Round_2 function has the same logic with some modifications
My project is a maze game that is controlled using a joystick /APP and can move in the x-axis and the
y-axis , using two servo motors , one is placed on the side stand and the other is placed on the board wall, the idea of the game is that it can be played either by one player or by two players . The one player mode had five rounds each round displays a countdown timer for the player and his total score , if the player failed to score at all the lcd will display “GAME OVER LOSER” and an angry character made by me , if he got to score even one the lcd will display “ur score is … ” with a cute character made also by me .
in the two player mode : there are two rounds , the lcd whose turn it’s so that the score will be counted for each player correctly . Then when the time of the two rounds is up it displays whose is the winner or if neither it displays “BOTH OF You are losers ”
Some of the ideas that my instructor (Mohand) suggested and I found very useful
- To press the bearing between the sheet and a mount with the same diameter then restraining the movement by making another two mounts with a smaller diameter but bigger than 8mm for the axis
- Also to have the joystick positioned using long screws and adjusting the position using two nuts
- Also the laser maze cutter I didn’t know about it and my instructor (Menna) had previous experience using it and she explained all the details .
- This was my first time using the metro library ( instructor Ahmed Saeed) which was really lifechanging xd because now I know how to have multiple actions execute at the same time
- I helped my classmates with projecting their components and how to save as dxf and inserting components into the current file
- The most important is not to waste 3 hours of your life drawing a maze on fusion while you can generate the laser cut maze on a website
- Is to be more considerate with the components placement in a box and have it more spacious for the wires and the i2c of the lcd , just have more space than the needed
- Also if you want a component to be inserted into a mount don’t make it the exact same size of the projection but make a smaller offset by 0.2 or 0.1 makes a difference
- Colour code the components while wiring saves a lot of time later on
- Try as much as you can not to use many delays
- Make the mapping angle smaller because you only need to move the ball a little by little
I think I would work on the compatibility of the project as a real game product , I personally couldn’t find any small metal balls so I had to use the ones in accessories which isn’t the best option because of the two hole in it , it tends to stand more than to roll , also the surface isn’t as smooth as I would have liked because I first sprayed the maze board white then I didn’t like the white as much and changed it into black . another thing if I had time I would have experienced more with the angles and the speed until I find the most suitable for this game 😊
Also I would have liked to work on the sound effects using mp3 module , like for example when the mario figure is moving there could have been a cool video game sound .