Handheld Arduino Paper Rock Scissors Game Using 20x4 LCD Display With I2C

Introduction: Handheld Arduino Paper Rock Scissors Game Using 20x4 LCD Display With I2C

Hello everyone or maybe I should say "Hello World!"

It would be a great pleasure to share a project with you that has been my entry to many things Arduino. This is a handheld Arduino Paper Rock Scissors game using an I2C 20x4 LCD display. I know you might be thinking, "Another Paper Rock Scissors game?" But most Arduino Paper Rock Scissors games use simple LEDs and I also saw one that used paper symbols lifted by servos. Those are cool. This project uses 20x4 LCD display and did one with I2C and one without it (not shown here). Wanted an inexpensive case with a finished look, not just a bread-board mess. Not everyone has access to a 3D printer and wants to pay someone who does. And I wanted it to be easy to make so I could share the ideas with others. Since my programming skills are novice level the sketch is pretty simple and easy to understand and edit. This was my personal education into creating a sketch. You will find a lot of notes in the sketch and it has gone through many, many (20+?) iterations until I believe it is just right. Project costs less than $20 to make (non I2C).

Got started with Arduino in 2018 and went through their website and read everything I could. Built and experimented with the example projects it comes with and read a lot of Instructables so many of you have shared over the years. Really appreciate them and have learned so much from you all. Thank you. Now I want to share some of what I have learned adding my own creativity. Before the comments section pile up with lots of questions on how to do this and that please keep in mind, I started this with no experience in Arduino. I learned by building the example projects on the Arduino and the Instructables websites. I learned from you guys. When you get stuck those may be the quickest way for you to find a solution.

Step 1: Project Introduction

Selected the LCD display from Amazon and chose I2C 20x4 LCD because
of low cost (about $12 - $18) and ease of wiring and programming. If you want, you can use one without I2C and might get one as cheap as $7. But you will need to use a different library and wiring scheme and use up more Arduino pins. Don’t worry, it’s got enough to go either way. Serial I2C 20x4 would be easier to build, fewer wires are less confusing. But parallel 20x4 LCD is about $5 cheaper. I drew schematics for both wiring scemes. Most of the other parts I purchased from Amazon and couple of local stores. My box is an empty cappuccino drink mix box. I like that the lid easily pops off to turn the power on/off, work on any components or change battery. And "Hey!" the box was free and i like cappuccino. Recycling plastic is good for the environment. You can use whatever box you like that everything fits into or even skip the box or bread board the project. I wanted a "finished project look" on the cheap. I bet someone creates a 3D printed version. The Arduino plays the Paper Rock Scissors game with you on the LCD, keeps score, you can input with the buttons, and if you choose there is an option that lets you cheat. Originally the cheat feature was written for debugging purposes and when I was finished with it I commented it out. Just for fun I put it back in.

Step 2: Bread-board

I bread-boarded my circuits using Arduino Uno but when putting it all together used Arduino Nano because it fits in the box better. So, you can build this with either one. But remember to change a couple settings in IDE. The Nano is installed to the back of the LCD using Command Strips or double-sided sticky tape. Position the Arduino Nano beside the I2C piggyback board so the USB connector will face outward (to the right of LCD). You can use a 9v or 4x AA (which gives you 6v) battery box with SPST slide switch for power mounted inside the box also with Command Strips. Built it both ways, the Arduino has an on-board voltage regulator that brings it down to the 5 volts it needs. If you think about it this game can actually recycle "mostly dead 9v batteries" for power and work fine. (You do change smoke detector batteries twice a year, right?) Other devices that use a 9v battery might say it’s dead at 6 – 8 volts; but it’s not dead until it’s “Arduino Dead!”

While designing the project I used 4 SPST push buttons for input.
But building the finished game into the box used 5 SPST push buttons thinking in the future I might try to make a game that needed more buttons. Maybe a maze game? A resistor voltage divider for the buttons is mounted together on a scrap piece of proto board that can also be mounted with Command Strips.

Step 3: Assembly

Assembly:

The 4 main assemblies are the LCD with optional I2C piggyback board, Arduino Nano, the resistors and switches daisy chained to the interconnecting proto board and the battery box with on/off switch.

You should start by bread-boarding the circuit or hard wire the proto board following the schematic. I like storing the LCD face down in the box lid to keep from scratching it. I used a header on only the one side of Arduino that has 5v to connect it to proto board. I made a bridge with 3 headers (lots of solder work) from the Arduino to the proto board so they lay flat on the back of the LCD with Command strips or double-sided sticky tape. But really, the boards can be connected just soldering wires from one to the other. Used a female header to connect the proto board to the LCD I2C. The proto board resistor legs can be used to make the 5 solder points for the buttons. The other leg of each button goes to Arduino pin A0. Each button will need 2 wires soldered. Use an Ohm meter to determine which button legs to use but generally you can’t go wrong with nonadjacent legs (diagonal from each other).

Choose your settings for your Arduino in IDE. Download the sketch and load it onto the Arduino and test / trouble shoot.

Ready to put it in a box? Removed the label for cappuccino, washed and dried my box. Carefully measured and cut out the hole in the box for the LCD as you can see and it is mounted with 3 dowels screwed to three LCD corner holes (2 to the bottom of the box, 1 near the lid) just long enough to reach the back of the box and keep it in place with friction. The screw hole on the LCD the piggyback board might be too close to the terminal, so I omit it. Used an Exacto knife to drill pilot holes for screws in the dowels so they don't split (careful, don't slip and stab yourself, hold dowels with pliers). Had to bend / mush the box a little bit for final install, but it snaps back to proper shape. The holes for the buttons are "drilled" by positioning them (draw lines with straight edge) and heating up the terminals with a soldering iron until they "melt through" the box. Then removed the buttons after they cool off and solder on 6" - 9" CAT 5e wire scraps or 18ga to 22ga wire to the buttons. Install the buttons wire-first back into their holes then solder to the resistor proto-board. A dot of super glue, hot glue or even just friction will keep the buttons in place. On one build used some phone cable splicers (the red circles in the clear plastic blocks) to help make the last handful of connections easier between the battery box, resistor proto-board and LCD / Arduino assembly. If you want you can use solder and heat shrink instead. Then carefully and slowly push all the wire and components into the box and close the lid. You did install a battery and upload the Arduino sketch before doing all this? You will also need the library for 20x4 LCD display with or without I2C (whichever you choose) which you can download for free on Github. Power it up, try it out, and see if it works. Later I edited my sketch with pauses to make it easier to read, added the "blinking dots effect" and some other things along with plenty of comments. Try to position the Arduino so the USB can still be connected and a new sketch uploaded. Used a flow chart, of course, when creating the sketch. You'll find the comments pretty much define where each block of flow chart was.

You will find that the buttons are in a series / parallel circuit that allows you to use one Arduino input pin for as many buttons as you like. The circuit acts like a voltage divider to feed a value to the analog pin changing the value read by each button pressed. You can use the serial monitor to figure out your circuit values based on your resistors and change the "accepted values" in your sketch.

Hope you have fun building your own! If you make one or even make some mods of this please share with the rest of us. Thank you for reading.

Step 4: Programming and Settings

Now for fun with IDE. I hope you've been drinking some cappuccino. You might need it to help you stay awake.

You may find you will need to set up some libraries. You will need Wire.h For I2C, LCD.h for LCD, LiquidCrystal_I2C.h for I2C controlled LCD. You will also need to use the command lcd.begin(20,4) to tell Arduino you are using a 20 character 4 line LCD and there may be other settings.

For information on installing libraries, see: http://www.arduino.cc/en/Guide/Libraries

In the Arduino IDE you might find you will need to set your board and the port you have it connected to. The port can be found in your computer control panel/device manager/Universal Serial Bus controllers. You have to figure out which Arduino you are using. I'm using Arduino Nano but Uno works for this too. Choose your settings carefully.

You might need to figure out your I2C address. You should be able to read it directly from the board jumpers. You can also download an I2C scanner from Arduino.cc or also http://www.gammon.com.au/forum/?id=10896 and other places.

Somewhere around this point you should be able to load the program to the Arduino and test for functionality. Does the LCD screen light up? Can you read characters? One of times I built the circuit then tested it the backlight lit up but characters were unreadable. Spent hours (that’s right, HOURS) trying settings and toning connections to make sure it was built right. Gave up for a couple days. Came back to it later and realized the variable resistor on the piggyback board was set to minimum. Turned it up and the characters were visible. Bang head on desk. Another reason to bang your head on desk? If you need to change the battery you might need to adjust this variable resistor again. When this happened I cut a small hole in the back of the box for access.

You might need to set your own button values in this program based on the resistors you use for your buttons. You can use this handy little sketch for that and remember to activate the serial monitor. Run the sketch and press each button and write down each value. Then edit the sketch to reflect your button values. Then upload the edited sketch to your board and see if it works.

There's a lot of little variables that all have to be just right and yours might be different than mine. Being patient and trying different things will help you get yours working. Also remember after you set your Arduino variables (Like board name, com 3, 5 or whatever, processor and programmer [all under tools] ) you might have them all set right but it not work because you need to re-boot. Unplug the Arduino and plug it back into your computer. You might have to save and re-boot your computer again too.

Upload this sketch, run the monitor, push the buttons and record the values, then edit the Paper Rock Scissors sketch replacing my resistor values with yours. Run the Paper Rock Scissors sketch and see if it works right. Oh yeah, did you install your buttons in the wrong order? You might have to reinstall them if you want them in a particular order.

Have fun!

Step 5: Button Reading Sketch Will Help You Find Your Resister Values to Edit Into the Main Sketch. Push Each Button and Record Your Resistor Values to Enter Into the Main Sketch.

// button reading sketch

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

}

void loop() {

// put your main code here, to run repeatedly:

int buTTon; //For reading buttons

buTTon = 0; //For reading buttons

buTTon = analogRead(A0); //Command used to read the Buttons

delay(100);

Serial.println(buTTon);

Step 6: Parts Lists and Tools You Might Need

Parts List From Amazon:

Arduino Uno or Arduino Nano

20x4 LCD display with or without I2C

9v or 6v battery box with SPST slide switch (or get the slide switch separately)

5x SPST push buttons

1x Pull-up Resistor 1k - 5k

5x Resistors less than 1k, 200 - 500 Ohms is good

Parts Lists Other Locations or stores:

9v or 4x 1.5-volt battery (9v option lets you recycle "mostly dead" batteries)

Command Strips (used a refill pack) or double-sided sticky tape

Phone cable splicers (optional but makes it easy to connect wires)

A few inches of 1/4" dowel

Tiny wood screws to mount dowels to LCD

Solder

Heat Shrink for 18 ga wires

Scraps or Recycling Parts:

Empty cappuccino drink mix box (not everyone has a 3D printer, have some cappuccino and recycle some plastic)

About 1" x 2” Proto board scrap although I used protoboard from Amazon

Various length of 18ga to 22ga wire or Cat 5e solid core

Tools You Might Need:

Small Philips screwdriver

Small flat blade screwdriver

Exacto Knife

Soldering iron and solder

Heavy duty Scissors

Needle nose pliers

Ruler

Step 7: Some More Info and the Main Sketch

Thank you for reading. I know it's a lot. This is my first Intructable and this alone was a bit educational for me. Looking back I see I am wordy in some places and too brief in others. I should have broken the assembly down more into steps. And since I built this project about a dozen times until it was just right some of the pictures are from one model or other ones. I need to go back and take pictures of just one model. I also want to include a video or two. So yes, I'm going to come back and fix this stuff. But for now I put it into your hands. I hope you enjoy building it as much as I did. Thank you again for reading.

Be the First to Share

    Recommendations

    • Fruit and Veggies Speed Challenge

      Fruit and Veggies Speed Challenge
    • First Time Author Contest

      First Time Author Contest
    • Fandom Contest

      Fandom Contest

    Comments