I started experimenting with Arduino after attending a lecture given by Sarah Wiseman at the Royal Institution (Ri) in London. I've played with RFID readers, LEDs, etc. with varying degrees of success - but decided, as a result, that what I really needed was a simple user interface, rather than relying on outputting to a serial monitor, to start to make the projects useful - Enter the 16*2 LCD Display; It doesn't get much more simple than that!
I decided to use a Hitachi HD44780 based LCD, as the Arduino libraries contain drivers for this device, and discovered a host of tutorials on the net that describe various starter projects to display text on the screen, scroll text, etc. etc. - but I wanted to do something a bit different.
Inspired by my mis-spent youth, playing snake on my Nokia Mobile, I decided to make a snake-themed LCD project; Partly to prove that I could get an Arduino to drive an LCD screen as I wanted, and partly to see if I could remember how to code, as it's been about 20-years since I wrote any (which unfortunately is evident in the quality/structure of my code - I'm sure I could have written it more efficiently; perhaps I'll try to tidy it up one day!).
So the project connects an Hitachi HD44780 based LCD to an Arduino Uno board - and uses 'built from scratch' software to make a snake move clockwise around the edge of the screen. Apples randomly spawn in the bottom line of the LCD; the snake will grow in length when it eats one.
In order to make the project slightly more interesting (Challenging?), I also made the decision to use custom characters to represent the snake.
Hopefully this 'Instructable' will prove useful to those looking to do something a bit different with an LCD, or those trying out custom characters for the 1st time; Seasoned pros probably won't find much of interest here!
If you've already got an LCD hooked up to your Arduino and want to use, or hack, my code (It's coded to work with any size LCD, but I've only tested it on a 16*2, so would love to know if it works on something larger), feel free - though I'm sure you'd probably write it better than me!
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Gather the Ingredients!
For this project you'll need;
- 1 Arduino (I used an UNO)
- 1 HD44780 LCD Module (I got mine for a couple of £ on ebay)
- 1 10K Variable Resistor
- 1 470 Ohm resistor
- 1 16 Pin Header
- 1 Small Piece of VeroBoard or Breadboard
- Some Jumper Leads
- Soldering Iron and Solder
Step 2: Assemble the LCD Board
My LCD came supplied with the Header Pins needed to attach the module to the Veroboard, but I had to solder them in place. The header Pins need to go in straight, so it's advisable to fix one end first and adjust it until it's straight before soldering the remaining PINs.
Once the header Pins were in place I soldered the whole assembly onto my Veroboard before adding the rest of the connections.
There isn't really much wiring to do here. I started by soldering the 10k Resistor onto the board in an area clear from the LCD connector Pins. Wire the ends of the Variable Resistor to the +5v and Ground jumper wires that you'll use the connect the LCD to the Arduino (The Red and Black Jumper Wires in the Photo), and connect the wiper to the V0 Pin (The Blue wire on the board in the photo) - This controls the contrast of the screen.
Next connect the RW and VSS Pins to GND (The Black Wires in my picture) - If you want to power the LCD Backlight you will also need to connect the K Pin (Backlight Power GND) to GND.
Add a connection between the VDD (+5v) Pin on the LCD and the +5V jumper.
If you want to power the LCD Backlight you can do this by either; connecting the A Pin (Backlight 5V Supply) through a 470 Ohm Resistor to the 5V jumper, or (as I did) by connecting the A Pin, through a resistor, to a jumper lead (Yellow in my Photo), such that you can control the backlight from an Arduino Port. The resistor is important to prevent too much current damaging the Arduino port. If you're following my Veroboard layout you'll need to remember to break the copper track between the resistor solders (The copper tracks run Up/Down in my Photo), otherwise the resistor will be bypassed.
Next Up connect the D4-D7 Pins to jumper wires (These are Blue in my photo).
Lastly connect some jumpers to the RS and E Pins.(These are White in my Photo).
Test the circuit connections with a meter.
You're now ready to connect the LCD Board to the Arduino.
Step 3: Connect the LCD Board to the Arduino
For my Software you need to connect the LCD Board to the Arduino as follows;
- Red Jumper Lead (Power) to +5V
- Black Jumper Lead (GND) to GND
- Yellow Jumper Lead (Backlight A) to Digital Pin 9
- Blue Jumper Leads (4 of them)
- D4 to Digital Pin 5
- D5 to Digital Pin 4
- D6 to Digital Pin 3
- D7 to Digital Pin 2
- E to Digital Pin11
- RS to Digital Pin12
Then your ready to download and run the code!
Step 4: Download and Run the Code
All you need to do now is download an run the code on your Arduino.
Attached is the code I used - I've tried to comment it as thoroughly as I can, in the hope you'll understand what I tried to do - Some of the logic is a bit dodgy, but it works!
It's coded to work on any size LCD, but, as I said in my intro, I've only tested it on a 16*2 Display.
I hope you enjoy this project!
Thanks for reading.
1 Person Made This Project!
erkanokman made it!