├── LICENSE ├── README.md ├── dev └── ZE03_single.ino ├── examples ├── WinsenZE03Example │ └── WinsenZE03Example.ino ├── WinsenZE03_active_mode │ └── WinsenZE03_active_mode.ino └── WinsenZE03_triple_example │ └── WinsenZE03_triple_example.ino ├── library.properties └── src ├── WinsenZE03.cpp └── WinsenZE03.h /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Fabian Gutierrez (fabiangutierrez.co) 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # winsen-ze03-arduino-library 2 | 3 | > Library to use Winston ZE03 sensor series. 4 | 5 | ## Installation 6 | 7 | 1) [Download The .zip file](https://github.com/fega/winsen-ze03-arduino-library/archive/master.zip) 8 | 9 | 2) Import it. 10 | ![Image importing an Arduino library](https://www.arduino.cc/en/uploads/Guide/ImportLibraryFromZIPFile.png) 11 | 12 | ## Usage 13 | 14 | The library includes two modes: an active mode and a Question and answer mode. 15 | 16 | ### Question and Answer mode 17 | To use the question an answer mode (for an Arduino MEGA): 18 | ```cpp 19 | #include 20 | 21 | WinsenZE03 sensor; 22 | 23 | void setup() { 24 | Serial3.begin(9600); // Initialize the Serial port 25 | sensor.begin(&Serial3, CO); // Init the sensor, don't forget the "&" 26 | 27 | sensor.setAs(QA); // use ACTIVE, for the active mode 28 | Serial.begin(9600); 29 | } 30 | void loop() { 31 | float ppm = sensor.readManual(); //Read the sensor 32 | Serial.println(ppm); 33 | } 34 | ``` 35 | ## API 36 | ### WinsenZE03.begin(&Serial, type) 37 | Initialize the sensor to listen the Serial provided, the following types are supported: 38 | 39 | CO, 40 | SO2, 41 | NO2, 42 | O2, 43 | NH3, 44 | H2S, 45 | HF, 46 | CL2 and 47 | O3 48 | ### WinsenZE03.setAs(ACTIVE || QA) 49 | Sets the sensor to Active `.setAs(ACTIVE)` or Question and Answer mode `.setAs(QA)` 50 | ### WinsenZE03.readManual() 51 | Reads the sensor in QA mode and returns a Float with the result, if the read process suffers a problem, it returns -1 52 | 53 | ### WinsenZE03.readContinuous() 54 | Reads the sensor in active mode and returns a Float with the result if Serial data is available, if the read process suffers a problem, it returns -1 55 | 56 | ## License 57 | 58 | MIT © [Fabian Enrique Gutierrez](fabiangutierrez.co) 59 | -------------------------------------------------------------------------------- /dev/ZE03_single.ino: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fega/winsen-ze03-arduino-library/b5c4701283e8ddbedc0b44e86f5829c8033df714/dev/ZE03_single.ino -------------------------------------------------------------------------------- /examples/WinsenZE03Example/WinsenZE03Example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WinsenZE03.h - This library allows you to set and read the ZE03 Winsen Sensor module. 3 | More information: https://github.com/fega/winsen-ze03-arduino-library 4 | Created by Fabian Gutierrez , March 17, 2017. 5 | MIT. 6 | */ 7 | 8 | #include 9 | 10 | WinsenZE03 sensor; 11 | 12 | 13 | void setup() { 14 | Serial3.begin(9600); 15 | Serial.begin(9600); 16 | sensor.begin(&Serial3, CO); 17 | sensor.setAs(QA); 18 | } 19 | void loop() { 20 | float ppm = sensor.readManual(); 21 | Serial.println(ppm); 22 | } 23 | -------------------------------------------------------------------------------- /examples/WinsenZE03_active_mode/WinsenZE03_active_mode.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WinsenZE03.h - This library allows you to set and read the ZE03 Winsen Sensor module. 3 | More information: https://github.com/fega/winsen-ze03-arduino-library 4 | Created by Fabian Gutierrez , March 17, 2017. 5 | MIT. 6 | */ 7 | 8 | #include 9 | 10 | WinsenZE03 sensor; 11 | 12 | void setup() { 13 | sensor.begin(&Serial3, CO); 14 | Serial3.begin(9600); 15 | sensor.setAs(ACTIVE); 16 | Serial.begin(9600); 17 | 18 | } 19 | void loop() { 20 | float ppm = sensor.readContinuous(); 21 | Serial.println(ppm); 22 | } 23 | -------------------------------------------------------------------------------- /examples/WinsenZE03_triple_example/WinsenZE03_triple_example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WinsenZE03.h - This library allows you to set and read the ZE03 Winsen Sensor module. 3 | More information: https://github.com/fega/winsen-ze03-arduino-library 4 | Created by Fabian Gutierrez , Apr 3, 2017. 5 | MIT. 6 | */ 7 | 8 | #include 9 | 10 | WinsenZE03 sensor1; 11 | WinsenZE03 sensor2; 12 | WinsenZE03 sensor3; 13 | 14 | 15 | void setup() { 16 | Serial1.begin(9600); 17 | Serial2.begin(9600); 18 | Serial3.begin(9600); 19 | Serial.begin(9600); 20 | 21 | sensor1.begin(&Serial1, SO2); 22 | sensor2.begin(&Serial2, NO2); 23 | sensor3.begin(&Serial3, CO); 24 | 25 | sensor1.setAs(QA); 26 | sensor2.setAs(QA); 27 | sensor3.setAs(QA); 28 | } 29 | void loop() { 30 | float ppm = sensor1.readManual(); 31 | Serial.println(ppm); 32 | ppm = sensor2.readManual(); 33 | Serial.println(ppm); 34 | ppm = sensor3.readManual(); 35 | Serial.println(ppm); 36 | Serial.println("---"); 37 | } 38 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Winsen ZE03 sensor series 2 | version=0.1.0 3 | author=Fabian Gutierrez (fega) 4 | maintainer=Fabian Gutierrez 5 | sentence=The ZE03 are module sensor for air pollutants. 6 | paragraph=This library allows you to set and read the ZE03 module. 7 | category=Sensors 8 | url=https://github.com/fega/winsen-ze03-arduino-library 9 | architectures=* 10 | includes=WinsenZE03.h 11 | -------------------------------------------------------------------------------- /src/WinsenZE03.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | WinsenZE03.h - This library allows you to set and read the ZE03 Winsen Sensor module. 3 | Created by Fabian Gutierrez, March 12, 20017. 4 | MIT. 5 | */ 6 | 7 | #include "Arduino.h" 8 | #include "WinsenZE03.h" 9 | #define DEVMODE true //Set as true to debug 10 | 11 | WinsenZE03::WinsenZE03(){ 12 | _s = NULL; 13 | } 14 | 15 | void WinsenZE03::begin(Stream *ser, int type){ 16 | _s = ser; 17 | _type=type; 18 | } 19 | 20 | void WinsenZE03::setAs(bool active){ 21 | byte setConfig[] = {0xFF, 0x01, 0x78, 0x04, 0x00, 0x00, 0x00, 0x00, 0x83};//QA config 22 | byte response[9] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 23 | 24 | if (active){ 25 | setConfig[3] =0x03; 26 | setConfig[8] =0x84; 27 | } 28 | _s->write(setConfig,sizeof(setConfig)); 29 | // Wait for the response 30 | delay(2000); 31 | //Flush the incomming buffer 32 | if (_s->available() > 0) { 33 | _s->readBytes(response,9); 34 | } 35 | while(_s->available()>0){ 36 | byte c = _s->read(); 37 | } 38 | } 39 | 40 | float WinsenZE03::readContinuous(){ 41 | if (_s->available() > 0) { 42 | byte measure[8]; 43 | _s->readBytes(measure,9); 44 | // incomingByte = _s.read(); 45 | float ppm = measure[2]*256+measure[3]; 46 | return ppm; 47 | } 48 | } 49 | 50 | float WinsenZE03::readManual(){ 51 | float ppm; 52 | byte petition[] = {0xFF,0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};// Petition to get a single result 53 | byte measure[8]={0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};// Space for the response 54 | _s->write(petition,sizeof(petition)); 55 | delay(1500); 56 | // read 57 | if (_s->available() > 0) { 58 | _s->readBytes(measure,9); 59 | } 60 | // calculate 61 | if (measure[0]==0xff && measure[1]==0x86){ 62 | ppm = measure[2]*256+measure[3];// this formula depends of the sensor is in the dataSheet 63 | if (_type == 2){ 64 | ppm = ppm*0.1; 65 | } 66 | }else{ 67 | ppm=-1; 68 | } 69 | return ppm; 70 | } 71 | 72 | void WinsenZE03::debugPrint(byte arr[]){ 73 | Serial.print(arr[0],HEX);Serial.print(" "); 74 | Serial.print(arr[1],HEX);Serial.print(" "); 75 | Serial.print(arr[2],HEX);Serial.print(" "); 76 | Serial.print(arr[3],HEX);Serial.print(" "); 77 | Serial.print(arr[4],HEX);Serial.print(" "); 78 | Serial.print(arr[5],HEX);Serial.print(" "); 79 | Serial.print(arr[6],HEX);Serial.print(" "); 80 | Serial.print(arr[7],HEX);Serial.print(" "); 81 | Serial.println(arr[8],HEX); 82 | } 83 | -------------------------------------------------------------------------------- /src/WinsenZE03.h: -------------------------------------------------------------------------------- 1 | /* 2 | Morse.h - This library allows you to set and read the ZE03 Winsen Sensor module. 3 | Created by Fabian Gutierrez, March 12, 20017. 4 | MIT. 5 | */ 6 | 7 | #ifndef WinsenZE03_h 8 | #define WinsenZE03_h 9 | 10 | #include "Arduino.h" 11 | #define CO 1 12 | #define SO2 2 13 | #define NO2 2 14 | #define O2 2 15 | #define NH3 1 16 | #define H2S 1 17 | #define HF 1 18 | #define CL2 2 19 | #define O3 2 20 | 21 | #define QA false 22 | #define ACTIVE true 23 | 24 | class WinsenZE03 25 | { 26 | public: 27 | WinsenZE03(); 28 | void begin(Stream *ser, int type); 29 | void setAs(bool active); 30 | float readManual(); 31 | float readContinuous(); 32 | private: 33 | void debugPrint(byte arr[]); 34 | Stream *_s; //Serial1 - Serial3 are USARTClass objects. 35 | int _type; 36 | }; 37 | 38 | #endif 39 | --------------------------------------------------------------------------------