Arduino Projects

SGP30 Sensor with Arduino, eCO2 Sensor, Sensirion SGP30 Gas Sensor

SGP30 Sensor with Arduino:

SGP30 Sensor with Arduino, eCO2 Sensor, Sensirion SGP30 Gas Sensor- In this tutorial, you will learn how to use the SGP30 air quality sensor to display TVOC total volatile organic compounds and carbon dioxide equivalents (e) on the OLED display module. The SGP30 is a multiple gas and environmental sensor from the Adafruit. As in the previous projects we have already used environmental sensors like the MQ135 and DHT11 sensors; to measure the ammonia gas, temperature and humidity. This is another environmental sensor in which will measure some additional things like carbon dioxide and volatile organic compounds.


SGP30 sensor description:

The SGP30 sensor measures two different types of gases: volatile organic compounds (like hydrocarbons) and equivalent carbon dioxide.  This is a very fine air quality sensor made by the Sensirion to measure equivalent carbon dioxide and volatile organic compounds. It has I2C interfacing and fully calibrated output signals with a typical accuracy of 15% within measured values. If you are worried about the air quality or volatile organic compounds like benzene are getting in your house which can be dangerous to your health. Then the SGP30 is best sensor to monitor it. The SGP30 combines multiple metal-oxide sensing elements on one chip to provide more detailed air quality signals. This is a gas sensor that can detect a wide range of Volatile Organic Compounds (VOCs),  and is intended for indoor air quality monitoring. When connected to your microcontroller (running our library code) it will return a Total Volatile Organic Compound (TVOC) reading and an equivalent carbon dioxide reading (eCO2) over I2C.

SGP30 SENSOR



Carbon dioxide Equivalents:

When we are calculating the warming effect of the specific batch of gas we expressed the results in the unit carbon dioxide equivalents. As the gas warming effect is measured against the carbon dioxide therefore it is known as carbon dioxide equivalents. This enables us to compare different gases. In order to calculate warming effect of a gas we use the formula:

Where GWP is global warming potential for example if we are comparing the warming effect of 100 tonnes of methane and 10 tonnes of nitrous oxide so will perform the following calculations:

Methane:

Methane has global warming potential of 25 so by putting the values we will get:

Nitrous oxide:

For nitrous oxide the global warming potential is 298 so by putting the values we will get:

Now from the above calculation, we can conclude that 10 tonnes of nitrous oxide can produce more warming then 100 tonnes of methane. So this comparison is possible due to   equivalents which are standard unit of reference.

Volatile Organic compounds:

The volatile organic compounds are gases that are released in the air from various process and products. These gases can be dangerous to our health and can cause cancer. It can be found in both indoor and outdoor sources. In indoor sources it can be present in adhesives, paints, varnishes, air fresheners, cosmetics, fuel oil and in pressed wooden products etc. While in outdoor source it is present in wood burning, petroleum emissions and in industrial emissions etc. The excess of the Volatile organic compound can cause irritation to our eyes and can cause difficulty in breathing. We can prevent ourselves from these gases with a proper ventilation system.


Working of the SGP30 sensor:

The SGP30 has a ‘standard’ hot-plate MOX sensor, as well as a small microcontroller that controls power to the plate, reads the analog voltage, tracks the baseline calibration, calculates TVOC and eCO2 values, and provides an I2C interface. Unlike the CCS811, this sensor does not require I2C clock stretching. This sensor measures eCO2 (equivalent calculated carbon-dioxide) concentration within a range of 0 to 60,000 parts per million (ppm), and TVOC (Total Volatile Organic Compound) concentration within a range of 0 to 60,000 parts per billion (ppb). The SGP30 does have built in calibration capabilities, note that eCO2 is calculated based on Hydrogen concentration, it is not a ‘true’ CO2 sensor for laboratory use. Another nice element to this sensor is the ability to set humidity compensation for better accuracy. An external humidity sensor is required and then the RH% is written over I2C to the sensor, so it can better calculate the TVOC/eCO2 values.

Power Pins:

  • Vin – this is the power pin. Since the sensor chip uses 3V DC for logic, it consists of a voltage regulator on board that will take 3-5V DC and safely convert it down.
  • 1V8 – this is the 1.8V output from the voltage regulator
  • GND – common ground for power and logic

Data Pins

  • SCL – I2C clock pin, connect to your microcontrollers I2C clock line. Can use 3V

or 5V logic, and has a 10K pullup to Vin

  • SDA – I2C data pin, connect to your microcontrollers I2C data line. Can use 3V or

5V logic, and has a 10K pullup to Vin


Amazon Links:

Arduino

Gas Sensor SGP30

SSD1306 Oled display Module

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Circuit diagram for SGP30 Quality sensor with Arduino nano:

In order to connect the SGP30 sensor with Arduino we will make the following connections:

  • Connect the 3V of the Arduino Nano with the Vin of the SGP30
  • Connect the ground of the Arduino Nano with the ground of the SGP30
  • Connect the SDA pin of the SGP30 with the A4 of the Arduino Nano
  • Connect the SCL pin of the SGP30 with the A5 of the Arduino Nano

As we are display the data on the OLED so we will make the following connections:

  • Connect the VCC of the OLED with 3V of the Arduino Nano
  • Connect the Ground of the OLED with ground of the Arduino Nano
  • Connect the SDA pin of the OLED with A4 pin of the Arduino Nano
  • Connect the SCL pin of the OLED with A5 pin of the Arduino Nano

SGP30 SENSOR


Required library for SGP30 Sensor:

Now in order to install the library, first, we will open the library manager and install Adafruit SGP30 Sensor library.

SGP30 SENSOR

After installing the library we will open the SGP30test example

SGP30 SENSOR

I made several changes in order to be able to display the values on the Oled display module.



SGP30 Sensor Arduino code:

#include <Wire.h>
#include "Adafruit_SGP30.h"
#include "Adafruit_MQTT_Client.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SGP30 sgp;

/* return absolute humidity [mg/m^3] with approximation formula
* @param temperature [°C]
* @param humidity [%RH]
*/
uint32_t getAbsoluteHumidity(float temperature, float humidity) {
    // approximation formula from Sensirion SGP30 Driver Integration chapter 3.15
    const float absoluteHumidity = 216.7f * ((humidity / 100.0f) * 6.112f * exp((17.62f * temperature) / (243.12f + temperature)) / (273.15f + temperature)); // [g/m^3]
    const uint32_t absoluteHumidityScaled = static_cast<uint32_t>(1000.0f * absoluteHumidity); // [mg/m^3]
    return absoluteHumidityScaled;
}

void setup() {
  Serial.begin(115200);
  while (!Serial) { delay(10); } // Wait for serial console to open!
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  delay(2000);
  display.clearDisplay();
  display.setTextColor(WHITE);
  Serial.println("SGP30 test");

  if (! sgp.begin()){
    Serial.println("Sensor not found :(");
    while (1);
  }
  Serial.print("Found SGP30 serial #");
  Serial.print(sgp.serialnumber[0], HEX);
  Serial.print(sgp.serialnumber[1], HEX);
  Serial.println(sgp.serialnumber[2], HEX);

  // If you have a baseline measurement from before you can assign it to start, to 'self-calibrate'
  //sgp.setIAQBaseline(0x8E68, 0x8F41);  // Will vary for each sensor!
}

int counter = 0;
void loop() {
  // If you have a temperature / humidity sensor, you can set the absolute humidity to enable the humditiy compensation for the air quality signals
  //float temperature = 22.1; // [°C]
  //float humidity = 45.2; // [%RH]
  //sgp.setHumidity(getAbsoluteHumidity(temperature, humidity));

  if (! sgp.IAQmeasure()) {
    Serial.println("Measurement failed");
    return;
  }
  Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
  Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");

  if (! sgp.IAQmeasureRaw()) {
    Serial.println("Raw Measurement failed");
    return;
  }
  Serial.print("Raw H2 "); Serial.print(sgp.rawH2); Serial.print(" \t");
  Serial.print("Raw Ethanol "); Serial.print(sgp.rawEthanol); Serial.println("");
 
  delay(1000);

  counter++;
  if (counter == 30) {
    counter = 0;

    uint16_t TVOC_base, eCO2_base;
    if (! sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) {
      Serial.println("Failed to get baseline readings");
      return;
    }
    Serial.print("****Baseline values: eCO2: 0x"); Serial.print(eCO2_base, HEX);
    Serial.print(" & TVOC: 0x"); Serial.println(TVOC_base, HEX);
  }
  display.clearDisplay();
     display.setTextSize(2);
  display.setCursor(0, 10);
  display.print("TVOC:");
   display.print(sgp.TVOC);
  display.setTextSize(1);
   display.print("ppb");
    display.setTextSize(2);
  display.setCursor(0, 30);
 display.print("CO2:"); 
    display.print( sgp.eCO2);
 display.setTextSize(1);
   display.print("ppm");
   display.display();
}

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

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

Back to top button