Your shopping cart is empty!
What Is The Air Quality Inside Your Room
- Hussien Jawhar Sathik
- 21 Mar 2022
- Tutorial
- 1272
Introduction
In this simple tutorial today, we shall see how to measure the air quality inside your room using the Grove SGP30 sensor
Video
Hardware Preparation
This is the list of items used in the video.
Building The Circuit
- Constructing the circuit is very straight forward since both the sensor and the lcd use the Grove i2C type connection. Hence the circuit can be constructed as shown in the image below
Once the connection are made as per the figure above, we can now start to code.
Code
For the code, i have used the sample code and make few modification to it.
#include
#include "sensirion_common.h"
#include "sgp30.h"
#include
#include "rgb_lcd.h"
rgb_lcd lcd;
void setup() {
s16 err;
u32 ah = 0;
u16 scaled_ethanol_signal, scaled_h2_signal;
Serial.begin(115200);
Serial.println("serial start!!");
lcd.begin(16, 2);
lcd.clear();
delay(1000);
/*For wio link!*/
#if defined(ESP8266)
pinMode(15, OUTPUT);
digitalWrite(15, 1);
Serial.println("Set wio link power!");
delay(500);
#endif
/* Init module,Reset all baseline,The initialization takes up to around 15 seconds, during which
all APIs measuring IAQ(Indoor air quality ) output will not change.Default value is 400(ppm) for co2,0(ppb) for tvoc*/
while (sgp_probe() != STATUS_OK) {
Serial.println("SGP failed");
while (1);
}
/*Read H2 and Ethanol signal in the way of blocking*/
err = sgp_measure_signals_blocking_read(&scaled_ethanol_signal,
&scaled_h2_signal);
if (err == STATUS_OK) {
Serial.println("get ram signal!");
} else {
Serial.println("error reading signals");
}
//ah=get_relative_humidity();
/*
The function sgp_set_absolute_humidity() need your own implementation
*/
//sgp_set_absolute_humidity(ah);
// Set absolute humidity to 13.000 g/m^3
//It's just a test value
sgp_set_absolute_humidity(13000);
err = sgp_iaq_init();
//
}
void loop() {
s16 err = 0;
u16 tvoc_ppb, co2_eq_ppm;
err = sgp_measure_iaq_blocking_read(&tvoc_ppb, &co2_eq_ppm);
if (err == STATUS_OK) {
Serial.print("tVOC Concentration:");
Serial.print(tvoc_ppb);
Serial.println("ppb");
lcd.setCursor(0, 0);
lcd.print("tVOC :");
lcd.setCursor(6, 0);
lcd.print(tvoc_ppb);
lcd.setCursor(9, 0);
lcd.print("ppb");
Serial.print("CO2eq Concentration:");
Serial.print(co2_eq_ppm);
Serial.println("ppm");
lcd.setCursor(0, 1);
lcd.print("CO2eq:");
lcd.setCursor(6, 1);
lcd.print(co2_eq_ppm);
lcd.setCursor(11, 1);
lcd.print("ppm");
} else {
Serial.println("error reading IAQ values\n");
}
delay(1000);
}
Outcome
Thank You
Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.
"Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for a better application."