Introduction: Arduino First to 20 Game!
This application uses the Arduino board to play the classic first to 20 game. Here's how the game works. You as the user will compete with the computer to reach the number 20 first by only adding either 1 or 2 to the score every turn. The first to 20 wins the game.
Step 1: Parts
These are the parts you will need:
1) Arduino Board (I went with the Arduino UNO)
2) 2 Potentiometers
3) LCD (I used a 16x2 LCD)
Step 2: Wiring the LCD
I followed the circuit diagram provided above to wire up the LCD. I highly recommend soldering the wires to the LCD to ensure maximum reliable performance. However you can also loop wires tightly around their corresponding pin hole. The latter method runs the risk of wires contacting each other with might affect the LCD performance. I also recommend using the breadboard for wiring.
The various pin wiring:
- VSS pin to ground and leftmost pin of potentiometer.
- VDD pin to 5 V and rightmost pin of potentiometer.
- V0 pin to centre pin for potentiometer.
- RS pin to digital pin 12.
- RW pin to ground.
- E pin to digital pin 11.
- The next 7 pins are data pins and only 4 of them have to be used. I went with D4 to D7, wiring them to digital pins 5-2 respectively.
- Pin A to 5 V.
- Pin K to ground.
Although the last 2 pins are not wired in the diagram, I went ahead and wired them up as they provide the back light for the LCD. The use of the potentiometer in this case is to adjust the contrast of the LCD.
Step 3: Wiring the Control Pontentiometer
The input of the addition of 1 or 2 is done through the use of a pontentiometer. The way I did this is by finding the max and min value of the potentiometer. The max value was about 1024 and min value was 0. So I decided that an input of less than 512 (mid point of min and max) would be considered input of 1 and greater than 512 would be considered input of 2.
Wiring the Potentiometer:
- Leftmost pin to ground.
- Centre pin to analog pin A0.
- Rightmost pin to 5 V.
Step 4: Program
This is the code needed to run this application. I do believe it can be shortened as I have not played around with Arduino in a while but nonetheless it is here for your viewing.