Connect DS18B20 temperature sensor to micro:bit

I had a DS18B20 1-wire Temperature Sensor that came with the excellent Sensors CamJam EduKit for Raspberry Pi – I wondered if you could use this with micro:bit to get more accurate external temperature readings. It turns out, thanks to my amazing colleagues Mark and Carlos, that you can!

The version of the DS18B20 Temperature Sensor I have is waterproof, so this means I can make an alarm to tell me when my coffee is getting cold (although I’d probably need to use pin 1 or pin 2 for the sensor instead of pin 0).

Here’s what you need:

  • micro:bit
  • DS18B20 temperature sensor
  • some way of connecting it, e.g. breadboard, jumper wires and crocodile clip leads
  • 4.7kΩ resistor
  • Online MakeCode editor and internet access

Connect the sensor to the micro:bit like this:

Then in the MakeCode editor, add this extension.

You do this by clicking on the cog wheel, going to extensions, and paste in the ‘Search or enter project URL’ box.

You should see you have some new blocks you can use, one to show the temperature as a number, another as a string:

This project will show a bar graph of the temperature, but if your micro:bit firmware is up-to-date and you’re using a recent version of Chrome, you can also use webUSB to log temperature data on a connected computer, plot it in real time on a graph and save for later analysis in a spreadsheet or other program.

Here are a couple of simpler projects, one that just shows the temperature as a rounded integer when you press button A:

And another that uses a truncated string to show the temperature to 1 decimal place:

This entry was posted in computers, microbit and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>