Sensing the temperature

In this lesson, help Celsius measure the temperature using a temperature sensor, also called a thermistor.

A thermistor is a component that changes its resistance based on the ambient temperature.  To measure the voltage changes like you did with the potentiometer, you will need to add a resistor to create voltage divider.  You can then measure the voltage across the divider.

Let's give it a try!


Step 1 - Place the temperature sensor

Place the temperature sensor across the middle of the breadboard and connect one side to the power supply (5V) using a red wire.

Your kit comes with two types of thermistor.  One with a 1K maximum resistance, and one with a 10K resistance. The different values make it more or less sensitive.  For this example, use the 1K one (the one with the gold on top).


Step 2 - Create a voltage divider

Create a voltage divider by placing a resistor between the temperature sensor and the ground (GND) just like the picture on the right.

Add a yellow wire to the analog input (A0 pin).  This pin will be measuring the voltage continuously.  When the temperature changes, the voltage will increase and decrease and you can capture the digital value in your code.

Step 3 - Add a resistor for the LED

Add a 330 ohms resistor (orange, orange, brown) connected to digital pin 3 (4th from the bottom) with a blue wire.

Let's use the LED to display changes in temperature by controlling its brightness or its blink rate.


Step 4 - Add the LED

Add the LED across the breadboard (anode with the resistor and cathode on the other side).

Add a black or blue wire from the cathode to the ground header (GND) below.


Your circuit is all set, let's code!

The code

var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var celsius = new five.Sensor('A0');
var led = new five.Led(3);
var value = 0;

celsius.on('change', function() {
temp_value = this.value;
console.log('Temperature analog value is: ' + temp_value);

Experiment #1 - Touch the sensor

Touch the sensor between your fingers and see what happens to the LED.

Get something cold from the fridge and touch the sensor with it.  What happens?

Experiment #2 - Color display based on temperature.

Use an RGB LED and set the color of the LED based on the temperature sensed.  For example, blue when cold, green at ambient temperature and red if too hot.

Here is a quick example of code that you can use, but you will have to tweak it to make it work for you.

var five = require("johnny-five");
var board = new five.Board();
var clicks = 0;
board.on("ready", function() {
var celsius = new five.Sensor('A0');
var red = new five.Led(3);
var green = new five.Led(4);
var red = new five.Led(5);
var value = 0;

celsius.on('change', function() {
value = this.value;
console.log('Temperature value is: ' + value);
if ( value > 500 ) {
} else if ( value > 400 ) {; green.on();;
} else {;; blue.on();