Zonnestroompanelen in Nederland

duurzaamheid achter de meter

(19) The GY-21P: temperature, barometric pressure and humidity sensor in one breakout board

by Floris Wouterlood – August 21, 2020

Summary
A GY-21P is a breakout board with I2C functionality that contains two sensors. One is a BMP280 which measures barometric pressure and temperature. The other sensor is a Si7021 which measures temperature and relative humidity. The breakout board reports therefore temperature twice.
This project discusses the wiring a GY-21P to an Arduino Nano and to an ESP8266 type microcontroller board. Also discussed are the basic instructions needed by those microcontroller boards to extract the environmental data from the sensors and to display them in Serial Monitor.

Introduction
If one wants to build a weather station the intuitive choice is to use dedicated sensors to measure the environmental parameters. Most important parameters in this respect are temperature, relative humidity and barometric pressure. There are several good and affordable ‘single’ sensors on the market. One consideration to apply a single sensor that reports several parameters is space: the desire to create a weather station with a very small form factor.
The attractiveness of the GY-21P breakout board lies in the fact that it is small (11×14 mm) and that it accurately measures temperature, humidity and barometric pressure simultaneously. On board is a reliable Si7021/SHT21 temperature/humidity sensor and an accurate BMP280 barometric pressure/temperature sensor (see figure 1). The temperature sensors are of the thermistor type while the humidity sensor measures resistance over a polymer substrate whose resistance depends on the amount of water absorbed from the air. The temperature range is between -40 oC and +125 oC while relative humidities between 0% and 100% are measured. The BMP280 component measures air pressure. As it is a very accurate sensor that is used as altitude reporter in drones, correction for altitude above sea level is necessary for calibration. My home in The Netherlands is built on terrain 0.5 meter below sea level and the GY-21P sensor is positioned slightly higher, say exactly at average sea level.

GY-21P: pins and connectivity with an Arduino
The GY21-P breakout board (figure 1) has four pins of which two serve the I2C data communication protocol. The Si7021/SHT21 humidity sensor and the BMP280 component are in figure 1 indicated with arrows. A voltage level shifter is on board to accommodate both 5V (Arduino Uno, Nano) and 3.3V (ESP8266) microcontroller logic. The pins on the breakout board are labeled VIN, GND, SCL and SDA. VIN and GND are the usual power supply pins. The pins marked SCL and SDA are the I2C pins necessary for data exchange with the Arduino.

Connectivity with an Arduino is quite straightforward and is pictured in figure 1. We use in this example an Arduino Nano (the Arduino Uno has the same pin layout) and a Lua NodeMCU ESP8266.

Figure 1: Wiring scheme of a GY-21P and an Arduino, in this example a Nano. VIN is connected to the 5V pin of the Nano, GND to GND, SCL to pin A5 and SDA to pin A4. Pull-up resistors for SCL and SDA are compulsory.

Connectivity table

Pull up resistors
A 4.7 kΩ resistor must be mounted between SDA and VIN, and another one between SCL and VIN, in order to keep the signal level high during operation. According to the spec sheet of a Si7021 one may use 10 kΩ pull-up resistors as well.

Electronics and supplies
1x Arduino Nano microcontroller board, Si7021 breakout board, 2x 4.7 kΩ resistor, breadboard, jumper wires.

Figure 2: Bench version of a GY-21P (arrow) wired to an Arduino Nano. The 4.7 kΩ pull-up resistors placed between 5V and pin A4 and between 5V and pin A5 are indicated with asterisks. Right panel: Serial Monitor output on a Linux powered computer. The usb port is here /dev/ttyUSB0 instead of the familiar COMXX port on a Windows powered system

GY-21P: connectivity with an ESP8266 microcontroller board
ESP8266 microcontroller boards are popular because they have wifi on board; they offer also much more working memory than Arduinos while they are programmable via the Arduino IDE interface. Notably the wifi feature makes these boards very useful for application in an outdoor weather station with small form factor. Shown in figure 3 is the wiring of a GY-21P to a Lua NodeMCU board. SCL and SDA are wired to pins D2 and D1, respectively. VIN is connected to 3.3 V. Pull-up resistors are 4.7 kΩ.

Figure 3: Wiring scheme of a GY-21P and a Lua NodeMCU ESP8266. VIN is connected to the 3.3V pin of the NodeMCU, GND to GND, SCL to pin D1 and SDA to pin D2. Pull-up resistors for SCL and SDA are compulsory.

Sketch

Sketch name: GY-21P_bare_serial_monitor.ino (zip-ped)

This sketch runs without adaptation both on an Arduino and on a Lua NodeMCU or similar ESP8266 microcontroller board.