You are on page 1of 22

Effat University College of Engineering Electrical and Computer Engineering Department

Crazy Ball
ECE 341, ECE 391 &ECE 440

Team Supervisor

Prof. Mohammed Shehatha

Team members
Juahir Albakri Haneen Bawayan Maha Nour Maryam Tora

Spring 2011

Table of Contents
1. Introduction .................................................................................................................................... 1 2. Design Overview .......................................................................................................................... 3 2.1. Block Diagram .................................................................................................................. 3 2.2. Block Diagram description ........................................................................................... 4 2.3. Conveyor ............................................................................................................................. 4 2.4. Truck Car ............................................................................................................................ 6 2.5. Elevator & Catapult ......................................................................................................... 8 2.6. LCD ................................................................................................................................... 10 3. Hardware and software design .............................................................................................. 11 3.1. Hardware .......................................................................................................................... 11 3.2. Software using C language ........................................................................................ 11 4. Test Verification ........................................................................................................................ 15 4.1. Component Test.......................................................................................... 15 4.1.1. Infrared transmitter receiver sensor ........................................... 15 4.1.2. Micro touch Sensors .................................................................. 15 4.2. System test ....................................................................................................................... 17 4.2.1. IR sensor at the end of the roller coaster .......................................... 17 4.2.2. IR sensor before the care ........................................................................ 17 4.2.3. Micro touch at the end of the car track .............................................. 17 4.2.4. Micro touch at the beginning of the car track ................................. 17 4.3. Challenges during the test .......................................................................................... 18 4.3.1. The elevator challenge ............................................................................ 18 4.3.2. Car challenge ............................................................................................. 18 5. Conclusion ................................................................................................................................... 19

ii

1. Introduction
Our project for the spring of 2011 is the result of combining three different major courses revolving around multivariable control and integrating a microcontroller with different sensor circuits. Numerous reasons formed the foundation of our project, starting with fulfilling a course requirement, learning to work in a team, thinking outside the box and becoming handy with different tools! In addition to that, learning how to build and manage a project of a large scale, answering questions regarding budget management and demo construction materials. Moving on to designing the needed circuits, picking the best components and testing every one of them. Finally, assembling the separated parts together. The second reason fuelling our project - from the components integrated within it to the devices chosen for it - is that they all pool in to provide the perfect groundwork for testing the apparatuses we will be implementing in our Senior Capstone Project Automated Shipment Sorter through our final year. Giving us a home run advantage in the form of an early insight to some of the problems we need to avoid, replace or improve upon. The Crazy Ball project was an interesting experience this semester to say the least! due to some new factors appearing; the biggest of all was our freedom in picking and designing the system from scratch!! That independence in choice inspired our team to produce our best effort yet, and drove us to go that extra mile. Our project was contaminated with many a problem, but that was reassuring since our team supervisor once professed if your project is running smoothly then probably something isnt right. In the light of that statement, here are some of the obstacles our group faced: finding a replacement to the conveyer belt, designing the boxes placed on top of it and connecting them together, integrating the NXT microcontroller (used in the elevator and the catapult) with the Atmel ATMEGA 168 microcontroller (used in controlling the whole system). Some other hindrances had appeared but that 1

were in the form of a challenge rather a full-blown problem, of those we highlight the difficulty of moving the project, the accuracy needed to test it caused a strain on us until it was achieved and some of the needed components were unavailable in the market and we had to import them from the United States of America. This section will be discussed thoroughly in the body of the report. All in all, it was our most sophisticated project by far, so naturally the information and feedback obtained from it during the two months it took us to finish it were equally rewording.

2. Design Overview
2.1. Block Diagram

2.2. Block Diagram description


Crazy Ball is a game about automated ball control. In this game the ball has a closed loop path to move through different stages such as, conveyor, rollercoaster, elevator, car and catapult. In addition, sensors were used to detect the ball location therefore controlling the next action.

2.3. Conveyor
The conveyor stage is located after the rollercoaster. It consists of rubber belt, two wheels and a DC motor attached to one of the wheels. The main function for the conveyor in this game is to carries the ball and moves it to the next stage only when the ball reaches the conveyor otherwise its turned off. An infrared senor was used to sense the ball location. Whenever an object was detected, the sensor sends directly to the microcontroller to turn on the DC motor to let the conveyor move and carry the ball to the next stage.

The figure above shows the IR Circuit. LD271 was chosen as IR emitter with 2.5V to connect it in series to a resistor and 5V power supply. The resistor was chosen to be 180 based on the following calculations.
!!!.! !" !

R=

= 166 . But, 180 was found in the market, which is excepted value.

The phototransistor was connected to pin 15 (PB1) in the microcontroller. When there is no object the phototransistor receive infrared signal to connect the microcontroller pin to the ground. However, when an object passes between the transmitter and emitter, the it prevents the IR signal to reach the phototransistor and the MCU is no more connected to the ground but the MCU has 5V because it pulled up high. Once this happened the microcontroller send 5V to pin 27 (PC4) to turn on the motor circuit for few seconds by activating the NMOS and connecting its source to the ground to complete the motor circuit.

2.4. Truck Car


The truck car is the most important stage in this game because there are a lot to control in this step. In addition, its trail takes almost the most area of this game so, its the center of attention. The car is located after the conveyor and before the elevator. Its main function is to transport the ball from the conveyor area to locate the ball inside the elevator. Then goes back to its original place and wait for the ball again. Three sensors were used in the truck car stage to complete the requirements. The first sensor is IR sensor, which is located above the truck. Whenever the ball falls in the back of the truck, this sensor tells to the microcontroller to move the car backward. The second sensor is micro touch sensor, which located before the elevator stage. The car presses this micro touch sensor while its moving backward. When it pressed, the car stop moving backward and left up the truck back to locate the ball inside the elevator. After few seconds, the trucks back goes down again to its normal place and the elevator moves up. Then finally the car moves forward to reach its original place that it started from. The third and the last sensor in this phase is also a micro touch sensor, but located at the beginning of the car trail. This sensor is responsible to stop moving the car backward when it reaches its starting point to wait for the next cycle.

The figure above shows all the necessary circuits for this stage. First of all, the IR circuit, the same as the one in the conveyor phase. Its function is to detect the location of the ball. Detecting the ball means there is an object between IR transmitter and receiver so the phototransistor is not active and the microcontroller has 5V since its pulled up high. Once this is the case the microcontroller sends 5V to pin 24 (PC1) to activate the NMOS. Consequently, the relay that takes 6 V in its coil switch to connect 4.5V to the wire that is responsible to move the truck backward. This wire was removed from the cars remote control and connected to this circuit. The car keeps moving backward until the micro touch sensor which is connected to pin 18 is pressed then its no more connected to the ground but it has 5V because its pulled up high. When this happened the microcontroller stops sending 5V to pin 24 (PC1) to open the relay switch and the 4.5 V is no more connected to the backward wire to stop the car moving backward. In the same moment the microcontroller sends 5 V for only 2 seconds to pin 25 (PC2) to move the cars back up and keeps it up for 4 seconds to give enough time for the ball to fall inside the elevator. Then 5V was sent to pin 26 for the same amount of time when its was lifted up, which is 2 seconds, to moves it back to its original place. After that, the elevator and the catapult take a place, which is explained bellow. After the elevator and catapult stage is done, the microcontroller sends 5V to pin 23 (PC0) to move the car forward until pin 17 (PB3) is no more connected to the ground. In other word, the car will keep moving forward until the micro touch sensor that located at the beginning of the trail is pashed.

2.5. Elevator & Catapult


The elevator is located after the car truck and before the catapult. Its core function is to move the ball above the ground one meter and eleven centimeters to let the ball pass the rollercoaster successfully by having high speed when it falls. However, the catapult is located after the elevator to receive the ball and locate it exactly on rollercoasters track. This stage contains two servomotors, one to control the elevator and another one for the catapult. In addition to NXT Intelligent Brick that use 32-bit ARM7 microprocessor to control the two servomotors and to connect it to the ATmega 168 microcontroller. NXT Intelligent Brick was chosen since no enough pins in ATmega 168 microcontroller. Also, it is much more easier to program especially for accurate number of rotations. NXT Intelligent Brick was programmed using NXT-G v1.0 programming software that comes bundled with the NXT. It is drag-and-drop software comes with building instructions in it to simplify programming process. The figure bellow shows the program done to control both of the elevator and catapult.

This program run when NXT push button is pushed. Then and only then the motor A, that responsible for the elevator, rotates for 24.2 rotations to lift the elevator upward. After that, the elevator waits for two seconds to give enough chance for the ball to fall inside the catapult. Next, the same motor moves with the same number of rotations but in reverse direction. By this, the elevator mission is done and the catapult mission starts. After one second from the elevator stops the motor B, that responsible for the

catapult, rotate for 0.25 rotation and waits for 1 second and them moves in the revese dirction with also 0.25 rotation to go back to its original place. The exact number of rotations for the elevator was calculated by selecting 20 rotations as a random number to observe where the elevator will reach. It was noticed that it reached to 92 cm above the ground, but still 19.5 cm needed to reach the target point. 20 = 0.217 !"#$#%"&/ !" 92 0.217 19.5 = 4.2 !"#$#%"&' Final number of rotations for motor A = 4.2 + 20 = 24.2 rotations. Since the target in this game is to make it all automated. Therefore, NXT push button is not accepted to control the elevator and the catapult, but instead NXT push button the micro touch sensor near the elevator was required to control when the program should be run. For that reason the following circuit was created.

In this circuit when the micro touch sensor that is connected to pin 18 is no more connected to the ground and after few seconds to ensure the ball is inside the elevator, the microcontroller sends 5V to pic 28 (PC5) to activate the NMOS and connect the two NXT wires together as if someone is pushing NXT push button but actually no NXT push button. That cause to run the program inside NXT Intelligent Brick to turn on the elevator and catapult in their required time.

2.6. LCD
On the LCD screen the name of the game and the number of cycles are displayed. The numbers of cycles are counted using the same IR senor that used for the conveyor to move, which is connected to pin 15 (PB1) . The figure bellow shows the circuits to count the number of cycles.

Whenever an object pass between the IR emitter and phototransistor the signal cant reach to activate the transistor and its no more connected to the ground. Then the number of cycles, which has an initial value zero, increased by one in each time an object located between the transmitter and receiver.

10

3. Hardware and software design


3.1. Hardware
by using microcontroller ATmega 168 all the circuits for the entirely stages was combined together as follow :

Then the microcontroller was programmed using C language to control and integrate all the stages together.

3.2. Software using C language

#define F_CPU14745600 #include <stdio.h> #include <math.h> #include <avr/io.h> #include <avr/interrupt.h> #include <avr/pgmspace.h> #include <inttypes.h> #include "../libnerdkits/delay.h" #include "../libnerdkits/lcd.h" 11

#include "../libnerdkits/uart.h" int main() { // start up the LCD lcd_init(); lcd_home(); // definde port C as output DDRC |=(1<<PC0); // PC0 out Car forward DDRC |=(1<<PC1); // PC1 out Car backward DDRC |=(1<<PC2); // PC2 out Car up DDRC |=(1<<PC3); // PC3 out Car down DDRC |=(1<<PC4); // PC4 out Conveyor motor DDRC |=(1<<PC5); // PC5 out Mindstorm (elevator + catapult) // define port B as input DDRB &=~(1<<PB1); // PB1 input IR conveyor DDRB &=~(1<<PB2); // PB2 input IR car DDRB &=~(1<<PB3); // PB3 input start push button DDRB &=~(1<<PB4); // PB4 input End push button // create variables unsigned char port_B; unsigned char B_1; unsigned char B_2; unsigned char B_3; unsigned char B_4; unsigned char count=0x00; unsigned char B_1_old=0x00; // pull up high port B PORTB |= (1<<PB1); // pull up high IR conveyor PORTB |= (1<<PB2); // pull up high IR car PORTB |= (1<<PB3); // pull up high start push button PORTB |= (1<<PB4); // pull up high End push button while(1) { //============ Conveyor =============== port_B= PINB; B_1 = port_B & 0x02; // to return 0000 00x0 if (B_1==0x02) // before conveyor IR high { delay_ms(2000); PORTC |=(1<<PC4); // turn on conveyor's motor delay_ms(4000); PORTC &=~(1<<PC4); // turn off conveyor's motor 12

if( B_1_old==0x00) // before conveyor IR { count=count+1; } // count number of cycles. B_1_old=B_1; } B_1_old=B_1; if (B_1==0x00) // before conveyor IR off { PORTC &=~(1<<PC4);} // ========== Display on LCD ============ lcd_home(); lcd_write_string(PSTR(" lcd_write_string(PSTR(" CraZy BaLl")); "));

lcd_line_three(); lcd_write_string(PSTR("This is Cycle: ")); lcd_write_int16( count ); lcd_write_string(PSTR(" ")); //================ Car and Mindstorm nxt ================= port_B= PINB; B_2 = port_B & 0x04; // to return 0000 0x00 if (B_2==0x04) // before Car IR high { delay_ms(2000); PORTC |=(1<<PC1); // car moves backward } port_B= PINB; B_4 = port_B & 0x10; // to return 000x 0000 if (B_4==0x10) // micro touch sensor before elevator { PORTC &=~(1<<PC1); // car stop moving backward PORTC |=(1<<PC2); // car lift up delay_ms(2000); PORTC &=~(1<<PC2); // car stop lift up delay_ms(4000); PORTC |=(1<<PC3); //car moves down delay_ms(2000); PORTC &=~(1<<PC3); // car stop moving down delay_ms(4000); PORTC |=(1<<PC5); // nxt is pushed PORTC &=~(1<<PC5);// nxt is not pushed any more 13

PORTC |=(1<<PC0); // moves forward } port_B= PINB; B_3 = port_B & 0x08; // to return 0000 x000 if (B_3==0x08) // micro touch sensor at the begining { PORTC &=~(1<<PC0); } // stop moving forward } return 1; // close while }

14

4. Test Verification 4.1.


Component Test

4.1.1. Infrared transmitter receiver sensor

Object
Infrared Transmitter

No Object

Phototransistor

Infrared Transmitter

Phototransistor

There are two conditions to test the IR sensor whether the one where placed at the end of the role coaster or the one where place before the car both are the same. And their conditions as the following: If there is an object pass through the sensor the led light will be on If there is no object pass through the sensor the led light will be off

4.1.2. Micro touch Sensors These two sensors at the end and at the beginning of the car track do many tasks and they are as the following: When we hits the sensor at the end of car track a. The red wire of the car, which is responsible for the moving the car backward, will be pulled low (led light of the MCU output pin is off) as result of that the car, will stop moving backward. b. The white wire of the car which is responsible to left up the back of the car will be pulled high (led light of the MCU output pin is on) so the back of the car will left up that let the ball goes to the elevator.

15

c. The green wire of the car which is responsible to left down the back of the car will be pulled high (led light of the MCU output pin is on) so the back of the car will left down. d. The blue wire of the car, which is responsible to move the car forward, will be pulled high (led light of the MCU output pin is on) so the car moves forward. e. The elevator goes up and rotate 24,2 rotation f. The catapult rotates a quarter rotation to reach the ball to the beginning of the role coaster. When we hits the sensor at the beginning of car track a. The blue wire of the car, which is responsible to move the car forward, will be pulled low (led light of the MCU output pin is off) so the car stop moving. After test the connection of each electronic components of the microcontroller circuit, we are going to put led light in each output pins of MCU and then we can test the circuits of the system such as, IR circuit, and Micro touch circuit. of course we cant forget that C language is one of the major thing to control the time for each step or stage of our closed loop path game.

16

4.2. System test


To test crazy ball project, the ball has to pass through many sensors in different places inside the closed loop and they are as the following: 1. IR sensor at the end of the role coaster 2. IR sensor before the care 3. Micro touch at the end of the car track 4. Micro touch at the beginning of the car track

4.2.1. IR sensor at the end of the roller coaster When the ball passes through the IR sensor, it senses the ball and send signal to the microcontroller to rotate the DC motor of the conveyor belt.

4.2.2. IR sensor before the care When the ball passes through this sensor, it senses the ball and send signal to the microcontroller to let the car move backward.

4.2.3. Micro touch at the end of the car track When the car hits the sensor, it sends a signal to MCU to do many tasks 1. Left up the back of the car 2. Left down the back of the car after specific time 3. The car move forward 4. The elevator goes up 5. The catapult arrive the ball to the beginning of the role coaster.

4.2.4. Micro touch at the beginning of the car track When the car reach the beginning of the track it will hits the sensor and the car will stop.

17

4.3. Challenges during the test


4.3.1. The elevator challenge First, we used ultra sonic sensor to stop the elevator when it comes close to 10 cm but unfortunately, this idea didnt work because when we covered the sensor by our hands, the motor rotate and still running but as soon as we take off the cover it will stop thats mean it works in opposite way that we want to desire. Second, we used timer and we tried to specify time for the elevator to work and stop when it reachs the top but also this idea didnt work because the speed of the motor varies according to the load and the direction of the motor. Third, we tried to select a random number of rotation and check where the elevator will stop e.g. we selected 20 rotation and this reached the elevator to 92 cm, so we measured that each cm needs 0.217 rotation, after calculation regarding to our required distance we used 24,4 rotation for the motor. At the end, this idea worked perfectly and as we need.

4.3.2. Car challenge For the car circuit we connected the relay and it doesnt work because the relay needs 6 V and the microcontroller cant supply that voltage. So we tried to use transistor but unfortunately this idea didnt work because the whole current moved from the MCU and LCD To the relay. Finally, we decided to use MOSFT to buffer the current and we had to use two-power supply for the relay. As result, the idea worked perfectly.

18

5. Conclusion
1.1. Results
The final result of the project was very pleasing and pleasant, since the objective of the project was met. The final test in which the whole route worked perfectly and was taped using a video camera. The test started by placing the ball on the top of the rollercoaster path leading it to drop into the conveyor escalator which is triggered by an IR sensor which sensed the ball when it reached it, the conveyor then dropped the ball into a sliding path that lowered the ball into the truck that is activated by an IR sensor as well, the truck drove the ball and slid it into a bridge which lead the ball into the elevator, the elevator is lifted up when the truck hit a micro touch sensor. Finally, the ball is dropped into the catapult then launched onto the rollercoaster track to repeat the cycle once again.

1.2. Comments
After all the hard work, sleepless nights and the continuous efforts of four young engineers placed into executing this project, it was noticed that there is a place for improvement even though that this project has amazing and astonished many eyes including the eyes of journalists which lead them to publish an article in AlMadina national newspaper titled Four young ladies studying at Effat university developed a game that mimics production lines in factories on the 26th of May 2011. There are three main areas that need some enhancements. First of all, there is a total of three power supplies in this project; one is connected to the sensors to power the IR transmitter/receiver, one to supply the microcontroller, and the last one to source the mindstorms NXT controller. It was noticed that the power supplies have to be switched on in an ordered sequence; first the sensor circuit, followed by the microcontroller circuit, and finally the NXT controller is switched on. Second of all, the project is very precise fragile in a way that if any part were moved 1cm there would be an error and the project wouldnt work properly as desired. We

19

need to improve its robustness by setting it on a stable platform, this way the parts will be fixed permanently in their exact and specific location. Third of all, the IR sensors would, sometimes, not be able to detect the presence of the ball when it passes through because of the balls fast speed. To improve the detection of the ball and to solve that problem, we suggest placing extra sensors, if one didnt work then hopefully the next one would.

20

You might also like