Example Code for Arduino-Dissolved Oxygen Measurement
Last revision 2026/01/12
This tutorial will show how to use this dissolved oxygen sensor kit. The dissolved oxygen probe is a precision electrochemical sensor. Please pay attention to the usage details.
Hardware Preparation
- SEN0237-A Gravity Analog Dissolved Oxygen Sensor x 1
- DFR0216-2 DFRduino UNO R3 with IO Expansion Shield and USB Cable A-B x1
- FIT0897 Gravity: Analog Sensor Cable for Arduino(Included with SEN0237-A) x1
- 0.5mol/L NaOH Solution(Please prepare it independently.) x 1
Software Preparation
- Arduino IDE (Version requirements: V1.0.x, V1.6.x or V1.8.x), Click to Download Arduino IDE from Arduino
Wiring Diagram
When the probe is filled with NaOH solution, it needs to be calibrated. Before calibration, please connect the probe as shown in the the following diagram. Connect the probe to BNC connector on the signal converter board. Connect the board to the analog input of Arduino main-board.

Other Preparation Work
-
Before using the dissolved oxygen probe, 0.5 mol/L NaOH solution should be added into the membrane cap as the filling solution of the probe.
-
As NaOH solution has strong corrosivity, protective gloves should be put on before handling the solution. If the solution accidentally drops onto the skin, wash your skin with plenty of water immediately.
Sample Code
Please calibrate first, modify the program parameters according to the calibration data before uploading
#include <Arduino.h>
#define DO_PIN A1
#define VREF 5000 //VREF (mv)
#define ADC_RES 1024 //ADC Resolution
//Single-point calibration Mode=0
//Two-point calibration Mode=1
#define TWO_POINT_CALIBRATION 0
#define READ_TEMP (25) //Current water temperature ℃, Or temperature sensor function
//Single point calibration needs to be filled CAL1_V and CAL1_T
#define CAL1_V (1600) //mv
#define CAL1_T (25) //℃
//Two-point calibration needs to be filled CAL2_V and CAL2_T
//CAL1 High temperature point, CAL2 Low temperature point
#define CAL2_V (1300) //mv
#define CAL2_T (15) //℃
const uint16_t DO_Table[41] = {
14460, 14220, 13820, 13440, 13090, 12740, 12420, 12110, 11810, 11530,
11260, 11010, 10770, 10530, 10300, 10080, 9860, 9660, 9460, 9270,
9080, 8900, 8730, 8570, 8410, 8250, 8110, 7960, 7820, 7690,
7560, 7430, 7300, 7180, 7070, 6950, 6840, 6730, 6630, 6530, 6410};
uint8_t Temperaturet;
uint16_t ADC_Raw;
uint16_t ADC_Voltage;
uint16_t DO;
int16_t readDO(uint32_t voltage_mv, uint8_t temperature_c)
{
#if TWO_POINT_CALIBRATION == 0
uint16_t V_saturation = (uint32_t)CAL1_V + (uint32_t)35 * temperature_c - (uint32_t)CAL1_T * 35;
return (voltage_mv * DO_Table[temperature_c] / V_saturation);
#else
uint16_t V_saturation = (int16_t)((int8_t)temperature_c - CAL2_T) * ((uint16_t)CAL1_V - CAL2_V) / ((uint8_t)CAL1_T - CAL2_T) + CAL2_V;
return (voltage_mv * DO_Table[temperature_c] / V_saturation);
#endif
}
void setup()
{
Serial.begin(115200);
}
void loop()
{
Temperaturet = (uint8_t)READ_TEMP;
ADC_Raw = analogRead(DO_PIN);
ADC_Voltage = uint32_t(VREF) * ADC_Raw / ADC_RES;
Serial.print("Temperaturet:\t" + String(Temperaturet) + "\t");
Serial.print("ADC RAW:\t" + String(ADC_Raw) + "\t");
Serial.print("ADC Voltage:\t" + String(ADC_Voltage) + "\t");
Serial.println("DO:\t" + String(readDO(ADC_Voltage, Temperaturet)) + "\t");
delay(1000);
}
Result
After the upload is complete, open the serial port monitor, set the baud rate to 115200, you can see the following results
Temperaturet: 25 ADC RAW: 215 ADC Voltage: 1049 DO: 5413
Temperaturet: 25 ADC RAW: 214 ADC Voltage: 1044 DO: 5387
Temperaturet: 25 ADC RAW: 214 ADC Voltage: 1044 DO: 5387
Temperaturet: 25 ADC RAW: 213 ADC Voltage: 1040 DO: 5362
Temperaturet: 25 ADC RAW: 213 ADC Voltage: 1040 DO: 5362
Temperaturet ℃
ADC RAW ADC raw reading
ADC Voltage ADC original voltage mv
DO Dissolved oxygen μg/L, Convert to mg/L need ÷1000
Additional Information
-
The oxygen permeable membrane in the membrane cap is sensitive and vulnerable. Use caution when handling with it. Fingernail and other sharp objects should be avoided.
-
During the measuring process, the oxygen probe will consume a little oxygen. You need to gently stir the water and let the oxygen to be distributed evenly in water. On the other hand, do not stirring violently to prevent the oxygen in the air from quickly entering into the water.
Was this article helpful?
