|

Building an Arduino Powered BBQ Thermometer

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 JavaScript Powered Arduino with Johnny-Five post, you walked through the basics of getting an Arduino Uno R3 prototyping platform up and running with NodeJS and the Johnny-Five framework. After configuring Arduino with the “StandardFirmata” sketch, you wrote code with JavaScript and NodeJS, running various versions of LED configurations. This showed several of the core principles of both electronics and software development for the Arduino platform. Having a few blinking LEDs with a button to press, though, isn’t the most exciting thing in the world. So now, in this post, it is time to tackle something fun: a food grade thermometer to monitor the temperature of a steak (or tofu or whatever else) on a grill, and light up an LED when it’s done!

The Parts List

Before you get rolling, you will need a small parts list, in addition to what you purchased for the last article. If you don’t already have an Arduino Uno and a general assortment of jumper wires, buttons, and LEDs, you should refer to the previous post for that list.

Additional items needed are:

The food grade thermometer that you want can be found at any grocery store or hardware store with grills. I purchased the cheapest, store-bought food thermometer with a 3-foot-long cord that plugs into the side of a base unit. Unplug the thermometer probe (called a “thermistor” – a “thermal resistor”) from the base and you can use it in your project.

thermistor-and-base

For this project to work, you must know if it is a 10K Ohm or 100K Ohm thermistor probe. This will inform you of the secondary resistor that you need to use in your circuit. If you have a 10K thermistor, you will need a 10K resistor. If you have a 100K thermistor, you will need a 100K resistor (this post will assume a 10K Ohm thermistor).

3/32″ Audio Input

The connector used for the thermistor probe is most likely going to be a 3/32″ audio input jack. It does not matter if the audio jack is mono or stereo: 2 wires or 3. Your thermistor should be 2 wire, but a 3 wire input jack will work just fine. You’ll simply ignore the 3rd connector on the input jack.

audio-input-jack

You will be connecting this to your breadboard with jumper wires and alligator clamps to create stability, while being able to move the input jack around. You’ll see why later, when you hook everything up.

Thermistor Configuration: Voltage Divider

Think back to the pull-down resistor configuration for the button, in the previous post. It looks something like this, as a schematic:

pull-down-resistor

The configuration for the thermistor is going to look the same, except for the use of a thermistor instead of a button.

voltage-divider-thermistor

This small configuration changes the circuit from a pull-down resistor to a voltage divider circuit. If you’d like to know more, do a little research on your own to see how a voltage divider works. It involves Ohm’s law, and knowing the input voltage and both of the resistor values.

Design Patterns: Voltage Divider versus Pull-Down Resistor

If the difference between the button circuit and thermistor circuit is just those two parts, then what is the difference between a pull-down resistor and a voltage divider? Nothing, other than the button versus thermistor. A button with a pull-down resistor can be calculated as a voltage divider circuit. The difference is that the button either provides 0 Ohm or infinite Ohm resistance, while the thermistor provides variable resistance through temperature changes.

Much like software design patterns, circuit design patterns are often differentiated by intent or use, and not by implementation.

Connecting The Thermistor Probe And LED

For this configuration, make sure that you have a red wire running from the Arduino power (5v) to the red line of the breadboard. Also use a black wire to run from the Arduino ground (gnd) to the breadboard’s blue line. This will let you power any number of components, and ground any number of circuits, on the breadboard.

breadboard-power

Resistor Protected LED

Now add a simple resistor protected LED circuit, similar to what you built last time. Use a 330K Ohm or 1K Ohm resistor, to create a nice bright LED. Connect Arduino digital pin 8 to the input of the resistor circuit. The pin number doesn’t really matter, as long as it’s a digital pin. Just remember what pin you chose, so the software can match. Then connect the output of the circuit to the breadboard’s ground line.

resistor-protected-led

Voltage Dividing A Thermistor

Set up the same configuration for the thermistor that you had used for the button and pull-down resistor. Only in this case, connect a red and black jumper wire where the button leads were. On the unconnected ends of the jumper wires, use your alligator clamps to connect the two leads on the back of the 3/32″ audio input jack (the extra set of jumper wires and alligator clamps are used because if you tried to plug the audio jack directly in to the breadboard, it wouldn’t fit).

Run a red wire from the power line of the breadboard to the input line of the thermistor. Then connect a line out of the thermistor’s output to analog pin 0 of the Arduino. Connect another wire from the same thermistor output to the thermistor’s matching resistor. Then connect the resistor to the ground line of the breadboard.

In diagram form, it looks like this:

audio-input-jack-connection

And the actual breadboard and Arduino setup should look something like this:

thermistor-led-breadboard

The signal line of the thermistor is connected to an analog input on the Arduino because you will need to read the actual voltage from the line. If you plugged it into a digital input pin, you would only get a 1 or 0 for the signal – on or off. It would behave like an oddly designed pull-down resistor. By using an analog input, you will get variations in the input signal – the actual voltage coming out of the thermistor’s signal line.

Let The Code Flow!

With the breadboard configured and everything plugged in to the Arduino Uno, it’s time to write some code, do some math, and determine when your steak is done! With SCIENCE!

Reading The Thermistor; Calculating Temperature

Remember the first version of the blinking LED code, and how it used a loop on the board? You’re going to be pulling that back off the shelf for the thermistor. In this case, you will read the current voltage from an analog input pin and then run a calculation on it to determine the temperature. This will be done using a Pin object from Johnny-Five, and a little bit of math, triggered on a loop.

Start with the basic configuration of the board and pins for the Arduino, a loop to get the current thermistor voltage and a call to calculate the current temperature.

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

var LEDPIN = 8;
var THMPIN = "A0";

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

  thm.on("change",  function(err, thmVoltage){
    currentTemp = convertVoltToTemp(thmVoltage);

    // do stuff w/ the temperature, here
  });

});

The “sensor” provides its own loop to check for changes. In this case, it is run every half second (500 milliseconds), because there isn’t much need to do it more often than that. In fact, you wouldn’t have any problem if you changed this to 1 or 2 seconds. It is nice to see temperature change a little more often than that, when testing, though.

Now you’ll need a convertVoltToTemp function that can convert the voltage in to a temperature. In this case, the return value will be a structure that contains Fahrenheit, Celsius, and Kelvin temperatures. That way you can use the temperature scale you are most comfortable with, or all of them if you want.

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
  };
}

For a complete and detailed understanding of these calculations, see the WikiPedia article on thermistors.

Light Up The LED

With the calculation to convert voltage into temperature in place, you can use this information to determine when your food is cooked!

Go back to the board “ready” callback and set up a simple check to turn the LED on if the temperature is greater than or equal to 135 degrees Fahrenheit. This is the “prime” temperature for a medium-rare steak, according to the USDA.

// ... existing variables, methods, etc.

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

  var alertTemperatureF = 135;
  var currentTemp;

  thm.on("change",  function(err, thmVoltage){
    currentTemp = convertVoltToTemp(thmVoltage);

    if (currentTemp.tempF >= alertTemperatureF) {
      led.on();
    } else {
      led.off();
    }

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

});

Test Your New Thermometer

The code you just wrote requires the temperature to get well over the point where it would be difficult to test without actually cooking a steak. For now, though, it will be easier to lower this temperature to something that can be tested at your desk.

For example, if you lower the alertTemperatureF to 90, then you can check whether or not you are generating a temperature above 90 degrees:

var alertTemperatureF = 90;

Plug It In And Test it

Plug the thermistor probe in to the input jack. Plug the Arduino in to your computer, and run the code:

node thermistor.js

The LED should be off when the code first starts up, with the actual temperature being logged to the console window:

logging-current-temp

Now take the thermistor probe, having cleaned it so that it does not have any old food or anything else on it, and hold it tightly between two fingers. The tip is where the temperature is read, so be sure it is firmly in your fingers. The console window should start logging an increase in temperature. Within a few seconds, it should be showing something above 90 degrees and the light will turn on:

thermistor-fingers-temp

thermistor-led-on

Inaccurate, But Consistent

Don’t worry if your thermistor doesn’t report 98.6 degrees when measuring yourself. It likely won’t, but that’s okay. Your store bought food thermometer won’t, either.

If you disconnect your Arduino, unplug the thermistor probe and then plug it back in to your store bought thermometer base – the store bought version should show the same temperature as your Arduino version. I’ve done this multiple times and verified the accuracy of my code, each time. I’ve even purchased additional digital food thermometers from the store and verified that all of them produce the same result as my Arduino version.

The thermistor you are using is designed to be more accurate at temperatures where food safety is important. But, the thermistor will be consistent above all else. As long as your connections to the breadboard, input jack and Arduino are good, and the thermistor itself is clean and in good condition, you will continue to get the same temperature reading from the thermistor for years to come.

Challenges: Solder A Perfboard, Build A Web App

You now have an Arduino powered food thermometer, worthy of any BBQ or cooking station. Well, almost worthy of that. If you really want to use this for some cooking, you’ll want to do a few things to make it stand up to real use:

  1. Solder the circuits to a perfboard
  2. Build a rocking mobile website so you can monitor the temperatures from your phone, and not just your computer or the LED
  3. Put it in a project box

A “perfboard” is a circuit board with hundreds of holes drilled in it, sized for electronics components. Buy a handful of boards, a soldering iron and practice soldering wires in to it before you solder actual components.

For the web application: you’re already using NodeJS, the hipster’s web server. Don’t stop with Johnny-Five. Checkout ExpressJS and Socket.io. See if you can get a web page to show you the current temperature, reported through a websocket.

Once you have it working the way you want, buy a small plastic project box and mount the parts in it. This will help protect the parts, prevent short circuits from things accidentally touching solder joints and leads, and keep everything safe from food splatters while cooking.

Safari Books Online has the content you need

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

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.
Arduino Cookbook, 2nd Edition helps you create your own toys, remote controllers, alarms, detectors, robots, and many other projects with the Arduino device.
In Beginning Arduino teaches by using an amazing set of 50 cool projects. You’ll progress from a complete beginner regarding Arduino programming and electronics knowledge to intermediate skills and the confidence to create your own amazing Arduino projects.
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.

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.
|

2 Responses to Building an Arduino Powered BBQ Thermometer

  1. Paul Freidrich says:

    How can Aurduino make enough power to heat BBQ? I don’t believe this is possible without some kind of powerful heating element. The Arduino cannot supply much current, not enough for heating element.

    • Bright 'N' Squirrelly says:

      The device does not heat the BBQ. It measures the temperature. You put the probe into your meat, and the arduino reads out how hot it is, because there are safety requirements for the internal temperature of meat. This could also be used to construct a candy thermometer.