Indoor Air quality analysis using ESP32 and Bytebeam cloud

people typically spend more than 90% of their time in indoor environments. Monitoring indoor air quality parameters like CO2 plays an important role in a healthy lifestyle.

Indoor air quality (IAQ) monitoring is a very often talked about topic nowadays as it critically affects a person’s health, comfort, and safety.

People who might be at their homes, workplace offices, etc. typically spend more than 90% of their time in indoor environments. So, It is not only directly related to occupational health but also has a significant impact on the quality of life of people.

One of the key indicators of indoor air quality is Carbon dioxide (CO2) and it has a substantial influence on public health. Thus, regular monitoring and Analysis of indoor air quality parameters like CO2 becomes essentially important to regulate occupational health and ensure better working environments

Some of the Factors affecting indoor CO2 levels include:

Keeping in mind all the factors affecting indoor CO2 levels we will be going through a step-by-step guide to creating an IoT solution for CO2, temperature, and Humidity monitoring using ESP32 and Bytebeam Cloud. In this blog we will be demonstrating the following:

So Let’s get started.

Hardware and Software Specifications

Hardware Specification

Software Specification

Setting Up Bytebeam Cloud

Bytebeam is a fully managed cloud platform. Which serves all cloud needs from device management to dashboard, Handling actions, and notification to OTA updates. It provides the following features

If you are new to the Bytebeam IoT cloud platform. Go through the getting started with bytebeam tutorial to dive deep into the concepts of Bytebeam.

I hope you found the getting started guide useful and are aware of the concepts of Bytebeam cloud.

Setting Up ESP32

Hardware connection

Project Setup

git clone
git clone

Provision ESP32 with device config data

Earlier in this guide, we had provisioned a new device in the bytebeam cloud console and downloaded a JSON file. We need to flash this file to SPIFFS to connect our device to the cloud.

Now navigate to the provisioning example and create a new folder config_data inside it. -p PORT flash monitor

Getting CO2 Sensor and temperature and humidity sensor values

#include "ccs811/ccs811.h"
#include "sht31.h"
if (init_ccs811()){
printf("\nNO Initialized\n");
if (sht31_init()) {
printf("Initialised SHT31");
} else {
printf("Could not initialize SHT3x sensor\n");
carbon_json = cJSON_CreateNumber(get_ccs811(0)); 
cJSON_AddItemToObject(device_shadow_json, "carbon", carbon_json);
humid_json = cJSON_CreateNumber(humidity);
cJSON_AddItemToObject(device_shadow_json, "humidity", humid_json);
temperature_json = cJSON_CreateNumber(temperature);
cJSON_AddItemToObject(device_shadow_json, "temperature", temperature_json);

Creating an action handler to control blinds

Increasing levels of CO2 in the workspace can cause laziness and sleepiness. So to regulate the flow of fresh air. We are using a relay to open and close window blinds to improve airflow.

We will trigger this action whenever the CO2 levels cross a particular threshold(1000PPM)

We can create an action handler using these simple steps.

#define BLINK_GPIO 4
static void configure_blinds(void)
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
bytebeam_add_action_handler(&bytebeam_client, toggle_blinds, "toggle_blind");

Flash and Upload -p PORT flash monitor

In the next section, we will add “toggle_blind” actionon the bytebeam cloud.

Adding action on Bytebeam cloud

Triggering an Action

We need to follow these easy steps to trigger an action:

Data Visualization in Bytebeam cloud

Guidelines to Check CO2 levels in a workplace

Escalation of CO2 levels in a workplace can affect your health in different ways. The CO2 levels can differ based on occupancy, ventilation and respiration rate. The increasing level can also cause laziness, sleepiness, dizziness etc.

As we can see in the graph variation in CO2 level as the occupancy and ventilation in the room changes


We are officially launching our ESP-SDK to connect the ESP-32 device to the Bytebeam cloud. ESP-SDK is live on the product hunt. I hope you find this guide useful. We will come up with more interesting tutorials and maker content. Stay tuned.



Full Stack IoT developer working on effective Wireless Sensor Network

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
vaibhav sharma

Full Stack IoT developer working on effective Wireless Sensor Network