Aug 21, 2013

Arduino: LCD thermometer

I am truly and utterly in love with the Arduino project. There is no simpler and easier way to learn both programming and electronics. Believe me, the smartest gift for a 12-year old kid today is a C beginner book ("Beginning C with Arduino" is a perfect fit: read and approved!), an Arduino starter kit and some guidance to get going. If this had been around 30 years ago, a lot of innocent components would have been spared an untimely death at my n00b hands :D

I usually practice what I preach, so my own kids (10 and 12) are on their way. I can't believe how fast they learn, you should see reading schematics, wiring at light speed and correcting my fat finger mistakes: "Dad, you got this one wrong, it must go to the ground". Awesome.

Anyway, here's a cool little project I've built once I could actually lay my hands on the board again. This is a mix between two projects included in the starter kit, i.e. the Love-o-meter (temperature sensor) and the Crystal Ball (LCD screen). Fritzing schematic and code are on GitHub.

The TMP36 temperature sensor is connected to analog input A0. Its value is read every second by the program. The LCD screen is wired like in the Crystal Ball project, with a potentiometer to adjust brightness.

To avoid displaying "jumpy" temperatures, I'm storing and averaging the last 256 samples. This is implemented using a simple array-based circular buffer. Once the average temperature has been computed, it's displayed on the LCD screen.

A couple more things:

  • I'm defining a custom character (°), using a 5x7 bitmap.
  • I'm using dtostrf() to convert a float into a string. Normally, sprintf() would be used, but the Arduino library doesn't provide float support in sprintf().

Here's the full code.



Till next time... Hack at the world!

No comments:

Post a Comment