ENGR2210        31 January 2012

Lab 1 - LCD’s and Sensing

Due: 10 February @ 9am


  In the first lab, you gained some comfort with the world of Arduino programming, and with digital inputs and outputs.  You learned how to connect buttons to digital inputs, what debouncing is, and how to do it in software and hardware.  You also learned how to use digital outputs to light an LED, and how to properly hook up and control an LED.  This lab will build on each of those skills, so if you are not comfortable with them - talk to an instructor or NINJA!


  In this lab, you will expand your familiarity with the capabilities of the Arduino microcontroller by building a computer-connected temperature sensor and LCD display.  

  When complete, the device will:

  If connected to a computer, it will also:

  This lab is expected to be challenging, and will stretch your knowledge in a few different directions.  I recommend starting early so that you have sufficient time to complete it, and tackling it in stages.  Don’t just try to build everything all at once.  It probably won’t work, and will be much harder for you to debug.

  These instructions try to be fairly explicit about how you could complete the lab.  If you feel like being creative, please do!  You don’t need to use the GUI we provide, or make your final product look exactly like the instructors’.
Part A - Reading Analog Sensors, and Datasheets

⬜  1 TMP36 Temperature Sensor

  The TMP36 temperature sensor is a very easy to use (relatively speaking) temperature sensor.  In class, we will go over how to use a resistive sensor, such as a thermistor or light sensor.  Thermocouples are cheap, but the resistance scales non-linearly with temperature.   TMP36 sensors have only three pins - ground, power supply, and the reading.  The reading is convertible into a temperature.

  1. Find the datasheet for the TMP36 sensor online, and read through it.  They are very dense, and full of much information you don’t care about.  Figure out which pins are which using the datasheet, and wire it up to your arduino.  Use the analogRead() command to read the value from the ADC.  Does it get change if you heat up the TMP36?
  2. The ADC has 10 bits of precision, which means it will always return a value in the range [0, 1023].  Use the map() command to convert this to a reading in millivolts.  Why should we use millivolts instead of Volts?
  3. Use the datasheet to figure out how you should convert the read voltage into a temperature measurement.  Using integer math, convert the voltage into a temperature.  What units should you use for your temperature?  Why are we using integer math?
  4. Communicate the temperature over the serial port, no faster than ~2Hz.  There’s no reason to flood the PC with readings.
  5. OPTIONAL : If you’re feeling particularly ambitious, you could low-pass filter the readings.

Part B - PWM Control of LEDs

⬜  1 @ 2x16 Character LCD with RGB Backlight

⬜  Current-limiting resistors for Backlight

  LCD’s come in a variety of styles, ranging from the style on your laptop, down to small color LCD’s, to small monochrome LCD’s, to the character LCD you have in front of you.  Character LCD’s are easier to use than graphical LCD’s, but more limited in capabilities.  Rather than displaying arbitrary graphics, the LCD has a preprogrammed set of characters that it can display in each space.  This LCD has space for 32 characters arranged in two rows.  The LCD has a backlight which shines through the liquid crystal, and makes it (much) easier to see the characters.  This LCD’s backlight is an RGB LED, which means we can change the background to nearly any color we want.

  1. Solder pins onto your LCD.  You will need pins 1-6 and 11-18.  You are welcome to solder pins to every spot if you want, though we will not be using 7-10.
  2. Now we need to wire up the LCD.  Start by wiring up the backlight.  The backlight consists of an RGB (Red, Green, Blue) LED, which you can think of as three separate LED’s.  On this LED, the R, G, and B channels share a common cathode (ground).  Just as in Lab 0, you need to limit the current through each LED.  What is the voltage across each LED?  What are the typical current limits?  What size resistor should you use for each LED to stay below them?  Are they the same?
  3. Using analogWrite(), turn on each of the backlight colors in some combination.  Does each color turn on as you’d expect?  Make the backlight orange-ish.  Despite the name, analogWrite() does not actually output an analog signal on the pin.  A link is on the course website with more information about this, for the curious.

Part C - The Fun Part

⬜  1 @ 10k Variable Resistor / Potentiometer for LCD Contrast Adjustment

  Now it’s time to wire up the rest of the LCD.  Follow the tutorial on Lady Ada’s (Limor Fried) website, at http://www.ladyada.net/learn/lcd/charlcd.html.  Note that your LCD does not have current-limiting resistors for the backlight, though hers does.  Her backlight also has a common anode.  In summary: don’t change the backlight wiring, which you completed in part B.

  1. To control the LCD, we will rely on the LiquidCrystal library distributed with the Arduino library.  Read the documentation on the Arduino website (http://arduino.cc/en/Reference/LiquidCrystal) to get an idea of what you can do with the library.  The LadyAda tutorial should also help get you started.
  2. Now, look at the datasheet.  What characters can you display?  Draw a non-English character on your screen.
  3. Make the LCD display the temperature.  Don’t use floating point math. (Hint: Use division and the modulus operator [%] to get whole / decimal degrees)
  4. Now, create a custom unit symbol to display after the temperature, indicating that you are using degrees Fahrenheit.  Alternatively, you can make and use some other custom symbol, like the PoE symbol below. The LiquidCrystal createChar() method will allow you to define up to 8 custom symbols.  You may want to look at the LadyAda tutorial for a helpful online utility.
  5. Add a button for switching from Celsius to Fahrenheit on the display.  Make sure you debounce the button!  You may want to define a new unit symbol as well.

Part D - Controlling from the PC

Finally, let’s add the ability to control the LCD from the host computer.  

  1. Instructors will provide a graphical user interface (GUI) written in Python.  You will need to install the Python Serial library from http://pyserial.sf.net.  Windows installers are at http://sourceforge.net/projects/pyserial/files/pyserial/2.5/.  You may also write your own UI in a different language if you’d like.
  2. We will communicate to the arduino with fixed length messages of 20 Bytes, to make decoding them simpler.  You will need to check every now and then whether you have received data on the serial port.  If you have received at least 20 Bytes, you should read 20 of them and decode them.
  3. The instructor’s GUI communicates with the LCD using the following packet format.  Use the serial output to help debug whether you are successfully decoding the packets.

1 Byte Packet ID

3 Byte Backlight Color (R,G,B)

16 Byte Message

  1. Make your LCD’s backlight controllable from the GUI, via those messages.
  2. Make your LCD’s message controllable from the GUI, via those messages.


  Please hand in a lab report at the completion of this lab.  I don’t need your answers to the questions in this handout.  Your report should contain, at a minimum:

  You may choose to write this report as a traditional lab report, or in the form of a tutorial for posting on a website or your portfolio.  The tutorial will be more work, but probably more valuable as well.