
BARBECUES are a great joy of the outdoors ā but undercooked food isnāt. So letās make our own digital temperature sensor to check both coals and food are piping hot.
The BBC micro:bit has a built-in temperature sensor, but we will use a DS18B20 temperature probe instead. This is more accurate and more flexible ā we can even poke it into food (just check the coating of your sensor is food-safe).
Advertisement
The sensor has three wires: black, yellow and red. Slot each into a different row on your breadboard, then use a crocodile clip jumper wire to connect the black wire to the micro:bitās ground. We will need a resistor to help it talk to the micro:bit. Place your 4700 ohm resistor so that one leg shares a row with the yellow wire, and the other leg with the red. Connect the row with the yellow wire to micro:bitās pin 0, and the row with the red to 3V.
Letās add an LED to alert us when we reach the desired temperature. Connect the LEDās short leg to micro:bitās ground, and the longer leg to one end of a 470 ohm resistor. The other end should go to pin 1, so the resistor stops the LED drawing too much current.
Now to teach our micro:bit some new tricks. In the MakeCode editor, go to āAdvancedā, then click on āExtensionsā. In the search box, enter āDFRobot/pxt-ds18b20ā. Clicking on the result will cause an option called āDS18B20ā to appear in the editor menu. We have just added some code to help us read the sensor more easily, just like a programmer uses a pre-existing ālibraryā to add functions to their programs without having to write all the code themselves.
Grab a āshow numberā from āBasicā and clip into āforeverā. Clip into that a āroundā block from āMathā and, from āDS18B20ā, a āPin 0 Temperature_numberā. This will show the temperature as a whole number on the micro:bit screen.
Now for the alert. From āLogicā, take an āif/elseā block and clip into it a ā0 \> 0ā comparison. Clip another āpin 0 Temperature_numberā on the left-hand side of the comparison, and write a value on the other. This is your target temperature ā whatever you want the coals or the food to be.
Nestled under āifā add a ādigital write pin 1ā from āPinsā and type 1 in the box. Put another under āelseā, but leave the default zero. This turns the LED on and off as the temperature goes above and below the target. As ever, you can .
Finally, some safety frills. To keep the sensor cable away from the coals, I bent a wire coat hanger into a stand. For extra heat protection, I padded the wire with swatches clipped from oven mitts.
Now go forth and cook. Just donāt forget to change the target temperature between checking the BBQ and food, or you will end up with very well-done wings!
New stuff you need
Next in the series
2 Moisture and temperature-sensing plant
6 BBQ thermometer
7 Rain alarm Tell if precipitation is on the way
8 Mini weather station
9 & 10 Remote controlled pest-proof bird feeder parts 1&2
To download a printable version of this page click here
Email:maker@newscientist.com