PinBall Game (Atmega 32)

Pinball Game

Introduction:

Our aim in this project is designing a pinball machine that can be played in automatic mode and manual mode. In manual mode player can control the flippers with buttons, in automatic mode game play itself automatically. Setup has consist of ldr, laser, ultrasonic sensor, solenoid motors, 7-segment display, buzzer and led . Next parts, we will explain working principles of each parts. We have also used delay library in our code.

LDR and Laser

A photocell or photo resistor is a light dependent resistor. Ldr is a photoresistor to detect light. When light increases, resistance of Ldr decrease to 1 Kohm while resistance increase to 1 Mohm when the light decreases. We also used laser that just work with 5 V to increase light falls on the sensor. We received voltage data of Ldr using ADC converter of ATMEGA32. Overall, it is work principle, when light on sensor is high, that means there is no score, Ldr had high voltage because of low resistance. Otherwise, when there is score, ball prevents light passes to Ldr and resistance of Ldr became very high and voltage decrease because of too much decreasing in current. We also used UART to see changes of voltage and decides changes values of score, but it is not in our main code.

You can see Ldr, laser and their connection.

Secondly, I want to talk about software part of Ldr. Normally, LDR gives us analog values of voltage and we needed to convert it to digital values. So, we used in built ADC of ATMEGA32 that has pin on PORTA. We can convert any values between 0-5 V and this range divided into 1024 step. Therefore input between 0-5 V gives us output between 0-1023.

This is the basic idea of ADC. We used ADCSRA control and status register A and ADMUX ADC multiplexer selection register. ADC converter gave us unsigned row data and we divided 1024 and multiplied with 5000 to obtain millivolts value between 0-1023. We took millivolts because it gave us accuracy voltage differences. Also, you can see third part of code to increase score, make sound from buzzer and blink led. I will explain seven segments display and buzzer, led part. I just explain how we decided counting here, first we check millivolts are less than 1500 and score is less than 9. When these two cases are okey, we check are there any increase to prevent second increase in the same time. After that we called countpoint to active buzzer, led and change score.

 

 

 

Led and Buzzer

In this part, we used led and port’s buzzer. When score change, we blinked led and make sounds from buzzer to show new score. We used PD4 of buzzer and gave there high and low voltage with delay to obtain sound from buzzer. Also, we connected led to another Pin of PD4 to blink when buzzer make sounds. Also, we increase integer a that is equal our score in the below code.

 

 

Score Board

Our pinball project has a score board to show how many shots are on target. We used seven segments display to show the score. Also, we make a sound from a buzzer and blinked a led for each score. We used Ldr, that is a photo resistor, laser, buzzer and led as hardware designs while using seven segments display of board and receiving data from Ldr with ADC converter.

7-Segment Display

We used seven segments of board to show score. Port C indicates which seven segment display each digit is displayed on. Port C connects seven segments of board so we used Port

c. We created cases for numbers between 0-9. We sent output degree to Port C depending on number of scores that comes from countpoint funciton.

 

 

}

Solenoid Motors:

Selenoid motors work linearly forward and backward and our physical components that consist of physical components that turns linear motion to angular motion for flipper as you seen at below. It is a 12 V motor that is feed by the adaptor via H-bridge. H bridge provides us to drive motor with higher voltage than 5V.

Example code that drives right flipper:

—————————————————————————————————————————

 

Ultrasonic Sensors:

Ultrasonic sensor has 4 different pins that are Vcc, GND , echo and trigger. Our trigger is connected to PD0 and echo is connected to PD2(INT0). In our code we are sending high signal to PD0 for 10us.

We have used different type interrupt in our system that is executed right after interrupt pin is triggered. Once echo goes hight counter has started to count and stop when echo goes low. So this echo signal length gives us an information about the distance.

————————————————————————————————————————-

 

This pulse value gives us the count of clock cycle for ultrasonic signal triggered and echo to the sensor again which means the time of ultrasonic signal has exit and turn back again to the sensor. (pulse/fclk)x(340000mm/s)/2 = pulse/47. Ultrasonic sensor is used for detecting the coming ball to the gate from which direction. When our game is automatic mode, ultrasonic sensor gives distance value to our controller and controller controls the flipper witch respect to the ball distance. Give high voltage to motors with proper delays for blocking the ball that tends to pass from the gate.

Conclussion:

After we have built the setup our manual mode works properly but flipper angular freedom can be increased with using better physical components for gaining the stronger flipper hit to balls and ldr, laser connection can be repaired with better coverage for holding ldr value more stable. Another thing that we can develop is the automatic control. In our setup, gate width is narrow for getting rid of the high distance noises that causes flipper bad sometimes. Also with one ultrasonic sensor we could not detect the velocity of a ball, so this causes timing error of the flipper when ball is so slow and fast because our delay times is configured with setup slope and the expected ball velocities. If we have used 2 different ultrasonic sensors, we would have ability to detect the ball velocity and configure delays with respect to ball velocity in each time.

Our setup video youtube link: https://youtu.be/wSSWP-MrH78

Leave a Reply

Your email address will not be published. Required fields are marked *