2. Sensor project Page 2
1-About the Game ................................( page :3 )
2-The Accelemeter sensor ..................... (page : 4)
3-Interface between Arduino,Unity engine.. ......... (page : 5)
4-System of the Game............................ (page:6)
5-The Code Part.,,................................ (page:7-9)
6-Documentation(codes,datasheet).…page (9-14)
Students names :
Group 5
الرمام عبدالهادى عبدالمقصود خالد
عبدهللا األنور السيد دمحم عمرو
الزناتى احمد عبدالعال احمد شيماء
عبدالعزيز عبدالعزيز شفيق ياسمين
محمو سليمان عبدالمنعم مجدىد
3. Sensor project Page 3
The project is a 3D Game designed by Unity 3D engine & programmed
by c# language.
Idea of the game: We have a Plate object in our game and the
balls fall on the plate & by rotation the plate by Accelerometer sensor
The objects in the game: we have only 3 objects in the game
1- The camera object :(it’s the default object in unity and his position in the
3D space depend the screen of the game
2- The Plate object : the plate which we change his rotation by
Accelerometer sensor or Mouse and the balls fall on it
3- Balls : every 5Sec a ball will fall in the plate
4. Sensor project Page 4
Basic Understanding Of Accelerometers
(This part from a link in the Documentation )
Basic Understanding Of Accelerometers
Accelerometers measure acceleration, often caused by motion. But when they are standing
still, the only acceleration the accelerometer senses is due to gravity pulling down on it.
Imagine a box that has little springs sticking straight out from the sides of the box, and that
the accelerometer measures how hard gravity is stretching out those springs. The springs on
the side are all bending the same amount, the spring on the bottom is all stretched out, and the
one at the top is not stretched at all (because the spring is pull back into itself), so the
accelerometer sees it as feeling no gravity, or 0g (gravity). If you rotate the box 90º and follow
the spring on the top. It is now on the side and is hanging down some and the sensor sees it now
feels .5g. Rotate 90º again, and it is at the bottom, stretched out, and it feels 1g. Rotate again
90º and we are at the side again, with it feeling .5g, and 90º rotation again, we are back at the
top and it feels 0g. So we made a full rotation and the accelerometer saw this: 0g-> .5g -> 1g ->
.5g -> 0g.
5. Sensor project Page 5
Interface Arduino with unity :the arduino (which
connected to the Accelerometer sensor ) send the rotation angels to
serial port COM3 And by unity script (c#) we can read the
information which come from serial
The code in unity by C# to receive angels date to
unity(class plate)
Serial angels
6. Sensor project Page 6
Every 5 sec a ball fall into the plate and by rotation in the plate we will
try save all balls ....if 3 balls go out from the plate you will lose...
First scene in the Game
When the Game end you will
see your score and Text about
how good you are in the
Game like(really noob, not
bad,good…etc)
Then you can press the
mouse button to play
again
7. Sensor project Page 7
The Code Part: we have 2 parts in our project:
1 - The arudino code part which read the data from Accelerometer
sensor and send it to Script in unity
The Main part in the Arduino Code :
All the code in Documentation
Map to the reading (xAng , yAng , ZAng) [-90,90]
X,y,z, convert the reading to DEG
The values of angles in x,y,z in range [ 0,360]
Then we convert it to [ -180 , 180 ]to be like unity engine system
8. Sensor project Page 8
2- The Game Code which is programmed by C# in unity Engine
- The Game has 7 scripts ( classes )
- All class which we made inheritance from the main class
(MonoBehaviour) which designed by unity
Main Class :
MonoBehaviour
Text
ball
Level
Manger
Flag
Camera
Rotation
Plate
Score
To transform
between
scenes
Texts in the game
Score and health
variable
The main code to
take rotation
angels and move
by mouse
Make new
Balls
If the plate rotated
to up , the camera
will move up too Check if ball fall out
from plate
9. Sensor project Page 9
The Classes in objects :
Ball Object : has only one Script(Ball,)
Camera object :has 4 scripts (camera_rotation,Score,Text,flag)
Plate object :has only one Script :Plate
The Main class to transform between Scenes:Levelmanger
(we put it in empty object)
11. Sensor project Page 11
⦿ Arduino code:
}
USING THE SENSOR TURORIAL :
http://bildr.org/2011/04/sensing-orientation-with-the-
adxl335-arduino/
12. Sensor project Page 12
Plate Script
The main code to
take rotation
angels and move
by mouse
Camera_rotation
If the plate rotated
to up , the camera
will move up too