2.8 Read Temperature and Humidity

Previous projects have been using stage mode, but some functions are only available in upload mode, such as serial communication function. In this project, we will print the temperature and humidity of the DHT11 using the Serial Monitor in Upload Mode.

../_images/11_serial.png

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

ESP32 Starter Kit

320+

ESP32 Starter Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

ESP32 WROOM 32E

BUY

ESP32 Camera Extension

-

Breadboard

BUY

Jumper Wires

BUY

DHT11 Humiture Sensor

BUY

You Will Learn

  • Get the temperature and humidity from the DHT11 module

  • Serial Monitor for Upload Mode

  • Add extension

Build the Circuit

The digital temperature and humidity sensor DHT11 is a composite sensor that contains a calibrated digital signal output of temperature and humidity.

Now build the circuit according to the following diagram.

../_images/9_dht11_bb.png

Programming

1. Adding Extensions

Switch to Upload mode, click the Add Extension button in the bottom left corner, then select Communication to add it, and it will appear at the end of the palette area.

../_images/11_addcom.png

2. Initializing the ESP32 and Serial Monitor

In Upload mode, start ESP32 and then set the serial port baud rate.

  • [when ESP32 Starts up]: In Upload mode, start ESP32.

  • [set serial baud rate to]: From the Communications palette, used to set the baud rate of serial port 0, default is 115200. If you are using Mega2560, then you can choose to set baud rate in serial port 0~2.

../_images/11_init.png

3. Read temperature and humidity

Create 2 variables tem and humi to store the temperature and humidity respectively, the code will appear on the right side while you drag and drop the block.

../_images/11_readtem.png

4. Print them on the Serial Monitor

Write the read temperature and humidity to the Serial Monitor. To avoid transferring too fast and causing PictoBlox to jam, use the [wait seconds] block, to add some time interval for the next print.

../_images/11_writeserial.png

5. Uploading code

Unlike the Stage mode, the code in Upload mode needs to be uploaded to the ESP32 board using the Upload Code button to see the effect. This also allows you to unplug the USB cable and still have the program running.

../_images/11_upload.png

6. Turn on the serial monitor

Now open the Serial Monitor to see the temperature and humidity.

../_images/11_serial.png