Menu Close

si7021 Temperature & Humidity sensor on ESP8266

Robo India presents tutorial on how to read temperature and humidity data through si7021 sensor using NodeMCU ESP8266 wifi module on Arduino IDE.

1. Introduction:

This tutorial explains how to read temperature and humidity data through si7021 sensor using ESP8266 wifi module on NODEMCU LUA platform.

You need to have basic understanding of ESP8266, below mentioned tutorials of Robo India may help you out in this.

1. This tutorial explains configuration and setup of ESP8266

2. This tutorial explains basic of ESPlorer.

2. Understanding si7021 sensor

Si7021 sensor gives humidity and temperature data.
It has the following pin interface.

3. Circuit

Node MCU AMICA circuit connections :

Connections

NodeMCUSi7021
GPIO5CL
GPIO4DA
VCC3V3
GNDGND

5.Blynk

After you’ve successfully logged into your account, start by creating a new project.
Select the hardware model you will use.
Every new project you create will have its Auth Token. You’ll get Auth Token automatically on your email after project creation.
Paste the Auth code in “char auth[ ]” of below code.
Now add widgets to your project.

In the widget box, you will find the Gauge widget.

This is how you can set widget for temperature.

Widget for Humidity

4. Programming

Run the following code after adding your Auth Token and WiFi credentials.

Adafruit_Si7021 sensor = Adafruit_Si7021();

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "******************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********";
char pass[] = "********";
BlynkTimer timer;
void sendSensor()
{ float h = sensor.readHumidity();
  float t = sensor.readTemperature();
  if (isnan(h) || isnan(t)) 
                {
                     Serial.println("Failed to read from DHT sensor!");
                     return;
                  }
      // You can send any value at any time.
     // Please don't send more that 10 values per second.
      Blynk.virtualWrite(V2,h);
      Blynk.virtualWrite(V1,t);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
  if (!sensor.begin())
  {
    Serial.println("Did not find Si7021 sensor!");
    while (true);
  }
   // Setup a function to be called every second
   timer.setInterval(1000L,sendSensor); 
}

void loop()
{
  Blynk.run();
  timer.run();
}

Temperature and humidity widgets will show the values as follows.

This is how to use si7021 sensor on ESP8266 using LUA.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
http://roboindia.com

Leave a Reply