|

Arduino: Show me the Temperature!

A guest post by Derick Bailey, who is a Developer Advocate for Kendo UI, a developer, speaker, trainer, screen-caster and much more. Derick blogs at DerickBailey.LosTechies.com, produces screencasts at WatchMeCode.net and tweets as @derickbailey.

In the first article in this series, you walked through the basics of getting an Arduino device up and running with NodeJS and Johnny-Five. The second article had you connect a food-grade thermometer probe to your Arduino via a breadboard. The net result is that you can know when your steak, pork chops, tofu or other food item is done cooking, using a NodeJS application on your computer. It lights up an LED on the breadboard and tells you that the temperature has reached the desired temperature. But wouldn’t it be nice to have a little more information than just done or not done? Wouldn’t it be nice to know the actual temperature of the steak so that you can start getting other food ready just before the steak is done?

No problem! You can use a Lquid Crystal Display (LCD) for just this purpose, and it’s easy to get it working to show what you want! In this final post of this series, we are going to tackle this very thing.

Connecting A 16×2, Parallel LCD

It’s easy to find LCD screens that are compatible with Arduino software. They can usually be purchased from the same store where you got your Arduino board. Or, they can be found on any websites that deal with Arduino parts. The most common LCD type to get is a 16pin, 16×2 character display with backlight and contrast. They are cheap and they are easy to control. All you need to do is hook up 12 out of the 16 pins in a configuration that looks like this:

lcd-configuration

Wait, this was supposed to be easy, right? The good news is that the software you need to run this LCD is very simple. Unfortunately, hooking up the LCD is a little less than easy when using a standard 16 pin, parallel LCD for an Arduino project. There are a lot of wires to run – 12 of them. And if you want variable contrast in the LCD (which you do want, trust me) you’ll need to have a potentiometer in the mix.

A Potentiometer?

A potentiometer is another type of variable resistor, much like the thermistor used to get temperature readings. In this case, the variance comes from turning the knob on the potentiometer. When the signal line from the potentiometer is hooked up to pin 3 of the LCD, it will change the contrast of the display. This is a very useful feature to have as it lets you get the display working at the anticipated angle of viewing.

For this project, you might not need a potentiometer. You could replace it with a single resistor of relatively low value, like 1K Ohm (see the LCD temperature display below).

To LED Or Not To LED?

In spite of all the wires needed, you should take the time to hook up the LCD according to the diagram above. But notice that one of the pins used by the LCD was previously used by your code to turn the LED on and off. You have two choices now:

  1. Hook up the LED to a different pin (easy enough)
  2. Toss the LED aside, since you’ll have an LCD (even easier)

Personally, I think you should toss the LED aside. With the LCD in place, you don’t really need the LED. The end result, including the potentiometer and the thermistor configuration, looks like this:

lcd-thermistor-configuratio

Now it’s time to get the code flowing and show the current temperature on the LCD.

Show Me The Temperature!

Open a new .js file in your project folder where Johnny-Five is installed, and add this code (the majority of this comes from the previous code you had written).

var j5 = require("johnny-five");
var board = new j5.Board();

var THMPIN = "A0";

board.on("ready", function(){
  var thm = new j5.Sensor({ pin: THMPIN, freq: 500 });
  var currentTemp;

  var lcd = new j5.LCD({ pins: [ 7, 8, 9, 10, 11, 12 ] });
  var lcdIsReady = false;

  lcd.on("ready", function(){
    lcd.clear();
    lcdIsReady = true;
  });

  thm.on("change",  function(err, thmVoltage){
    if (!lcdIsReady){ return; }

    currentTemp = convertVoltToTemp(thmVoltage);

    lcd.setCursor(0,0);
    lcd.print("TempF: " + currentTemp.tempF);
    lcd.setCursor(0, 1);
    lcd.print("TempC: " + currentTemp.tempC);

    console.log("Current TempF: ", currentTemp.tempF);
  });

});

function convertVoltToTemp(volt){
  var tempK, tempC, tempF;

  // get the Kelvin temperature
  tempK = Math.log(((10240000/volt) - 10000));
  tempK = 1 / (0.001129148 + (0.000234125 * tempK) + 
    (0.0000000876741 * tempK * tempK * tempK));

  // convert to Celsius and round to 1 decimal place
  tempC = tempK - 273.15;
  tempC = Math.round(tempC*10)/10;

  // get the Fahrenheit temperature, rounded
  tempF = (tempC * 1.8) + 32;
  tempF = Math.round(tempF*10)/10;

  // return all three temperature scales
  return {
    tempK: tempK,
    tempC: tempC,
    tempF: tempF
  };
}

When you run this code, you’ll still see temperature reports in the console window. But now you’ll also see the same temperature reports on the LCD!

lcd-temperature-display

Now you can monitor the temperature and get other food and related items ready just before your thermometer reaches the desired temperature. You’ll also be able to see if you’ve severely overcooked or undercooked your food!

Serial LCDs: A Simplification And Complication

Even with all of the wires that you have to run, the LCD configuration for the food thermometer is not difficult. It just takes time.

If this is horribly annoying, though, there is another option. You can use a Serial LCD kit, which reduces the wiring from 12 down to 4 (or 3 in some cases). The down side to the Serial LCD, is that you can’t control it from Johnny-Five at this point. You would have to write C for the Arduino to make that work.

Perhaps this should probably be your next project anyway: take the code from your NodeJS and Johnny-Five based application, and write it in Arduino C, directly. Replace the parallel LCD with a serial LCD, and solder everything to a perfboard so it can be mounted in a project box.

Good luck, and happy hardware-hacking!

Safari Books Online has the content you need

These resources in Safari Books Online will help you enhance your Arduino project:

Arduino Robotics will show you how to use your Arduino to control a variety of different robots, while providing step-by-step instructions on the entire robot building process.
Getting Started with Arduino gives you lots of ideas for Arduino projects and helps you get started with them right away. From getting organized to putting the final touches on your prototype, all the information you need is right in the book.
Get Started with Arduino: A Hands-On Introductory Workshop is a video that teaches you how to use the Arduino for making projects that can sense and react to the real world.
Arduino Cookbook, 2nd Edition helps you create your own toys, remote controllers, alarms, detectors, robots, and many other projects with the Arduino device.

About this author

Dericknewheadshot Derick Bailey is a Developer Advocate for Kendo UI, a developer, speaker, trainer, screen-caster and much more. He’s been slinging code since the late 80’s and doing it professionally since the mid 90′s. These days, Derick spends his time primarily writing JavaScript with back-end languages of all types, including Ruby, NodeJS, .NET and more. Derick blogs at DerickBailey.LosTechies.com, produces screencasts at WatchMeCode.net, tweets as @derickbailey and provides support and assistance for JavaScript, BackboneJS, MarionetteJS and much more around the web.

About Safari Books Online

Safari Books Online is an online learning library that provides access to thousands of technical, engineering, business, and digital media books and training videos. Get the latest information on topics like Windows 8, Android Development, iOS Development, Cloud Computing, HTML5, and so much more – sometimes even before the book is published or on bookshelves. Learn something new today with a free subscription to Safari Books Online.
|

Comments are closed.