Example Code for Arduino-Software Calibration

Last revision 2026/01/21

This project demonstrates how to perform software calibration (single-point or double-point) for the SEN0495 Gravity: Oxygen / O2 Sensor using Arduino. Users will learn how to clear existing calibration data, calibrate the sensor for 20.9%Vol (air) and ≥99.5%Vol (pure oxygen) environments, and check the calibration status.

Hardware Preparation

  • DFRuino UNO R3 x1
  • SEN0495 Gravity: Oxygen / O2 Sensor x1
  • Several Dupont lines

Software Preparation

Wiring Diagram

Other Preparation Work

  • Unscrew the sealing cap on the probe. After a long time of sealing storage, it needs to stand in the air for at least 3 minutes after unscrewing the sealing cap to preheat the sensor.
  • Connect the module to the Arduino according to the wiring diagram above. Of course, you can also use it with the Gravity I/O Expansion Board, which can be more convenient and faster to complete the project prototype construction.
  • The default I2C address is 0x70, which corresponds to ADDRESS_0 in the code. If you need to modify the I2C address, you can first configure the hardware I2C address through the DIP switch on the module, and modify the I2C address definition ADDRESS_X in the sample code. The corresponding relationship between the DIP switch and the I2C address parameters is as follows:
    • ADDRESS_0:0x70, A0=0, A1=0
    • ADDRESS_1:0x71, A0=1, A1=0
    • ADDRESS_2:0x72, A0=0, A1=1
    • ADDRESS_3:0x73, A0=1, A1=1

Sample Code

20.9%Vol Single-Point Calibration

/*!
  * @file  calibrationSensor.ino
  * @brief Calibrate sensor 
  * @n The calibration status is printed on the serial port terminal
  */
#include "DFRobot_EOxygenSensor.h"

/**
 *  iic slave Address, The default is E_OXYGEN_ADDRESS_0
 *     E_OXYGEN_ADDRESS_0               0x70             // i2c device address
 *     E_OXYGEN_ADDRESS_1               0x71
 *     E_OXYGEN_ADDRESS_2               0x72
 *     E_OXYGEN_ADDRESS_3               0x73
 */
#define OXYGEN_I2C_ADDRESS E_OXYGEN_ADDRESS_0
DFRobot_EOxygenSensor_I2C oxygen(&Wire, OXYGEN_I2C_ADDRESS);
uint8_t calibrationState = 0;

void setup()
{
  Serial.begin(115200);
  while(!Serial);
  while(!oxygen.begin()){
    Serial.println("NO Deivces !");
    delay(1000);
  } Serial.println("Device connected successfully !");

  if(oxygen.clearCalibration()) Serial.println("clear calibration success!");
  if(oxygen.calibration_20_9()) Serial.println("20.9 calbration success!");
  //if(oxygen.calibration_99_5()) Serial.println("99.5 calbration success!");
}

void loop() 
{
  calibrationState = oxygen.readCalibrationState();
  if(calibrationState == 0) Serial.println("no calibration!");
  if(calibrationState&0x01) Serial.println("20.9 calibration!");
  if(calibrationState&0x02) Serial.println("99.5 calibration!");
  Serial.print("oxygen concetnration is "); 
  Serial.print(oxygen.readOxygenConcentration());
  Serial.println("% VOL");
  delay(1000);
}

≥99.5%Vol Double-Point Calibration

/*!
  * @file  calibrationSensor.ino
  * @brief Calibrate sensor 
  * @n The calibration status is printed on the serial port terminal
  */
#include "DFRobot_EOxygenSensor.h"

/**
 *  iic slave Address, The default is E_OXYGEN_ADDRESS_0
 *     E_OXYGEN_ADDRESS_0               0x70             // i2c device address
 *     E_OXYGEN_ADDRESS_1               0x71
 *     E_OXYGEN_ADDRESS_2               0x72
 *     E_OXYGEN_ADDRESS_3               0x73
 */
#define OXYGEN_I2C_ADDRESS E_OXYGEN_ADDRESS_0
DFRobot_EOxygenSensor_I2C oxygen(&Wire, OXYGEN_I2C_ADDRESS);
uint8_t calibrationState = 0;

void setup()
{
  Serial.begin(115200);
  while(!Serial);
  while(!oxygen.begin()){
    Serial.println("NO Deivces !");
    delay(1000);
  } Serial.println("Device connected successfully !");

  //if(oxygen.clearCalibration()) Serial.println("clear calibration success!");
  //if(oxygen.calibration_20_9()) Serial.println("20.9 calbration success!");
  if(oxygen.calibration_99_5()) Serial.println("99.5 calbration success!");
}

void loop() 
{
  calibrationState = oxygen.readCalibrationState();
  if(calibrationState == 0) Serial.println("no calibration!");
  if(calibrationState&0x01) Serial.println("20.9 calibration!");
  if(calibrationState&0x02) Serial.println("99.5 calibration!");
  Serial.print("oxygen concetnration is "); 
  Serial.print(oxygen.readOxygenConcentration());
  Serial.println("% VOL");
  delay(1000);
}

Result

  • 20.9% of the single-point calibration is completed after the code is programmed successfully.

  • If you need to continue to complete the 99.5% calibration, please place the probe in a pure oxygen environment, and then program the sample code below. After the code is successfully programmed, the two-point calibration will be completed.

Additional Information

  • 20.9% of the single-point calibration is completed after the code is programmed successfully.
  • If you need to continue to complete the 99.5% calibration, please place the probe in a pure oxygen environment, and then program the sample code below. After the code is successfully programmed, the two-point calibration will be completed.

Was this article helpful?

TOP