How to Build a Temperature and Humidity Monitor with Raspberry Pi Pico, DHT11 and OLED Screen?

How to Build a Temperature and Humidity Monitor with Raspberry Pi Pico, DHT11 and OLED Screen

If you are looking for a fun and easy project to learn how to use a Raspberry Pi Pico, a DHT11 sensor and an OLED screen, this blog post is for you. In this tutorial, we will show you how to build a temperature and humidity monitor that displays the readings from the DHT11 sensor on a 0.96″ I2C OLED screen. You will also learn how to write and upload MicroPython code to your Pico board using Thonny IDE.

The DHT11 sensor is a low-cost and simple device that measures the temperature and humidity of the surrounding air using a thermistor and a capacitive sensor. It outputs the data as a digital signal that can be read by a microcontroller like the Raspberry Pi Pico. The OLED screen is a small and bright display that uses organic light-emitting diodes to show text and graphics. It communicates with the Pico via I2C protocol, which requires only two wires: SDA (data) and SCL (clock).

To complete this project, you will need the following components:

  • Raspberry Pi Pico
  • DHT11 sensor
  • 0.96″ I2C OLED screen
  • Breadboard
  • Jumper wires
  • Micro USB cable

The wiring diagram for this project is shown below. Connect the components as follows:

  • Connect the VCC pin of the DHT11 sensor to pin 36 (3V3 OUT) of the Pico.
  • Connect the GND pin of the DHT11 sensor to pin 38 (GND) of the Pico.
  • Connect the DATA pin of the DHT11 sensor to pin 4 (GP28) of the Pico.
  • Connect the GND pin of the OLED screen to any GND pin of the Pico.
  • Connect the VCC pin of the OLED screen to pin 36 (3V3 OUT) of the Pico.
  • Connect the SDA pin of the OLED screen to pin 6 (GP0) of the Pico.
  • Connect the SCL pin of the OLED screen to pin 7 (GP1) of the Pico.

Once you have wired everything up, you can proceed to write the code for this project. We will use Thonny IDE, which is a simple and user-friendly Python editor that comes pre-installed with Raspberry Pi OS. You can also download it from https://thonny.org/ if you are using a different operating system.

To write MicroPython code for your Pico, you need to install the MicroPython firmware on your board first. Follow these steps to do so:

  • Download the latest MicroPython UF2 file from https://micropython.org/download/rp2-pico/
  • Plug your Pico into your computer via USB while holding down the BOOTSEL button on the board. This will put your Pico into USB mass storage mode, and you should see a new drive called RPI-RP2 appear on your computer.
  • Drag and drop the MicroPython UF2 file onto the RPI-RP2 drive. This will flash the MicroPython firmware onto your Pico and reboot it.
  • Open Thonny IDE and select Tools > Options > Interpreter. Choose MicroPython (Raspberry Pi Pico) as your interpreter and select your Pico from the Port dropdown menu. Click OK to save your settings.

Now you are ready to write some code for your project. The code consists of three parts: SSD1306.py, dht.py and main.py.

SSD1306.py is a library that provides functions for controlling the OLED screen. You can download it from https://github.com/adafruit/micropython-adafruit-ssd1306/blob/master/ssd1306.py

dht.py is a library that provides functions for reading data from the DHT11 sensor. You can download it from https://github.com/dhylands/python_lcd/blob/master/lcd/dht.py

main.py is the main script that imports both libraries and displays the temperature and humidity readings on the OLED screen.

Copy and paste each part of the code into separate tabs in Thonny IDE, and save them as SSD1306.py, dht.py and main.py respectively on your Pico.

The main.py script looks like this:

Leave a Reply

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