Hi all,
I've found a good oxygen sensor with a fairly good accuracy.
But there wasn't any good code yet to find.
There are two versions, a OCS-3F-2.1 and OCS-3F-3.0
OCS-3F-2.1 WINPOWER Ultrasonic Oxygen Sensor for oxygen concentrator 2024 detect 21%-95.6% ,0-10L New gas detector
So here's a small working example.
#include <SoftwareSerial.h>
SoftwareSerial oxygenSensor(10, 11); // RX, TX
void setup() {
Serial.begin(9600);
oxygenSensor.begin(9600);
}
void loop() {
if (oxygenSensor.available() >= 12) { // Wait until full package has received
byte buffer[12];
for (int i = 0; i < 12; i++) {
buffer[i] = oxygenSensor.read();
}
// Check the header (first trhee bytes have to be 0x16, 0x09, 0x01)
if (buffer[0] == 0x16 && buffer[1] == 0x09 && buffer[2] == 0x01) {
int concentration = (buffer[3] << 8) | buffer[4]; // Oxygen at 0,1%
int flow = (buffer[5] << 8) | buffer[6]; // Flow in L/min
int temperature = (buffer[7] << 8) | buffer[8]; // Temperature at 0,1 °C
// Calculate checksum and validate
byte checksum = 0;
for (int i = 0; i < 11; i++) {
checksum += buffer[i];
}
checksum = 0x00 - checksum;
if (checksum == buffer[11]) { // Checksum validate
Serial.print("Concentration: ");
Serial.print(concentration / 10.0);
Serial.println(" %");
Serial.print("Flow: ");
Serial.print(flow / 10.0);
Serial.println(" L/min");
Serial.print("Temperature: ");
Serial.print(temperature / 10.0);
Serial.println(" °C");
} else {
Serial.println("Checksum error!");
}
}
}
}
OCS-3F 2.1data sheet.pdf (598.0 KB)