How to use the DHT11 sensor module with Micro:bit board | Micro:bit with Temperature and Humidity

How to use the DHT11 sensor module with Micro:bit board | Micro:bit with Temperature and Humidity

Hello and welcome back. In this tutorial, we will learn how to use the DHT11 sensor module with the Micro: bit V2 board. This sensor can measure temperature and humidity; we’ll display these measurements on an LCD screen. Also, I have used the Microsoft MakeCode platform to write our code. MakeCode is great because it lets us build programs easily with code blocks, making it perfect for beginners. Also, this knowledge is useful for projects that need temperature and humidity data. You can use the DHT22 sensor with the same code if you need more accurate measurements.

I used the DHT11 sensor module in this project, but you can also use just the DHT11 sensor. If you choose the DHT11 sensor on its own, remember to connect a pull-up resistor. Using the DHT11 sensor module makes things simpler because it includes the pull-up resistor. If you want to learn more about the DHT11 sensor and its features, click this link for more information.

  • What is the Micro:bit board and how to use it step by step – Click on me
  • What is the DHT11 sensor and how to use it with Arduino – Click on me

OK, let’s do it step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect the Micro:bit board to the sensor shield.

How to use the DHT11 sensor module with Micro:bit board | Micro:bit with Temperature and Humidity

Step 3

Thirdly, connect the DHT11 sensor and LCD I2C module to the sensor shield. For that, use the circuit diagram below.

How to use the DHT11 sensor module with Micro:bit board | Micro:bit with Temperature and Humidity

Step 4

Now connect the Micro:bit board to the computer. Then go to the Makecode website.

Step 5

Next, create a new project. You can name it as you like. Then, include the DHT and LCD extensions.

Step 6

Now, copy and paste the following Python script to the Python tab. Then you can see the automatically generated code blocks. You can also make this code using code blocks.

def on_forever():
    makerbit.connect_lcd(39)
    dht11_dht22.query_data(DHTtype.DHT11, DigitalPin.P16, True, False, True)
    dht11_dht22.select_temp_type(tempType.CELSIUS)
    makerbit.show_string_on_lcd1602("Temp:", makerbit.position1602(LcdPosition1602.POS1), 16)
    makerbit.show_string_on_lcd1602("" + str(dht11_dht22.read_data(dataType.TEMPERATURE)),
        makerbit.position1602(LcdPosition1602.POS6),
        16)
    makerbit.show_string_on_lcd1602("Humi:", makerbit.position1602(LcdPosition1602.POS17), 16)
    makerbit.show_string_on_lcd1602("" + str(dht11_dht22.read_data(dataType.HUMIDITY)),
        makerbit.position1602(LcdPosition1602.POS22),
        16)
    basic.pause(10)
basic.forever(on_forever)

Step 7

Next, click the Download button and select your Micro:bit board. At this point, the Micro:bit board should be connected to the computer.

Step 8

After downloading the code, remove the USB cable and connect it to the Sensor shield power port. You can also use a 9V battery or other power source. Finally, you can test it using the soldering iron or hot air gun. Then, you can see the temperature and humidity values on the LCD screen.

OK, enjoy this tutorial, The full video guide is below. So we hope to see you in the next tutorial or project. Have a good day.

Troubleshooting

  • Check the Jumper wires.
  • Check the power source.
  • Check the contrast level on the I2C module.
  • Check the code blocks again.

How to use the DHT11 sensor module with Micro:bit board | Micro:bit with Temperature and Humidity

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *