Exercise 16 - Connecting a gas sensor

1.      INTRODUCTION

This module uses a tiny heater inside with an electro-chemical sensor, which can measure a range of gasses like: CH4,Natural Gas, Cigarette smoke, alcohol…

You can read these measures with an analog pin on the Arduino board.


2.      HOW TO CONNECT?

You can use this module as electro-chemical (digital output) or/and analog measuring (analog output).

To connect this module to Arduino you must connect Vcc and GND pins to 5V and ground respectively, also connect AO and DO pins to analog (A0) and digital (pin4) pin on Arduino.

On the other hand, you must connect a LED to pin13.

Materials:

·         Arduino UNO board

·         Protoboard

·         Some wire Jumpers

·         LED

·         220 ohms resistor

·         Gas sensor (MQ-4)


EXERCISE_A (Testing the sensor)


3.      PROGRAMMING

 

This program allows to measure density of different gasses in air.

 

int led=13;//Led to Arduino pin 13

int digitalGas=4;

int analogGas=A0;//GAS sensor output pin to Arduino analog A0 pin

 

On setup, you should declare analogGas and digitalGas as INPUT led pin as OUTPUT.

 

void setup()

{

  Serial.begin(9600);//Initialize serial port - 9600 bps

  pinMode(analogGas,INPUT);

  pinMode(digitalGas,INPUT);

  pinMode(led,OUTPUT);

}

 

In this exercise loop part have condition, which turn on the LED if sensor digital output sends to the Arduino board a HIGH level.

 

void loop()

{

  //Turn on led if detects alcohol.

  if(digitalRead(digitalGas)==LOW){

    digitalWrite(led,HIGH);

  }

  else{

    digitalWrite(led,LOW);

  }

  Serial.println(analogRead(analogGas));

  delay(1000);// Print value every 1 sec.

}


Última modificación: Tuesday, 21 de January de 2020, 10:29