002 - Brickcell DHT11 | MakeCode Microbit
Introduction
The DHT11 is a low-cost, digital temperature and humidity sensor. It is commonly used in electronics projects and application to measure temperature and relative humidity. The sensor is consists of a capacitive humidity seensor and a thermistor to measure temperature. It provides digital output, making it relatively easy to interface with microcontrollers like microbit.
Temperature Range
The DHT11 can measure temperatures in the range of 0 degree Celsius to 50 degrees Celsius with accuracy of +/-2 degrees Celsius.
Humidity Range
The DHT11 can measure humidity in the range of 20% to 90% with a +/-5% accuracy.
Interface
The DHT11 communicates with the microcontr4oller 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.
- Connect the DHT11 sensor GND pin to microbit GND pin.
- Connect the DHT11 sensor VCC pin to microbit VCC pin.
- Connect the DHT11 sensor signal (S) pin to microbit pin 0.
Software Instruction
Now, let's start into programming the micro:bit to utilize the NTC temperature sensor.
- Login to https://makecode.microbit.org/ using your Microsoft account.
- Create a new project by clicking the "New Project" button. You may name it anything you want, I suggest to name it with descriptive name such as "temperature-dht11-test".
- Click the "Extensions" block just under the "Math" block.
- Type https://github.com/gbantique/brickcell-temperature-dht11/ on the search bar.
- Select the "brickcell-temperature-dht11" from the search results. The "temperature dht11" block should appear under the "Brickcell" block.
- Copy the code provided below.
1serial.setBaudRate(BaudRate.BaudRate115200)
2
3basic.forever(function () {
4 serial.writeLine("" + (Brickcell.readDHT(dataType.temperature, DigitalPin.P0)))
5 basic.pause(2000)
6})
- 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 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 instruction above, you should be able to view the measured temperature/humidity on the serial terminal every 2000 milliseconds.
Posts in this series
- 016 - Brickcell 8x16 Dot Matrix Display | MakeCode Microbit
- 015 - Brickcell 8x8 Dot Matrix Display | MakeCode Microbit
- 014 - Brickcell CO2 SGP30 | MakeCode Microbit
- 013 - Brickcell Gesture APDS9960 | MakeCode Microbit
- 012 - Brickcell Rotary Encoder | MakeCode Microbit
- 011 - Brickcell RTC DS3231 | MakeCode Microbit
- 010 - Brickcell Gyro MPU6050 | MakeCode Microbit
- 009 - Brickcell TOF VL53L0X | MakeCode Microbit
- 008 - Brickcell Color TCS34725 | MakeCode Microbit
- 007 - Brickcell Pressure BMP280 | MakeCode Microbit
- 006 - Brickcell Weight HX711 | MakeCode Microbit
- 005 - Brickcell Fine Dust | MakeCode Microbit
- 004 - Brickcell Ultrasonic HCSR04 | MakeCode Microbit
- 003 - Brickcell NTC Temperature | MakeCode Microbit
- 001 - Brickcell LCD I2C | MakeCode Microbit
No comments yet!