16x2 character LCDs are a great way to add a visual output to an Arduino project, though they are somewhat inflexible in terms of the information that they are able to display - for example, the character size and font is fixed. Or is it ? By using the 8 available user-defined characters, it's possible to add your own custom glyphs - and if you're clever, you can combine them to completely transform the capabilities of this humble display!
Our own resident clever clogs Carrie published the BigNums2x2 library a while back as a byproduct of another project she was working on. This library redefines the 8 available characters to create BigNumbers which each occupy 2x2 characters! As explained in her original blog post, Carrie was inspired by other, larger examples of the same technique, using 3x2 characters. Combining characters in this way revolutionizes LCD usage, since you can now easily take a reading from across the room, making it ideal for at-a-glance data. One of the most common numeric values that humans like to glance at is temperature data, so I thought it would be fun to create a simple thermometer using a DHT11 and an Arduino Uno, in order to put the library through its paces.
I happened to have an unused Adafruit RGB backlight positive LCD 16x2 handy, so I soldered on the headers, then followed their wiring guide to ensure everything was working. The particular LCD that I'm using is RGB-backlit, but to keep the project somewhat generic and applicable to standard single-color displays, I resisted the urge to get fancy, and only wired up the R(ed). There's quite a bit of wiring required, with 12 of the 16 pins populated on the standard LCD (the RGB adds another two pins for controlling green and blue). The Adafruit tutorial has an excellent description of how to hook it up, as well as what each pin does, but here's a cheat sheet so that you can check your work, or skip the long version:
1 GND
2 +5V
3 contrast pot wiper (with other sides of pot connected to GND and +5V respectively)
4 Arduino D7
5 GND
6 Arduino D8
11 Arduino D9
12 Arduino D10
13 Arduino D11
14 Arduino D12
15 +5V
16 GND
2
Test the LCD
Once you've got the LCD wired up, it's a good idea to give it a quick test before proceeding, so grab the built in HelloWorld example from File->Examples->LiquidCrystal. The Adafruit tutorial uses different pins than the Arduino default, so we'll need to tweak the code slightly; instead of:
for the way we wired it. Compile and Upload the sketch, and you should see a lovely hello, world! on your LCD. If not, hit me up in the comments and I'll try to help you figure out what went wrong! 💙
3
Add the DHT11
Now that we know the LCD is working, let's have a look at the temperature. I'm using the commonly available, inexpensive, DHT11. It's not the fastest or most accurate way to measure temperature, but it's cheap, and good enough for our purposes. Hook the middle (out) pin on the DHT11 to digital pin 2 on the Arduino, and the + and - pins to 5V and GND respectively. You'll need to install the Adafruit DHT sensor library as well as its dependency, the Adafruit Unified Sensor library - if you've not done this before, Adafruit has an excellent walk-through. With the libraries installed, we can run another quick test sketch like we did for the LCD: open File->Examples->DHT->DHTtester and uncomment this line (15 at the time of writing) by removing the leading forward slashes:
#define DHTTYPE DHT11 // DHT 11
then comment out this line (16) by prefixing it with two forward slashes:
and give it a quick Compile. If you run it, chances are you won't see the expected output on the serial monitor, but as long as it compiled OK, we should be good for now.