Introduction
While the micro:bit can estimate the ambient temperature, it isn't as accurate as using an external temperature sensor. This is because the micro:bit actually measures the temperature of a silicon die on its CPU.Â
In this guide, you will learn to use an external temperature sensor module and the micro:bit to make a temperature and humidity display!Â
After completing this guide, you can use it to detect the temperature around you much more accurately.
-
-
-
-
-
-
-
basic.forever(function () { basic.showString("Temp:") basic.showNumber(Environment.temperature(Environment.DHT11Type.DHT11_temperature_C, DigitalPin.P0)) basic.showString("Hum:") basic.showNumber(Environment.temperature(Environment.DHT11Type.DHT11_humidity, DigitalPin.P0)) })
-
-
-
#include "DHT.h" #define DHTPIN 0 // what digital pin we're connected to #define DHTTYPE DHT11 // DHT 11 DHT dht(DHTPIN, DHTTYPE);
-
void setup() { Serial.begin(9600); Serial.println("DHT11 Sensor"); dht.begin(); }
-
void loop() { // Wait a few seconds between measurements. delay(2000); // Read Humidity float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } Serial.println("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("\n"); Serial.println("Temperature: "); Serial.print(t); Serial.print("\n"); }
-
#include "DHT.h" #define DHTPIN 0 // what digital pin we're connected to #define DHTTYPE DHT11 // DHT 11 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Serial.println("DHT11 test!"); dht.begin(); } void loop() { // Wait a few seconds between measurements. delay(2000); // Read Humidity float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } Serial.println("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("\n"); Serial.println("Temperature: "); Serial.print(t); Serial.print("\n"); }
-
-