├── README.md ├── library.properties ├── examples ├── AGS10_calibrate_factory │ └── AGS10_calibrate_factory.ino ├── AGS10_readTVOC_basic │ └── AGS10_readTVOC_basic.ino ├── AGS10_readConfig │ └── AGS10_readConfig.ino └── AGS10_calibrate_custom │ └── AGS10_calibrate_custom.ino ├── AGS10.h └── AGS10.cpp /README.md: -------------------------------------------------------------------------------- 1 | # AGS10_sensor 2 | 3 | This library allows you to read the TVOC (total volatile organic compounds) data in ppb as well as read and set current sensor resistance in 0.1 kΩ. 4 | 5 | See the exmaples folder for how to use the library. (more/better ones coming soon) 6 | 7 | Confirmed working with Arduino will check ESP32 soon. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=AGS10 2 | version=1.0.2 3 | author=JohnGermann 4 | maintainer=JohnGermann 5 | sentence=A library for the AGS10 sensor 6 | paragraph=allows reading TVOC, Version, and Current Resistance as well as set the Slave Address and Sensor Zero Point. 7 | category=Sensors 8 | url=https://github.com/gina-seth/AGS10_sensor 9 | architectures=* 10 | includes=AGS10.h, AGS10.cpp 11 | -------------------------------------------------------------------------------- /examples/AGS10_calibrate_factory/AGS10_calibrate_factory.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // declare sensor 6 | AGS10 sensor = AGS10(); 7 | 8 | 9 | void setup() { 10 | // begin a serial monitor 11 | Serial.begin(9600); 12 | 13 | // initialize sensor 14 | sensor.begin(); 15 | 16 | // calibrate the sensor to factory resistance 17 | sensor.calibrateFact(); 18 | 19 | } 20 | 21 | void loop() { 22 | // the code only needs to run once 23 | 24 | } 25 | -------------------------------------------------------------------------------- /examples/AGS10_readTVOC_basic/AGS10_readTVOC_basic.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // declare sensor 6 | AGS10 sensor = AGS10(); 7 | 8 | // declare data variable 9 | int tvoc; 10 | 11 | void setup() { 12 | // begin a serial monitor 13 | Serial.begin(9600); 14 | 15 | // initialize sensor 16 | sensor.begin(); 17 | 18 | 19 | } 20 | 21 | void loop() { 22 | // read TVOC sensor data every 1.6 seconds, according to datasheet max speed is 1.5 seconds/reading 23 | tvoc = sensor.readTVOC(); 24 | Serial.println(tvoc); 25 | delay(1600); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /examples/AGS10_readConfig/AGS10_readConfig.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // declare sensor 6 | AGS10 sensor = AGS10(); 7 | 8 | // declare data variables 9 | int version, resist; 10 | 11 | void setup() { 12 | // begin a serial monitor 13 | Serial.begin(9600); 14 | 15 | // initialize sensor 16 | sensor.begin(); 17 | 18 | version = sensor.readVersion(); 19 | resist = sensor.readResist(); 20 | 21 | Serial.println("----------------------------------"); 22 | Serial.print("Firmware version: "); 23 | Serial.println(version); 24 | Serial.println("----------------------------------"); 25 | Serial.print("Current Resistance (0.1kR): "); 26 | Serial.println(resist); 27 | Serial.println("----------------------------------"); 28 | } 29 | 30 | void loop() { 31 | // this code only needs to run once 32 | 33 | } 34 | -------------------------------------------------------------------------------- /examples/AGS10_calibrate_custom/AGS10_calibrate_custom.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // declare sensor 6 | AGS10 sensor = AGS10(); 7 | 8 | // declare calibration variables 9 | uint8_t calib_CMD1 = 0xFF; 10 | uint8_t calib_CMD2 = 0xFF; 11 | 12 | void setup() { 13 | // begin a serial monitor 14 | Serial.begin(9600); 15 | 16 | // initialize sensor 17 | sensor.begin(); 18 | 19 | /* calibrate the sensor 20 | 21 | this function works like such: 22 | xxx.calibrateCust(ResistanceByte1, ResistanceByte2); 23 | 24 | the two values are the bytes that will make up the resistanace that you will 25 | set for the sensor. see the AGS10 datasheet for more info about these values: 26 | http://www.aosong.com/en/products-86.html 27 | 28 | in the future, i may just add the math and such into the library, until then... 29 | */ 30 | sensor.calibrateCust(calib_CMD1,calib_CMD2); 31 | 32 | } 33 | 34 | void loop() { 35 | // the code only needs to run once 36 | 37 | } 38 | -------------------------------------------------------------------------------- /AGS10.h: -------------------------------------------------------------------------------- 1 | // AGS10.h 2 | 3 | // This is a library for the AGS10 sensor // It measures the total volatile organic compounds (TVOC) in the air // The sensor uses I2C communication protocol 4 | 5 | #ifndef AGS10_H 6 | #define AGS10_H 7 | 8 | #include 9 | #include 10 | 11 | // Define the I2C address of the sensor 12 | #define AGS10_ADDR 0x1A 13 | 14 | // Define the register addresses 15 | #define TVOC_REG 0x00 16 | #define VERS_REG 0x11 17 | #define RESIST_REG 0x20 18 | #define CALIB_REG 0x01 19 | #define SLAVE_REG 0x21 20 | 21 | // Define the calibration commands 22 | #define CALIB_CMD1 0x00 23 | #define CALIB_CMD2 0x0C 24 | #define CALIB_FACT 0xFF 25 | #define CALIB_ZERO 0x00 26 | 27 | class AGS10 { 28 | 29 | public: 30 | 31 | AGS10(); // Constructor 32 | void begin(); // Initialize the sensor 33 | void calibrateFact(); // Calibrate the sensor 34 | void calibrateCust(uint8_t CALIB_RES1, uint8_t CALIB_RES2); // Calibrate the sensor using a custom resistance value (measured in 0.1kΩ) 35 | void setAddress(uint8_t newAddr); // Set the sensor's i2c addr to have more than one sensor on the same bus 36 | int readResist(); // Read the current resistance of the sensor in 0.1 kO 37 | int readVersion(); // Read the sensor's current firmware version 38 | int readTVOC(); // Read the TVOC value in ppb 39 | uint8_t Calc_CRC8(uint8_t *dat, uint8_t Num); 40 | 41 | 42 | private: 43 | 44 | int _tvoc; // Variable to store the TVOC value 45 | int _version; // Variable to store the version value 46 | int _resist; // Variable to store the resistance value 47 | int _status; // Variable to store the status of the sensor [INACTIVE] 48 | byte _crc; 49 | 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /AGS10.cpp: -------------------------------------------------------------------------------- 1 | // AGS10.cpp 2 | 3 | #include "AGS10.h" 4 | 5 | 6 | uint8_t AGS10::Calc_CRC8(uint8_t *dat, uint8_t Num) 7 | { 8 | uint8_t i,byte1,crc=0xFF; 9 | for(byte1=0; byte1