Advertisement
microrobotics

Adafruit SGP30

Mar 30th, 2023
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*The Adafruit SGP30 is a digital air quality sensor that communicates over I2C. Here's an example code in Arduino that reads the air quality data from the sensor:
  2. Note: This code assumes that the Adafruit SGP30 sensor is connected to the I2C bus of the Arduino board. If you're using a different I2C bus or pins, you'll need to modify the sgp initialization accordingly. Also, the setIAQBaseline() function is called to calibrate the sensor for indoor air quality. If you're using the sensor in a different environment, you may need to adjust the baseline values accordingly.
  3. */
  4.  
  5. #include <Wire.h>
  6. #include "Adafruit_SGP30.h"
  7.  
  8. Adafruit_SGP30 sgp;
  9.  
  10. void setup() {
  11.   Serial.begin(9600);
  12.  
  13.   if (!sgp.begin()) {
  14.     Serial.println("SGP30 not found!");
  15.     while (1);
  16.   }
  17.  
  18.   // calibrate the sensor for indoor air quality
  19.   sgp.setIAQBaseline(0x8E14, 0x8F2E);
  20. }
  21.  
  22. void loop() {
  23.   // read the air quality data from the sensor
  24.   if (!sgp.IAQmeasure()) {
  25.     Serial.println("Measurement failed!");
  26.     return;
  27.   }
  28.  
  29.   // print the air quality data
  30.   Serial.print("eCO2: ");
  31.   Serial.print(sgp.eCO2);
  32.   Serial.print(" ppm\tTVOC: ");
  33.   Serial.print(sgp.TVOC);
  34.   Serial.println(" ppb");
  35.  
  36.   // delay before reading from the sensor again
  37.   delay(1000);
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement