Example Code for Arduino-Read Oxygen Concentration

Last revision 2026/01/21

This project demonstrates how to read real-time oxygen concentration data from the SEN0495 Gravity: Oxygen / O2 Sensor using an Arduino board. Users will learn how to connect the sensor to Arduino, install the required library, and upload code to obtain real-time oxygen concentration readings.

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

/*!
  * @file  getOxygenConcentration.ino
  * @brief Enable the power, and the information is printed on the serial port.
  * @n When using IIC device, select I2C address, set the dialing switch A0, A1 (Address_0 is [0 0]), (Address_1 is [1 0]), (Address_2 is [0 1]), (Address_3 is [1 1]).
  * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
  */
#include "DFRobot_EOxygenSensor.h"

/**
 *  iic slave Address, The default is E_OXYGEN_ADDRESS_0
 *     E_OXYGEN_ADDRESS_0               0x70
 *     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);

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

void loop() 
{
  Serial.print("oxygen concetnration is "); 
  Serial.print(oxygen.readOxygenConcentration());
  Serial.println("% VOL");
  delay(1000);
}

Result

Open the serial monitor of Arduino IDE, adjust the baud rate to 115200, and observe the serial port print result.

Additional Information

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.

Was this article helpful?

TOP