by Max Rhodes
Project Overview
This is an Arduino powered circuit that turns on a red LED at a random time. Once the reaction button is pressed after the red reaction light is turned on, the Arduino and a shift register send the time it takes to press the button to a 4-digit 7-segment display. A false start mechanism using logic gates, and a user-ready-for-game mechanism with a blue LED and pushbutton are also included. This uses electronics concepts such as micro-controlling, multiplexing, and logic.
Tools and Materials
- Arduino Uno R3
- 1 Red LED
- 1 Blue LED
- 12 one-kilo-ohm resistors
- 1 74HCT08 4x2-in AND gate
- 1 74HCT04 Hex inverter
- 2 pushbuttons (I used normally open ones that were active high)
- 1 4-digit 7-segment display (8041AS CC)
- 1 Shift register (74HC595)
- Several wires
Step-by-Step Instructions
I first programmed (see attached code from beginning) and created the random LED code with a normally-open active-high switch. When I pressed the switch, the LED would turn off. I made sure to put resistors in series with each of the elements.
Next I programmed (see attached code from beginning) and set up my shift register and display. I used a shift register to minimize pin usage on my Arduino. I only used one shift register to minimize the amount of space I ended up using on my prototyping board, and I had enough pins on my Arduino to connect the remaining 4 display pins to. 8 of the 12 display pins were connected to the shift register, which were associated with the segments of each digit. The 4 common cathodes were connected to my Arduino to control the digits; the shift register would release the segment information to that digit once the latch pin was sent high from the Arduino as my code multiplexed through each digit, meaning it would release the segment data for one digit at a time and then turn off. But this is done so fast that it looks like every digit is always on. I made sure to connect the segment inputs in series with a resistor to not burn out the LEDs in the display. Note: the display I used is common cathode, so a low signal from the Arduino activates the digit in my code. If you use a different display, check if it's common cathode or anode. If it's common anode, this needs to be changed in the code along with the binary literals in my segData variable.
Then I realized that the reaction LED would start immediately once the code was uploaded, giving no time to the user to prepare for the game. So I created another LED and pushbutton circuit (practically the same as the first) called usrPin and readyLight in my code (see attached code from beginning). This worked by having the user press the button to signal they were ready, which turned on the blue LED, meaning that the game was starting. This sent the signal to the Arduino saying it could now start turning on the reaction red LED after a random amount of time. Then for each consecutive round the user would press the button to signal they were ready for the game to start. I also used resistors in series to not burn out the LED and also as a pull-down with the switch.
Then I realized that the game had no way to measure if someone pressed the button too early. So someone could theoretically press the button repeatedly to get a low time. I decided to add a false start mechanism using an inverter and an AND gate. I connected the inverter to the output of pin 8, which controlled when the red reaction LED would turn on, and connected it to one input of the AND gate. Then I connected the input to pin 9, which measured the reaction pushbutton, to the other input of the AND gate. This way, when the reaction LED was off, it would send a high (1) to the AND gate since it was inverted. If someone pressed the reaction button before that red reaction LED turned on, then the AND gate would send a 1 to pin 6, which would be read by my Arduino as a false start and turn off the display and blue ready-for-game LED. Then the user would have to start over and press the userReady button again. The code got much more complex for me, so I separated it into another document called "False Start Incorporated" (see attached code from beginning).