Introduction
We can get an estimate of the temperature using the Micro:bit, though what is actually provided is the temperature of the silicon die on its main CPU. But what if you wanted to get even more accurate temperature readings?Â
In this guide, we will use a DS18B20 temperature sensor module with the Micro:bit. This temperature sensor is able to get readings like 23.50 degree celsius rather than just 23 degree celsius.Â
Complete this guide to get started with using this very useful component, where it could be used for data logging, gardening assistance and more.
-
-
-
-
-
-
-
-
#include <OneWire.h> //includes the library OneWire #include <DallasTemperature.h> //includes the library DallasTemperature #define ONE_WIRE_BUS 0 // Temperature sensor's data wire is plugged into pin 0 of micro:bit OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); float celsius, fahrenheit; //Declare 2 floating point variables void setup(void) { // start serial port Serial.begin(9600); Serial.println("Temperature Monitor"); // Start up the sensor library sensors.begin(); } void loop(void) { Serial.print(" Reading temperature..."); sensors.requestTemperatures(); // Send the command to get temperature reading celsius = sensors.getTempCByIndex(ONE_WIRE_BUS); // Put the reading into a variable fahrenheit = celsius * 1.8 + 32.0; //convert to f Serial.println("COMPLETE"); Serial.print("Temperature is: "); Serial.print(celsius); Serial.print(" Celsius, "); Serial.print(fahrenheit); Serial.print(" Fahrenheit"); delay(1000); //waits for 1 second }
-
-