An oxygen sensor measures O₂ levels using Arduino

An oxygen sensor detects oxygen concentration and sends data to an Arduino for reading or control. It works by producing a voltage or digital signal that changes with oxygen levels.

  • Measures oxygen concentration in air or liquid
  • Needs voltage, ground, and analog input
  • Use with calibration and stable power

Oxygen Sensor Arduino Setup Requires Basic Wiring

Connect the oxygen sensor to the Arduino using three main wires: power (VCC), ground (GND), and signal (analog output). Most analog oxygen sensors run on 5V, matching Arduino’s standard output. Plug VCC into the 5V pin, GND into any ground pin, and the signal wire into an analog input pin like A0.

Some sensors need a warm-up period before giving stable readings. For example, electrochemical sensors may take 30 to 60 seconds to stabilize. Wait at least 30 seconds after powering before reading values. Avoid touching the sensing element to prevent contamination or damage.

Reading Oxygen Levels Uses Analog to Digital Conversion

The Arduino reads voltage from the sensor through its analog-to-digital converter (ADC). This gives a value from 0 to 1023, representing 0V to 5V. Convert this to voltage using the formula: voltage = (sensorValue × 5.0) / 1023.0.

Once you have voltage, refer to the sensor’s datasheet to convert it to oxygen concentration. For example, a common sensor might output 0.1V at 0% O₂ and 4.0V at 25% O₂. That means each volt equals about 6.4% oxygen. Use linear interpolation: O₂ % = (voltage – minVoltage) / (maxVoltage – minV) × 25. Adjust the math based on your sensor’s specs.

Print the result to the Serial Monitor for testing. Use Serial.begin(9600) in setup() and Serial.println(oxygenPercent) in loop(). This lets you see real-time values during testing.

Calibration Ensures Accurate Oxygen Readings

Calibration is required for reliable results. Most oxygen sensors need a known reference point, usually room air, which contains about 20.9% oxygen. Place the sensor in fresh air, read the output voltage, and adjust your code to match that value to 20.9%.

Some sensors come with a calibration resistor or potentiometer. Use a small screwdriver to adjust it while watching the Serial Monitor until the reading matches expected levels. Do this in clean, outdoor air if indoor air quality is poor.

For precise work, recalibrate weekly or whenever ambient temperature or pressure changes significantly. Drift over time is normal, especially in electrochemical sensors. Never skip calibration if measuring for safety or scientific accuracy.

Different Oxygen Sensors Work With Arduino

Three main types of oxygen sensors work with Arduino: electrochemical, zirconia, and optical. Electrochemical sensors are common, low-cost, and work at room temperature. They last 1 to 3 years and are good for air quality monitoring.

Zirconia sensors require high temperatures (over 600°C) to operate, often used in car exhaust systems. These need a heater circuit and are not beginner-friendly. Do not power them directly from Arduino; use a separate power supply and relay.

Optical sensors use fluorescence and are more accurate but expensive. They resist poisoning and last longer. These often come with digital output (I2C or UART), making them easier to interface but costlier.

Check the sensor’s pinout and voltage requirements before connecting. Some list 3.3V logic and can be damaged by 5V signals. If in doubt, use a logic level shifter.

Code Example for Oxygen Sensor on Arduino

Use this basic sketch to read oxygen levels from an analog sensor:

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  float voltage = sensorValue * (5.0 / 1023.0);
  float oxygen = (voltage - 0.1) / (4.0 - 0.1) * 25.0;

  if (oxygen < 0) oxygen = 0;
  if (oxygen > 25) oxygen = 25;

  Serial.print("Voltage: ");
  Serial.print(voltage);
  Serial.print(" V, Oxygen: ");
  Serial.print(oxygen);
  Serial.println(" %");

  delay(1000);
}

This code assumes a sensor that outputs 0.1V at 0% O₂ and 4.0V at 25% O₂. Adjust minVoltage and maxVoltage values to match your sensor’s data sheet. The delay(1000) gives a reading every second.

For I2C sensors, include the correct library and use Wire.begin() and sensor.readOxygen() as per the manufacturer’s example. Always check wiring and pull-up resistors if I2C fails to connect.

Signs of a Failing or Inaccurate Oxygen Sensor

  • Readings do not change in different environments
  • Sensor reads near zero or max value continuously
  • Values drift rapidly without cause
  • Physical damage or corrosion on sensing element
  • Failed calibration in known air conditions

If the sensor doesn’t respond when moved from low-oxygen to high-oxygen areas, it may be dead. Exposure to chemicals, moisture, or extreme temperatures can shorten sensor life. Store unused sensors in a dry, sealed container with desiccant.

Electrochemical sensors degrade even when not in use. Replace them every 1 to 3 years, depending on the model. Optical sensors last longer—up to 5 years under normal conditions.

Common Mistakes When Using Oxygen Sensors With Arduino

One common mistake is powering the sensor directly from the Arduino’s 5V pin without checking current draw. Some sensors need more than 50mA, which can overload the Arduino’s regulator. Use an external 5V supply if the sensor draws over 40mA.

Another error is ignoring temperature effects. Oxygen sensors respond to partial pressure, which changes with temperature and altitude. At higher elevations, oxygen percentage stays the same, but partial pressure drops. Some sensors include temperature compensation; others require manual adjustment.

Never expose the sensor to liquids unless it is rated for it. Most are for gaseous oxygen only. Submersion can destroy electrochemical cells. For dissolved oxygen, use a specialized waterproof probe designed for liquid use.

Frequently Asked Questions

Can I measure oxygen in water with an Arduino oxygen sensor?

No, standard oxygen sensors measure gas. For water, use a dissolved oxygen (DO) probe, which is different and often requires temperature compensation and calibration in aerated water.

Why does my oxygen sensor read 0%?

It may not be warmed up, wired incorrectly, or damaged. Check connections, wait 60 seconds after power, and test in fresh air. If it still reads zero, the sensor may be dead.

Can I use an oxygen sensor from a car with Arduino?

Sometimes. Car O2 sensors are usually zirconia type and need high heat to work. They require a heater circuit and produce a narrow voltage range. Not all are compatible without additional hardware.

How often should I calibrate an oxygen sensor?

Calibrate at least once a week for critical applications. For casual use, recalibrate monthly or whenever readings seem off. Always recalibrate after moving to a new environment.

Further reading: none (general know-how)