├── library.properties ├── README.md ├── keywords.txt ├── examples └── AirQuality_Sensor │ └── AirQuality_Sensor.ino ├── license.txt ├── AirQuality.h └── AirQuality.cpp /library.properties: -------------------------------------------------------------------------------- 1 | name=ATmega32U4 Grove Air quality sensor 2 | version=0.0.1 3 | author=Joachim Cardoen 4 | maintainer=Diff Digital 5 | sentence=ATmega32U4 Arduino library to read values from Grove Air Quality Sensor. 6 | paragraph=ATmega32U4 Arduino library to read values from Grove Air Quality Sensor. 7 | category=Sensors 8 | url=https://github.com/JCardoen/ATmega32U4-Grove-Air-quality-sensor 9 | architectures=avr 10 | includes=AirQuality.h 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## AirQuality Industrial Ported library v0.0.1 2 | ### Sensor 3 | 4 | This sensor is designed for comprehensive monitoring of indoor air conditions. 5 | It's responsive to a wide scope of harmful gases such as carbon monoxide, alcohol, acetone, thinner, formaldehyde and so on. 6 | Due to the measuring mechanism, this sensor can not output specific data to describe target gases' concentrations quantitatively. 7 | But it's still competent enough to be used in applications that require only qualitative results, like auto refresher sprayers and auto air cycling systems. 8 | 9 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | 2 | ####################################### 3 | # Syntax Coloring Map For 4 | ####################################### 5 | 6 | ####################################### 7 | # Datatypes (KEYWORD1) 8 | ####################################### 9 | i KEYWORD1 10 | vol_standard KEYWORD1 11 | init_voltage KEYWORD1 12 | first_vol KEYWORD1 13 | last_vol KEYWORD1 14 | temp KEYWORD1 15 | counter KEYWORD1 16 | timer_index KEYWORD1 17 | error KEYWORD1 18 | 19 | 20 | ####################################### 21 | # Methods and Functions (KEYWORD2) 22 | ####################################### 23 | init KEYWORD2 24 | slope KEYWORD2 25 | 26 | ####################################### 27 | # Constants (LITERAL1) 28 | ####################################### -------------------------------------------------------------------------------- /examples/AirQuality_Sensor/AirQuality_Sensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ATmega32U4 AirQuality Example v0.0.1 3 | * By: https://github.com/JCardoen 4 | */ 5 | #include"AirQuality.h" 6 | #include"Arduino.h" 7 | AirQuality airqualitysensor; 8 | int current_quality =-1; 9 | void setup() 10 | { 11 | Serial.begin(9600); 12 | airqualitysensor.init(A0); 13 | } 14 | void loop() 15 | { 16 | current_quality=airqualitysensor.slope(); 17 | if (current_quality >= 0) 18 | { 19 | if (current_quality==0) 20 | Serial.println("High pollution! Force signal active"); 21 | else if (current_quality==1) 22 | Serial.println("High pollution!"); 23 | else if (current_quality==2) 24 | Serial.println("Low pollution!"); 25 | else if (current_quality ==3) 26 | Serial.println("Fresh air"); 27 | } 28 | } 29 | 30 | ISR(TIMER1_OVF_vect) 31 | { 32 | TCNT1 = 34286; 33 | airqualitysensor.last_vol = airqualitysensor.first_vol; 34 | airqualitysensor.first_vol = analogRead(A0); 35 | airqualitysensor.counter = 0; 36 | airqualitysensor.timer_index = 1; 37 | PORTB = PORTB ^ 0x20; 38 | } 39 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Diff Digital. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /AirQuality.h: -------------------------------------------------------------------------------- 1 | /* 2 | Original Copyright owner: 2010 Copyright (c) Seeed Technology Inc. All right reserved. 3 | Original Author: Bruce.Qin 4 | 5 | AirQuality Industrial Ported library v0.0.1 6 | Editor Copyright owner: 2018 Copyright (c) Diff Digital. All right reserved. 7 | Edit Author: Joachim.Cardoen 8 | */ 9 | #ifndef __AIRQUALITY_H__ 10 | #define __AIRQUALITY_H__ 11 | #include"Arduino.h" 12 | class AirQuality 13 | { 14 | public: 15 | int i ; 16 | long vol_standard; 17 | int init_voltage; 18 | int first_vol; 19 | int last_vol; 20 | long temp; 21 | int counter; 22 | boolean timer_index; 23 | boolean error; 24 | void init(int pin); 25 | int slope(void); 26 | private: 27 | int _pin; 28 | }; 29 | #endif 30 | 31 | /* 32 | 33 | LICENSE INFORMATION: 34 | This library is free software; you can redistribute it and/or 35 | modify it under the terms of the GNU Lesser General Public 36 | License as published by the Free Software Foundation; either 37 | version 2.1 of the License, or (at your option) any later version. 38 | 39 | This library is distributed in the hope that it will be useful, 40 | but WITHOUT ANY WARRANTY; without even the implied warranty of 41 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 42 | Lesser General Public License for more details. 43 | 44 | You should have received a copy of the GNU Lesser General Public 45 | License along with this library; if not, write to the Free Software 46 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 47 | */ 48 | 49 | -------------------------------------------------------------------------------- /AirQuality.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Original Copyright owner: 2010 Copyright (c) Seeed Technology Inc. All right reserved. 3 | Original Author: Bruce.Qin 4 | 5 | AirQuality Industrial Ported library v0.0.1 6 | Editor Copyright owner: 2018 Copyright (c) Diff Digital. All right reserved. 7 | Edit Author: Joachim.Cardoen 8 | */ 9 | #include"Arduino.h" 10 | #include"AirQuality.h" 11 | 12 | void AirQuality::init(int pin) 13 | { 14 | _pin=pin; 15 | pinMode(_pin,INPUT); 16 | unsigned char i=0; 17 | Serial.println("sys_starting..."); 18 | delay(20000);//200000 19 | init_voltage=analogRead(_pin); 20 | Serial.println("The init voltage is ..."); 21 | Serial.println(init_voltage); 22 | while(init_voltage) 23 | { 24 | if(init_voltage<798 && init_voltage>10)// the init voltage is ok 25 | { 26 | first_vol=analogRead(_pin);//initialize first value 27 | last_vol=first_vol; 28 | vol_standard=last_vol; 29 | Serial.println("Sensor ready."); 30 | error=false;; 31 | break; 32 | } 33 | else if(init_voltage>798||init_voltage<=10) 34 | { 35 | i++; 36 | delay(60000);//60000 37 | Serial.println("waitting sensor init.."); 38 | init_voltage=analogRead(_pin); 39 | if(i==5) 40 | { 41 | i=0; 42 | error=true; 43 | Serial.println("Sensor Error!"); 44 | } 45 | } 46 | else 47 | break; 48 | } 49 | // initialize timer1 for the ATmega32U4 50 | noInterrupts(); // disable all interrupts 51 | TCCR1A = 0; 52 | TCCR1B = 0; 53 | TCNT1 = 34286; // preload timer 65536-16MHz/256/2Hz 54 | TCCR1B |= (1 << CS12); // 256 prescaler 55 | interrupts(); // enable all interrupts 56 | TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt 57 | Serial.println("Test begin..."); 58 | sei(); 59 | } 60 | int AirQuality::slope(void) 61 | { 62 | while(timer_index) 63 | { 64 | if(first_vol-last_vol>400||first_vol>700) 65 | { 66 | timer_index=0; 67 | return 0; 68 | } 69 | else if((first_vol-last_vol>400&&first_vol<700)||first_vol-vol_standard>150) 70 | { 71 | timer_index=0; 72 | return 1; 73 | 74 | } 75 | else if((first_vol-last_vol>200&&first_vol<700)||first_vol-vol_standard>50) 76 | { 77 | timer_index=0; 78 | return 2; 79 | } 80 | else 81 | { 82 | timer_index=0; 83 | return 3; 84 | } 85 | } 86 | return -1; 87 | } 88 | 89 | /* 90 | 91 | LICENSE INFORMATION: 92 | This library is free software; you can redistribute it and/or 93 | modify it under the terms of the GNU Lesser General Public 94 | License as published by the Free Software Foundation; either 95 | version 2.1 of the License, or (at your option) any later version. 96 | 97 | This library is distributed in the hope that it will be useful, 98 | but WITHOUT ANY WARRANTY; without even the implied warranty of 99 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 100 | Lesser General Public License for more details. 101 | 102 | You should have received a copy of the GNU Lesser General Public 103 | License along with this library; if not, write to the Free Software 104 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 105 | */ 106 | 107 | --------------------------------------------------------------------------------