I am working on ZE07 CO sensor. I have to interface it with ESP 8266. Kindly suggest some library
GitHub - HarvTech/ZE07_CO_UART_Library. Found this one but unable to install
Hi @vikramjeetagam. Which version of Arduino IDE are you using (e.g., "2.0.1")? The version is shown on the window title bar and also in the dialog that opens when you select Help > About (or Arduino IDE > About Arduino IDE for macOS users) from the Arduino IDE menus.
I ask for this information because I want to give you the appropriate instructions for the IDE version you are using.
Arduino 2.3.2
OK, great. Whenever possible, you should use Arduino IDE's "Library Manager" or "Add .ZIP Library..." features to install libraries as those are the most convenient and reliable methods. Unfortunately it is not possible to use them to install this library since the creator never submitted it for inclusion in Library Manager and the ZIP file download doesn't have the right structure for use with "Add .ZIP Library...". So in this case it is necessary to do a manual installation.
I'll provide instructions you can follow to do that:
- Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
The "Preferences" dialog will open. - Take note of the path shown in the "Sketchbook location" field of the dialog.
- Click the "CANCEL" button.
The "Preferences" dialog will close. - Click the following link to open the library's GitHub repository homepage in your web browser:
https://github.com/HarvTech/ZE07_CO_UART_Library - Click the "Code ▾" button you see on that page.
- Select Download ZIP from the menu.
A download of the ZIP file of the library will start. - Wait for the download to finish.
- Extract the downloaded file.
- Copy the
ZE07_CO_UART_Libraryfolder from the extracted folder to thelibrariessubfolder of the path you saw in the "Sketchbook location" preference.
The folder structure of the installation must look like this:
(where<Sketchbook location>/ ├── libraries/ │ ├── ZE07_CO_UART_Library/ │ │ ├── ZE7_CO.h │ │ ... │ ... ...<Sketchbook location>is the path from the Sketchbook location" preference) - Select File > Quit (or Arduino > Quit Arduino for macOS users) from the Arduino IDE menus.
All Arduino IDE windows will close. - Start Arduino IDE.
After that, you should be able to use the library in your Arduino sketches. You will find some example sketches that demonstrate the usage of the library under the File > Examples > ZE07_CO_UART_Library menu in Arduino IDE.
Tried but in examples this code is not showing
This indicates you made a mistake while following the instructions. Please double check that the folder structure of the library installation matches this diagram exactly:
<Sketchbook location>/
├── libraries/
│ ├── ZE07_CO_UART_Library/
│ │ ├── ZE7_CO.h
│ │ ...
│ ...
...
checked again but example not found. May you check with any desk. I shell be thankful
C:\Users\sahar\OneDrive\Documents\Arduino\libraries\ZE07_CO_UART_Library-main\ZE07_CO_UART_Library\Examples\ZE7_CO_UART_Mode1
You made a mistake at step (9) of my instructions. You were supposed to copy the ZE07_CO_UART_Library subfolder but you instead copied the ZE07_CO_UART_Library-main folder.
This is what your library installation folder structure looks like:
<Sketchbook location>/
├── libraries/
│ ├── ZE07_CO_UART_Library-main/
│ │ ├── LICENSE
│ │ ├── README.md
│ │ └── ZE07_CO_UART_Library/
│ │ ├── ZE7_CO.h
│ │ ...
│ ...
...
This is the correct structure:
<Sketchbook location>/
├── libraries/
│ ├── ZE07_CO_UART_Library/
│ │ ├── ZE7_CO.h
│ │ ...
│ ...
...
Do you see the extra folder level in your installation?
Now example found but compilation error occurred
I'm going to ask you to post the full verbose output from a compilation.
This procedure is not intended to solve the problem. The purpose is to gather more information.
Please do this:
- Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
The "Preferences" dialog will open. - Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
- Click the "OK" button.
- Select Sketch > Verify/Compile from the Arduino IDE menus.
- Wait for the compilation to fail.
- You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
- Open a forum reply here by clicking the "Reply" button.
- Click the
<CODE/>icon on the post composer toolbar.
This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.

- Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
This will paste the compilation output into the code block. - Move the cursor outside of the code block markup before you add any additional text to your reply.
- Click the "Reply" button to post the output.
In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:
- Open any text editor program.
- Paste the copied output into the text editor.
- Save the file in
.txtformat. - Open a forum reply here by clicking the "Reply" button.
- Click the "Upload" icon (
) on the post composer toolbar:

The "Open" dialog will open. - Select the
.txtfile you saved from the "Open" dialog. - Click the "Open" button.
The dialog will close. - Click the "Reply" button to publish the post.
Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.
/*-------------------Desription-----------------------------------------------------------------------------------
*
* This sketch demonstrates the use of ZE07-CO Carbon Monoxide Module Mode 1 UART I/O. In this mode UART data is automatically
* transmitted from the module periodically at one second time intervals. In this example mode 1 UART data is recovered as it
* arrives as indicated by a toggled read_flag state as well as a LED. Recovered CO concentration level in ppm is updated, and
* its value is printed out when read_flag state is toggled. There is also an option to use a board pin as a test point to observe
* read_flag state on an oscilloscope along with UART I/O data signals..
*
* Declaration ZE7_CO ZE7_CO(&COSerial), at line 49, refers the Software Serial port created in line 46 to library file ZE7_CO.h
* included at line 32.
*
* Two function calls are required to retrive concentration levels in Mode 1:
* 1) ZE7_CO.beginMode1(), at line 72 sets Mode 1 UART I/O Mode 1 if it had previously been set to Mode 2.
* 2) ZE7_CO.updateMode1_data(concentration, read_flag), at line 80, continuously recovers Mode 1 data as it arrives,
* updates concentration level, and read_flag state which is toggled after concentration has been updated.
* This function is non-blocking so other uperations may take place withinin the loop. However, it is most important
* that they must also be not block the receptioon of softwre serial data for this function to work.
*
* Be advised that the pin spacing on this device makes it impossible to plug it into a standard
* breadboard with 0.1 inch (2.54mm) spacing. An adaptor PCB that remedies this problem is available
* at https://www.tindie.com/products/ga_mecatronics/pcb-breakout-boards-for-winsen-ze07-co-modules/.
* Close pin spacing does require good soldering skills, and a good soldering iron or soldering
* station.
*
* Created by HarvTech 10/17/2022
*
*/
//-------------------Declarations------------------------------------------------------------------------------------------------
#include <ZE7_CO.h>
#include <SoftwareSerial.h>
//Software serial pins used for board in use.
//For NodeMcu 1.0 ESP-12E Module use:
#define Softserial_RX_pin D5
#define Softserial_TX_Pin D6
//LED pin to be used for indicating UART data reception.
#define LED_Pin D4
//pin to monitor read_flag state on an oscilloscope along with UART I/O signals.
#define read_flag_Pin D1
//Create a Software Serial Port.
SoftwareSerial COSerial(Softserial_RX_pin, Softserial_TX_Pin );
//Reference library use of the Software Serial port.
ZE7_CO ZE7_CO(&COSerial);
//Reference use of a HardwareSerial port, i.e.use of Hardware Serial2.
//ZE7_CO ZE7_CO(&Serial2);
//This should work with boards supporting multiple HardwareSerial ports. It does not work with
//the NodeMcu board due to the following issues.
// 1) I found the ZE07-C0 UART output unable to drive the NodeMCU HardwareSerial
// RX pin directly. It seems unable to sink enough current and a buffer is required.
// 2) The HardwareSerial port selected should not be that used to upload code or receive other serial input.
//-------------------Variables-----------------------------------------------------------------
unsigned long previousMillis = 0;
unsigned long currentMillis;
float concentration = 0; //CO concentration in ppm.
bool read_flag = false; //Toggles when UART data is received
bool last_read_flag;
//---------------------Setup--------------------------------------------------------------------
void setup() {
Serial.begin(9600);
delay(1000);
COSerial.begin(9600);
delay(1000);
pinMode(LED_Pin, OUTPUT);
pinMode(read_flag_Pin, OUTPUT);
//Set UART I/O to Mode1
ZE7_CO.beginMode1();
}
//---------------------Main Loop-----------------------------------------------------------------------------------
void loop() {
//Recover Mode 1 UART data as it arrives, update concentration, and read_flag state.
//Note: read_flag state will toggle after concentration has been updated.
ZE7_CO.updateMode1_data(concentration, read_flag);
//Toggle the state of LED_Pin and read_flag_ Pin when UART data has been recovered
Show_dataready();
//Print updated concentration level.
Print_Concentration();
//---------------------End Main Loop---------------------------------------------------------------------------------
}
//--------------------My Functions--------------------------------------------------------------------------------------
void Show_dataready()
{
if(read_flag)
{
digitalWrite(read_flag_Pin, HIGH);
digitalWrite(LED_Pin, LOW);
}
else
{
digitalWrite(read_flag_Pin, LOW);
digitalWrite(LED_Pin, HIGH);
}
}
void Print_Concentration()
{
if(read_flag != last_read_flag)
{
last_read_flag = read_flag;
//Print data
Serial.println("UARTI/O Mode1 Concentration Level:");
Serial.print(concentration, 1);
Serial.println(" ppm CO");
Serial.println("-------------------------------------");
Serial.println("");
}
}
//-------------------End Sketch---------------------------------------------------------------------------------------
/*-------------------Desription-----------------------------------------------------------------------------------
*
* This sketch demonstrates the use of ZE07-CO Carbon Monoxide Module Mode 1 UART I/O. In this mode UART data is automatically
* transmitted from the module periodically at one second time intervals. In this example mode 1 UART data is recovered as it
* arrives as indicated by a toggled read_flag state as well as a LED. Recovered CO concentration level in ppm is updated, and
* its value is printed out when read_flag state is toggled. There is also an option to use a board pin as a test point to observe
* read_flag state on an oscilloscope along with UART I/O data signals..
*
* Declaration ZE7_CO ZE7_CO(&COSerial), at line 49, refers the Software Serial port created in line 46 to library file ZE7_CO.h
* included at line 32.
*
* Two function calls are required to retrive concentration levels in Mode 1:
* 1) ZE7_CO.beginMode1(), at line 72 sets Mode 1 UART I/O Mode 1 if it had previously been set to Mode 2.
* 2) ZE7_CO.updateMode1_data(concentration, read_flag), at line 80, continuously recovers Mode 1 data as it arrives,
* updates concentration level, and read_flag state which is toggled after concentration has been updated.
* This function is non-blocking so other uperations may take place withinin the loop. However, it is most important
* that they must also be not block the receptioon of softwre serial data for this function to work.
*
* Be advised that the pin spacing on this device makes it impossible to plug it into a standard
* breadboard with 0.1 inch (2.54mm) spacing. An adaptor PCB that remedies this problem is available
* at https://www.tindie.com/products/ga_mecatronics/pcb-breakout-boards-for-winsen-ze07-co-modules/.
* Close pin spacing does require good soldering skills, and a good soldering iron or soldering
* station.
*
* Created by HarvTech 10/17/2022
*
*/
//-------------------Declarations------------------------------------------------------------------------------------------------
#include <ZE7_CO.h>
#include <SoftwareSerial.h>
//Software serial pins used for board in use.
//For NodeMcu 1.0 ESP-12E Module use:
#define Softserial_RX_pin D5
#define Softserial_TX_Pin D6
//LED pin to be used for indicating UART data reception.
#define LED_Pin D4
//pin to monitor read_flag state on an oscilloscope along with UART I/O signals.
#define read_flag_Pin D1
//Create a Software Serial Port.
SoftwareSerial COSerial(Softserial_RX_pin, Softserial_TX_Pin );
//Reference library use of the Software Serial port.
ZE7_CO ZE7_CO(&COSerial);
//Reference use of a HardwareSerial port, i.e.use of Hardware Serial2.
//ZE7_CO ZE7_CO(&Serial2);
//This should work with boards supporting multiple HardwareSerial ports. It does not work with
//the NodeMcu board due to the following issues.
// 1) I found the ZE07-C0 UART output unable to drive the NodeMCU HardwareSerial
// RX pin directly. It seems unable to sink enough current and a buffer is required.
// 2) The HardwareSerial port selected should not be that used to upload code or receive other serial input.
//-------------------Variables-----------------------------------------------------------------
unsigned long previousMillis = 0;
unsigned long currentMillis;
float concentration = 0; //CO concentration in ppm.
bool read_flag = false; //Toggles when UART data is received
bool last_read_flag;
//---------------------Setup--------------------------------------------------------------------
void setup() {
Serial.begin(9600);
delay(1000);
COSerial.begin(9600);
delay(1000);
pinMode(LED_Pin, OUTPUT);
pinMode(read_flag_Pin, OUTPUT);
//Set UART I/O to Mode1
ZE7_CO.beginMode1();
}
//---------------------Main Loop-----------------------------------------------------------------------------------
void loop() {
//Recover Mode 1 UART data as it arrives, update concentration, and read_flag state.
//Note: read_flag state will toggle after concentration has been updated.
ZE7_CO.updateMode1_data(concentration, read_flag);
//Toggle the state of LED_Pin and read_flag_ Pin when UART data has been recovered
Show_dataready();
//Print updated concentration level.
Print_Concentration();
//---------------------End Main Loop---------------------------------------------------------------------------------
}
//--------------------My Functions--------------------------------------------------------------------------------------
void Show_dataready()
{
if(read_flag)
{
digitalWrite(read_flag_Pin, HIGH);
digitalWrite(LED_Pin, LOW);
}
else
{
digitalWrite(read_flag_Pin, LOW);
digitalWrite(LED_Pin, HIGH);
}
}
void Print_Concentration()
{
if(read_flag != last_read_flag)
{
last_read_flag = read_flag;
//Print data
Serial.println("UARTI/O Mode1 Concentration Level:");
Serial.print(concentration, 1);
Serial.println(" ppm CO");
Serial.println("-------------------------------------");
Serial.println("");
}
}
//-------------------End Sketch---------------------------------------------------------------------------------------
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:37:27: error: 'D5' was not declared in this scope
37 | #define Softserial_RX_pin D5
| ^~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:46:25: note: in expansion of macro 'Softserial_RX_pin'
46 | SoftwareSerial COSerial(Softserial_RX_pin, Softserial_TX_Pin );
| ^~~~~~~~~~~~~~~~~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:38:27: error: 'D6' was not declared in this scope
38 | #define Softserial_TX_Pin D6
| ^~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:46:44: note: in expansion of macro 'Softserial_TX_Pin'
46 | SoftwareSerial COSerial(Softserial_RX_pin, Softserial_TX_Pin );
| ^~~~~~~~~~~~~~~~~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino: In function 'void setup()':
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:41:17: error: 'D4' was not declared in this scope
41 | #define LED_Pin D4
| ^~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:78:11: note: in expansion of macro 'LED_Pin'
78 | pinMode(LED_Pin, OUTPUT);
| ^~~~~~~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:43:23: error: 'D1' was not declared in this scope; did you mean 'y1'?
43 | #define read_flag_Pin D1
| ^~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:79:11: note: in expansion of macro 'read_flag_Pin'
79 | pinMode(read_flag_Pin, OUTPUT);
| ^~~~~~~~~~~~~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino: In function 'void Show_dataready()':
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:43:23: error: 'D1' was not declared in this scope; did you mean 'y1'?
43 | #define read_flag_Pin D1
| ^~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:107:18: note: in expansion of macro 'read_flag_Pin'
107 | digitalWrite(read_flag_Pin, HIGH);
| ^~~~~~~~~~~~~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:41:17: error: 'D4' was not declared in this scope
41 | #define LED_Pin D4
| ^~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:108:18: note: in expansion of macro 'LED_Pin'
108 | digitalWrite(LED_Pin, LOW);
| ^~~~~~~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:43:23: error: 'D1' was not declared in this scope; did you mean 'y1'?
43 | #define read_flag_Pin D1
| ^~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:112:18: note: in expansion of macro 'read_flag_Pin'
112 | digitalWrite(read_flag_Pin, LOW);
| ^~~~~~~~~~~~~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:41:17: error: 'D4' was not declared in this scope
41 | #define LED_Pin D4
| ^~
C:\Users\sahar\AppData\Local\Temp\.arduinoIDE-unsaved202428-17148-5h5bof.hp1qe\ZE7_CO_UART_Mode1\ZE7_CO_UART_Mode1.ino:113:18: note: in expansion of macro 'LED_Pin'
113 | digitalWrite(LED_Pin, HIGH);
| ^~~~~~~
exit status 1
Compilation error: 'D5' was not declared in this scope
You didn't follow the instructions correctly so important parts of the output are missing. Please try again, this time making sure to follow my instructions exactly.
If you have any problems, or if anything in my instructions is unclear, just let me know and I'll provide additional guidance.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.