Laser Reaction Game Design Project

advertisement
EE 330
Laser Reaction Game
Design Project
Shiya Liu & xin zhou
12/5/2011
1
Contents:
Introduction ------------------------------------------------------------------------------------------1
Basic design problems & Main ideas------------------------------------------------------1
Data analyze & Packages choices-------------------------------------------------------5
Schematic View------------------------------------------------------------------------------10
Implementation and Testing (Extra Credits)---------------------------------------------12
Conclusion------------------------------------------------------------------------------------17
2
1. Introduction:
This project is about to design a laser game which will randomly light up 5 LEDs one by one
from total 9 LEDs. The user need to use a laser pointer to point at detectors, the detector detects
laser, then the LED will be turned off automatically. After the fifth LED is turned off, the game
ends, and the total reaction time will be recorded. In this project, there are 5 steps that we worked
on. Main idea of design, coding, and then Packages choices and DATA analyze, the third step is
schematic design, and the last part is wiring and testing.
2. Basic design problems & Main ideas:
Before the circuit design, we have to come up with some good ideas and the easiest and most
static way to design this game.
Questions:
1. How to create random signals?
2. How to build detectors?
3. How to build a timer which can record the total reaction time?
4. How will the timer stop after the fifth LED is turned off?
There were also many other additional questions during the design. They are solved during the
testing or the wiring step.
3
Problem solved:
1. Using Microcontroller to create random lights is the easiest way to do it, though there are
also other ways to do it.
2. We used photo-resistors and regular resistors to make a voltage divider, so we can detect
the voltage between the photo-resistor and resistor using microcontroller. Actually this
can also be solved using many BJTs, but this will make our circuit much larger, and it
takes too much space on the breadboard.
3. To build a timer, we need 7-segment displays, 7-segment driver, and binary counters.
4. To stop the timer, this problem was solved during the testing part. We gave a 5V voltage
to the same pin at where the square wave is.
Coding the random lights:
The code for the game is shown below.
int value;
int number;
int set;
int x,y,z;
int signal=1;
unsigned long current;
void setup()
{
for(int i=2;i<=13;i++)
{
4
pinMode(i,OUTPUT);
}
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A5,INPUT);
Serial.begin(9600);
}
void loop()
{
set=analogRead(A2);
if(set==412) /* reset the LEDs. */
{
signal=1;
}
int i=0;
number=random(2,11); //obtain a random number
while(signal!=0) // start game
{
digitalWrite(13,LOW); //apply zero volts to start the counter
digitalWrite(12,LOW); //apply zero volts to start the counter
digitalWrite(number,HIGH); // turn on a LED
value=analogRead(A1); //read the voltage value between resistor
if(value>=170) // if the voltage between resistor larger than 170
{
digitalWrite(number,LOW); //turn off the current lit up LED
number=random(2,11); //obtain a random number
digitalWrite(number,HIGH); // turn on another LED
5
i=i+1; //count how many LED lights
}
if(i==5) //if 5 LED lights
{
signal=0; //jump out the while loop
digitalWrite(number,LOW); // turn off the LED
digitalWrite(13,HIGH); // stop the counter
digitalWrite(12,HIGH); // stop the counter
}
}
}
3. Data analyze & Packages choices
The main circuit in this project that we were building was the timer. To build a timer, we used
the packages “CD4055” as a 7-segment driver, “74LS93” as a 4 bit binary counter.
Binary counter”74LS93”:
The figure-1 below is the logic diagram of the package “74LS93” binary counter.
6
Figure 1, Logic Diagram of counter
From the figure, there are two inputs, four outputs. If circuit requires 4 bit, the input B should be
connected to output QA. RO(1) and RO(2) are used to enable or disable the bottom three flipflops.
7
7-segment driver “CD4055”:
Figure 2, PIN Diagram of CD4055
This 7-segment driver have 4 binary inputs, which means either the input voltage is 𝑉𝐻 or 𝑉𝐿 .
There are total 7 outputs which are matching the 7-segment display.
Figure 3, Option of Biasing
There are two options to bias this driver as shown above, the second option is better for our
design since we also need 5V to bias the many other circuits, so it is more convenient to have
just one positive voltage source.
8
Figure 4, Truth Table
This figure above is a truth table of 4 bit counting from 0 to A, but using as a timer driver, we
only need to count from 0 to 9 and then recycle. Then we found out from internet that RO(1)
should be connected to QB, RO(2) should be connected to QD. This will make it recycle from 9
to 0.
9
7-segments display:
Figure 5, PIN diagram of 7-segment display
7-segment LEDs are sensitive components which are easily burned if its current cannot be
controlled well. PIN 2,3,4,5,7,8,9,10 are the input which are connected to the output of Driver.
The highest voltage is 5V. From data sheet, it is also known that the voltage across the LEDs is
2V, the maximum current can go through LED is about 25 mA, which is shown below.
Then it is easy to calculate the resistance range we can add to connect the LED to the output of
driver. We used 150 ohms resistors.
10
4. Schematic View:
Timer Circuit:
Figure 6, Schematic of Timer Circuit
How is this working? Basically, we give a 1Hz input square wave, which was 0 ~ 5Vpp at input
A of Binary Counter, the output start at 0000, then it starts to count each time the 𝑉𝐻 triggers.
QA, QB, QC, QD four bits go to the driver, the driver drives 7-segment display as the same as
the truth table shown in figure 4.
11
3x3 grid of LED
In this section, the design of 3X3 grid of LED will be shown. In order to randomly pick LED and
detect the change of voltage, a microcontroller, which is arduino UNO, is used for this part.
There is a 3x3 grid of LED and each LED in the grid has a corresponding photo-resistor near-by.
Meanwhile, a 2200ohm resistor is in series with the photo-resistor. The reason why connect
photo-resistor and resistor in series is to make a voltage divider. When the laser pointer point at
the photo-resistor, the resistance of photo resistor becomes smaller which cause the voltage
between the resistors larger than before. When the microcontroller detects the change of voltage,
it will turn off this LED and randomly turn on another LED. After 5 lights, the game is end and
the time used is displayed on the 7 segments displays. The circuit for a single LED is shown on
figure 7. Other 8 LEDs have the same circuit. Every single LED has a specific output pin as its
source. However, there is only one input pin to detect the voltage change because every time
only one output pin can supply voltage.
Figure 7
12
Random LED schematic:
Figure 8, One Random LED circuit
Stopping counter:
After 5 lights, the counter needs to be stopped. The easiest way to achieve this goal is to apply a
5V voltage to the pin14, which is the input signal pin, of the 74LS93. It will stop the counter
effectively.
5. implementation and Testing (Extra Credits)
Before the whole circuit testing, we need to make sure every part is working as expected.
13
1. 7-segment test.
Figure 9, Internal Circuit of 7-segment
Give PIN 1,6 a 5V voltage, connect bottom PINs with 150 ohms resistors, and then connect the
bottom side to ground or 5V, to see what happened. For example, if PIN 1,6 is 5V, PIN 10 is 5V,
then LED A will not be lit up, if PIN 10 is connected to ground, LED A will be lit up. With 150
ohms resistor, the current going through LEDs is well controlled.
2. 7-segment driver test.
Figure 10, PIN diagram of driver
To test the driver, we initialize the four bit input to be 0, then a, b, c, d, e, f, should be all 𝑉𝐻 ,
except “g” point is 𝑉𝐿 . As expected, only LED “g” is on. We also measured the voltage of the 7
outputs. 𝑉𝐻 was indeed 5V, and 𝑉𝐿 is lower than 0V. That is because of the voltage of 𝑉𝐸𝐸 .
14
3. Binary counter test.
The circuit below is used for testing the binary counter. After built the circuit below, a 1Hz
square wave is applied on the pin 14. We can observe the output from those 4 LEDs. For
example, when only LED0 lit up, it means that the binary number is 0001. If LED0 and LED1 lit
up, the binary number that represents is 0011.
Figure 11
Figure 12
15
4. Random LED test
After the 3x3 grid LED and the detect circuit was built, the main task is to measure what specific
voltage is the signal to turn on another LED. In order to obtain this voltage, we pick one LED
and point the laser on it. Next, measure the voltage between the resistors. In the daytime, the
voltage of resistor is approximately 0.83V. However, we need change 0.83V to digital value
because the microcontroller cannot read analog value. According to the documentation of this
microcontroller, The Arduino board contains a 6 channel 10-bit analog to digital converter. As a
result, it will map input voltages between 0 and 5 volts into integer values between 0 and 1023
which means that 4.9mV per unit. 0.83V/4.9mV=169.3877. It is approximately 169 and this will
be the digital voltage of the resistor. Every voltage that larger than this value will cause the LED
change.
5. Stopping counter
There are so many ways to stop the counter. In the beginning, thyristors are used for solving this
problem. However, finally, our group found that the easiest way to solve it is to apply a 5V at the
pin14 which is the input signal pin for the 74LS93.
16
6. Final test & additional control
Two switches:
Two switches are added in the circuit. One switch is for the 7 segment display which is used for
set 7 segments to 0. Another switch is for the 3x3 grid LED which is used for restart this game.
Final test:
We built the timer circuit and implement a functional circuit for a complete working game.
During the presentation, two TAs played our game and the circuits worked very well. The
counter can counts the time accurately and is stopped after 5 lights. Multiple persons can play the
task consecutively.
17
6. Conclusion
This is our design for the laser reaction game. Although there are many problems are waiting for
us to improve, the purpose of this project is achieved. In the next step, we are going to make this
game more intelligence and convenient. For example, adding one more digit to count the time,
adding a alarm clock when time over.
Download