Gas Sensor

 

Aim

To detect smoke or gas using a gas sensor.

Components required for the experiment

Arduino UNO Board and Gas Sensor.

 

What is Gas Sensor and where it is used?

A gas sensor is a device that detecs and measures the presence and concentration of various gases in the air. It operates based on different principles such as chemical reactions, conductivity changes, and infrared absorption, among others. Gas sensors are used in various applications, such as air quality monitoring, industrial safety, and gas leak detection in homes and factories.

Gas sensors are particularly useful for detecting hazardous gases that are toxic, flammable, or explosive. In industrial settings, gas sensors are often used to detect gases such as carbon monoxide, methane, and hydrogen sulfide, which can pose serious safety risks if they accumulate in the air. In homes, gas sensors are commonly used to detect carbon monoxide, a colorless, odourless gas that can be deadly in high concentrations.

Gas sensors are available in different types, including electrochemical, infrared, and semiconductor sensors. Each type has its advantages and disadvantages, and the choice of sensor depends on the specific application and the gas that has to be detected.

 

Circuit Diagram

To practice, make the circuit diagram with the exact pin-to-pin connection as shown below. This will help you to complete the experiment successfully.

Code

int gasSensor = A0;

void setup()
{
pinMode(gasSensor, INPUT);  
Serial.begin(9600);
}

void loop()
{
int gasIn = analogRead(gasSensor);  
Serial.println(gasIn);   
delay(1000);
}

Code Explained

This code aims to read the analog value obtained from a Gas sensor and display it on the Serial Monitor and print a message to clear the area if the gas value reaches above 400 units. Below is a detailed explanation of each line of code.

int gasSensor = A0;

Gas sensor data pin is connected to A0 analog pin of Arduino. 

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

In the setup() function, the code initializes the serial communication with the baud rate of 9600, which means it can transmit 9600 bits per second.

void loop()
{
int gasIn = analogRead(gasSensor);  
Serial.println(gasIn);   
delay(1000);
}

In the loop() function, the code reads the analogue value from pin A0 using the analogRead() function. It then prints the value to the serial monitor using the Serial.println() function.

The sensor data will be updated for every 1 second. This ensures that the analog value is not read too frequently and provides a delay for the user to view the values in the serial monitor.

Output and Serial Monitor

  1. Press the start simulation button in the interface.

  2. Move the mouse cursor to the gas sensor.

  3. Click on the gas sensor to activate it.

  4. Once activated, a black cloud will be displayed near the sensor.

  5. Use your mouse to move the cloud, positioning it near and away from the sensor.

  6. Observe the changes in the values displayed on the serial monitor as you move the cloud.

Conclusion

As the smoke concentration increases, the reading in the Serial Monitor also increases.

Assignment

Change the code to display a warning message on the serial monitor when the gas value is above 400 units.