Learn electronics, coding, and projects — step by step.

002 - MakeCode MicroBit: Brickcell DHT11

George Bantique September 30, 2023 No Comments

Table of Contents

The DHT11 is a low-cost, digital temperature and humidity sensor. It is commonly used in electronics projects and applications to measure temperature and relative humidity. The sensor consists of a capacitive humidity sensor and a thermistor to measure temperature. It provides digital output, making it relatively easy to interface with microcontrollers like the micro:bit.

Temperature Range

The DHT11 can measure temperatures in the range of 0°C to 50°C with an accuracy of ±2°C.

Humidity Range

The DHT11 can measure humidity in the range of 20% to 90% with an accuracy of ±5%.

Interface

The DHT11 communicates with the microcontroller using a single-wire (1-wire) communication protocol, which involves sending and receiving data via a single data pin.

Hardware Instruction

Let's explore how to connect the DHT11 Temperature and Humidity sensor to a micro:bit microcontroller and utilize MakeCode for programming.

  1. Connect the DHT11 sensor GND pin to microbit GND pin.
  2. Connect the DHT11 sensor VCC pin to microbit VCC pin.
  3. Connect the DHT11 sensor signal (S) pin to microbit pin 0.

Software Instruction

Now, let's start programming the micro:bit to utilize the DHT11 temperature and humidity sensor.

  1. Login to https://makecode.microbit.org/ using your Microsoft account.
  2. Create a new project by clicking the “New Project” button. You may name it anything you want, for example temperature-dht11-test.
  3. Click the “Extensions” block just under the “Math” block.
  4. Type https://github.com/gbantique/brickcell-temperature-dht11/ in the search bar.
  5. Select the “brickcell-temperature-dht11” from the search results. The “temperature dht11” block should appear under the “Brickcell” block.
  6. Copy the code provided below.

serial.setBaudRate(BaudRate.BaudRate115200)

basic.forever(function () {
    serial.writeLine("" + (Brickcell.readDHT(dataType.temperature, DigitalPin.P0)))
    basic.pause(2000)
})

7. Open a Serial Monitor such as Termite terminal app: https://www.compuphase.com/software_termite.htm/. Set the baud rate to 115200 bps.

Or you can make a copy of my created project in your MakeCode workspace:

https://makecode.microbit.org/S97457-22215-78353-20278/

Expected Result

If you carefully follow the provided instructions above, you should be able to view the measured temperature and humidity values on the serial terminal every 2000 milliseconds.

×

Leave a Reply

Required fields are marked *






Related Articles: (by Categories)