Thermistor Sensor Module with micro:bit
In this guide, we will learn to use a thermistor. They are useful little components that change their resistance with temperature.
Completing this guide will teach you about thermistors and its relationship between resistance and temperature.
|Parts Used in This Guide|
Step 1 The Module
A thermistor is a type of variable resistor whose resistance changes with temperature.
Let's take a closer look at the thermistor module.
- Voltage Common Collector (VCC)
- Ground (GND)
- Digital Output (DO)
- Analog Output (AO)
Step 2 Overview of Pins
Step 3 Connect 3.3V to VCC
Step 4 Connect GND to GND
Step 5 Connect P0 to DO
Step 6 Connect P1 to AO
Step 7 Measuring analog value
- Open up MakeCode editor and start a new project
- Click on the 'Variables' tab.
- Click 'Make a Variable...' and name it 'AO'
- Then drag and drop a 'set ... to ...' block.
- From 'Basic' tab, drag and drop a 'show number' block
- From Variables tab, grab a 'AO' block and attach it to 'show number ... ' block
- From 'Pins' tab, get out a 'analog read pin' block and connect it to 'set ... to'
- Make sure the value in 'analog read pin' block is P1
- Again from 'Basic' tab, get out a 'pause (ms)' block and change its corresponding value to 1000
Step 8 Temperature reading
Let's use the micro:bit to get a temperature reading. What the micro:bit actually measures is the temperature of a silicon die on its CPU, which gives a rough estimate of the ambient temperature.
- Duplicate the 'show number' block: Right click on it and select 'Duplicate'.
- Place this new 'show number' block under the first 'show number' block
- From the Input tab, grab a 'temperature °C' block, and place it in the second 'show number' block.
Step 9 Set a threshold value
We are going to set a threshold value so that depending on the temperature, it may show a cross icon.
- From the 'Logic' tab, grab a 'if true ... then ...' block.
- Again back to the 'Logic' tab, grab a ' ... < ... ' block
- Change it to ' ... > ... '
- Replace its values with 'AO' block (get it from Variables tab), and '900'.
- Place this in the "if true ... then ..." block
- From 'Basic' tab, drag and drop a 'show icon ... ' block and place it in the if loop.
- Change the icon to a cross by clicking on the drop down arrow on the 'show icon... ' block
Step 10 Else statement
We are going to set another condition now, so that depending on the temperature, it may show a tick or a cross icon.
- Click on the white plus icon to add an 'else' statement.
- Right click on 'show icon' block and select 'Duplicate'.
- Change the second 'show icon' block's symbol to a tick and place this under the else statement.
This is a simple way to monitor temperature using a thermistor module. Displaying a tick or cross icon is just one of many ways to go about it. Thermistors can be found in refrigerators and air conditioners as well as many other systems.
Can you think of other ways you could use a thermistor module?
Step 11 Upload the code
It's time to upload the code to the micro:bit!
- Connect the micro:bit to your computer using a microUSB cable
- Click on the Download button
- Find the hex file in your computer's Downloads folder.
- Open up Finder on the MacOS or Explorer on Windows, and drag the hex file into MICROBIT under 'Devices' on the macOS.