Hello,
I got this winsen sensor for ozon. All i found was 1 example code for similar sensor (ZE03) on arduino on google. The wiring is correct. It's a simple serial connection. Datasheet of the sensor is in the following link: https://www.winsen-sensor.com/d/files/air-quality/ze25-o3-ozone-module--manual1_1.pdf
The code i used is here:
#include <WinsenZE03.h>
WinsenZE03 sensor;
void setup() {
Serial3.begin(9600);
sensor.begin(&Serial1, HF);
sensor.setAs(ACTIVE);
Serial.begin(9600);
}
void loop() {
float ppm = sensor.readContinuous();
Serial.println(ppm);
delay(1000);
}
But i think the main problem is library file. I think ACTIVE mode and function that returns bytes is wrong. Here is the code from the library file:
/*
WinsenZE03.h - This library allows you to set and read the ZE03 Winsen Sensor module.
Created by Fabian Gutierrez, March 12, 20017.
MIT.
*/
#include "Arduino.h"
#include "WinsenZE03.h"
#define DEVMODE true //Set as true to debug
WinsenZE03::WinsenZE03(){
_s = NULL;
}
void WinsenZE03::begin(Stream *ser, int type){
_s = ser;
_type=type;
}
void WinsenZE03::setAs(bool active){
byte setConfig[] = {0xFF, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A};
byte response[9] = {0xFF, 0x78, 0x01, 0x00, 0x00, 0x25, 0x00, 0x00, 0x87};
if (active){
setConfig[3] =0x03;
setConfig[8] =0x84;
}
_s->write(setConfig,sizeof(setConfig));
// Wait for the response
delay(2000);
//Flush the incomming buffer
if (_s->available() > 0) {
_s->readBytes(response,9);
}
while(_s->available()>0){
byte c = _s->read();
}
}
float WinsenZE03::readContinuous(){
if (_s->available() > 0) {
byte measure[8];
_s->readBytes(measure,9);
// incomingByte = _s.read();
float ppm = measure[2]*256+measure[3];
return ppm;
}
}
float WinsenZE03::readManual(){
float ppm;
byte petition[] = {0xFF,0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};// Petition to get a single result
byte measure[8]={0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};// Space for the response
_s->write(petition,sizeof(petition));
delay(1500);
// read
if (_s->available() > 0) {
_s->readBytes(measure,9);
}
// calculate
if (measure[0]==0xff && measure[1]==0x86){
ppm = measure[2]*256+measure[3];// this formula depends of the sensor is in the dataSheet
if (_type == 2){
ppm = ppm*0.1;
}
}else{
ppm=-1;
}
return ppm;
}
void WinsenZE03::debugPrint(byte arr[]){
Serial.print(arr[0],HEX);Serial.print(" ");
Serial.print(arr[1],HEX);Serial.print(" ");
Serial.print(arr[2],HEX);Serial.print(" ");
Serial.print(arr[3],HEX);Serial.print(" ");
Serial.print(arr[4],HEX);Serial.print(" ");
Serial.print(arr[5],HEX);Serial.print(" ");
Serial.print(arr[6],HEX);Serial.print(" ");
Serial.print(arr[7],HEX);Serial.print(" ");
Serial.println(arr[8],HEX);
}
And the ze.h file:
/*
Morse.h - This library allows you to set and read the ZE03 Winsen Sensor module.
Created by Fabian Gutierrez, March 12, 20017.
MIT.
*/
#ifndef WinsenZE03_h
#define WinsenZE03_h
#include "Arduino.h"
#define CO 1
#define SO2 2
#define NO2 2
#define O2 2
#define NH3 1
#define H2S 1
#define HF 1
#define CL2 2
#define O3 2
#define QA false
#define ACTIVE true
class WinsenZE03
{
public:
WinsenZE03();
void begin(Stream *ser, int type);
void setAs(bool active);
float readManual();
float readContinuous();
private:
void debugPrint(byte arr[]);
Stream *_s; //Serial1 - Serial3 are USARTClass objects.
int _type;
};
#endif
I used arduino mega so serial 1-4 is not a problem
Thx in advance for answers