What is the oxygen level in your room?

What is the oxygen level in your room?

 

Introduction

In this tutorial, it is demonstrated how to measure the oxygen level using the Grove Oxygen Level and display the value using Grove 16x2 LCD and Blynk app. The data obtained is important to ensure that the oxygen level is at the right amount. As we are all are aware, we humans need oxygen to live. The minimum oxygen concentration in the air required for human breathing is 19.5 percent. Most of the time, the air in the atmosphere contains the proper amount of oxygen for safe breathing.

What is the normal air composition?

The normal air in our environment consists of few different gases. Approximately 78% of the air composition is nitrogen while the percentage of oxygen is only about 20.9 percent. The remaining fraction consists of primarily argon gas, but trace amounts of carbon dioxide, neon and helium are also present as well.

 

Video

Hardware Preparation

This is the list of items used in the video.

 

Circuit

There is no additional circuit is required since we are using the grove sensor. Below is the connection details

Grove ---> Connection
Grove Wifi ---> Port D2
Grove Oxygen Sensor ---> Port A0
Grove 16x2 LCD ---> Port i2C

 

Code

The code for this tutorial is as shown below

#include 
#include "rgb_lcd.h"
#include 
#include 

#include 
SoftwareSerial EspSerial(2, 3); // RX, TX

char auth[] = "djigt1lMWzPmqbppsEDxk6uUFNeLzf-C";

// Set password to "" for open networks.
char ssid[] = "hotspot";
char pass[] = "hotspot123";

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

// Grove - Gas Sensor(O2) test code
// Note:
// 1. It need about about 5-10 minutes to preheat the sensor
// 2. modify VRefer if needed
 
const float VRefer = 3.3;       // voltage of adc reference
 
const int pinAdc   = A0;

rgb_lcd lcd;

const int colorR = 255;
const int colorG = 0;
const int colorB = 0;


void setup() 
{
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    
   // lcd.setRGB(colorR, colorG, colorB);
    
    // Print a message to the LCD.
    lcd.print("Oxygen Level");
    lcd.setCursor(0, 1);
    lcd.print("Monitoring");

    delay(1000);

    // Open the connection at 115200
  EspSerial.begin(115200);
  EspSerial.println("AT");

  Blynk.begin(auth, wifi, ssid, pass);
}

void loop() 
{

    Blynk.run();
    
    lcd.clear();
    lcd.setCursor(0, 0);
    float Vout =0;
    Vout = readO2Vout();
    lcd.print("Vout : ");
    lcd.print(Vout);
    lcd.setCursor(0, 1);
    lcd.print("O2% : ");
    lcd.print(readConcentration());
    
    Blynk.virtualWrite(V1, readConcentration());
    //delay(1000);
    delay(100);
}


float readO2Vout()
{
    long sum = 0;
    for(int i=0; i<32; i++)
    {
        sum += analogRead(pinAdc);
    }
 
    sum >>= 5;
 
    float MeasuredVout = sum * (VRefer / 1023.0);
    return MeasuredVout;
}
 
float readConcentration()
{
    // Vout samples are with reference to 3.3V
    float MeasuredVout = readO2Vout();
 
    //float Concentration = FmultiMap(MeasuredVout, VoutArray,O2ConArray, 6);
    //when its output voltage is 2.0V,
    float Concentration = MeasuredVout * 0.21 / 2.0;
    float Concentration_Percentage=Concentration*100;
    return Concentration_Percentage;
}

Thank You

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

"Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for a better application."