pluisiRiccardo
Published © CC BY-SA

Sensori gas e Arduino

A small project to find gas concentration in the room. Alcohol, Benzene, CO

BeginnerFull instructions provided50
Sensori gas e Arduino

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Seeed Grove - Gas Sensor(MQ3)
×1
Seeed Grove - Gas Sensor(MQ5)
×1
SparkFun Carbon Monoxide Sensor - MQ-7
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
IIC / I2C / TWI / SP Module Serial Interface Port Per 5V Arduino 1602LCD
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

Schematics (Fritzing)

Code

Main Code

Arduino
// LCD I2C Library available at:
// https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library

// Libraries call
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// constant definitions
#define MQ3_pin A1
#define MQ5_pin A2
#define MQ7_pin A0

// Conditional definition of function printByte
// based on Arduino board type
#if defined(ARDUINO) && ARDUINO >= 100
#define printByte(args) write(args);
#else
#define printByte(args) print(args,BYTE);
#endif

// Definition of special characters
uint8_t bell[8] = {0x4, 0xe ,0xe, 0xe, 0x1f,0x0, 0x4};
uint8_t note[8] = {0x2, 0x3 ,0x2, 0xe, 0x1e,0xc, 0x0};
uint8_t clock[8] = {0x0, 0xe ,0x15,0x17,0x11,0xe, 0x0};
uint8_t heart[8] = {0x0, 0xa ,0x1f,0x1f,0xe, 0x4, 0x0};
uint8_t duck[8] = {0x0, 0xc ,0x1d,0xf, 0xf, 0x6, 0x0};
uint8_t check[8] = {0x0, 0x1 ,0x3, 0x16,0x1c,0x8, 0x0};
uint8_t cross[8] = {0x0, 0x1b,0xe, 0x4, 0xe, 0x1b,0x0};
uint8_t retarrow[8] = {0x1, 0x1 ,0x5, 0x9, 0x1f,0x8, 0x4};

// Creation of the global object used to 
// control LCD display through I2C interface
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 
                                  // for a 16 chars and 2 line display

void setup()
{ 
 // LCD initialisation
 lcd.init();
 lcd.backlight();
 
 // creation of special characters to be used on LCD display
 lcd.createChar(0, bell);
 lcd.createChar(1, note);
 lcd.createChar(2, clock);
 lcd.createChar(3, heart);
 lcd.createChar(4, duck);
 lcd.createChar(5, check);
 lcd.createChar(6, cross);
 lcd.createChar(7, retarrow);
 
 // Position cursor at home (0, 0)
 lcd.home();
 
 // Write startup message
 lcd.print("Gas sensors");
 lcd.setCursor(0, 1);
 lcd.print(" I ");
 lcd.printByte(3); // write special character "heart"
 lcd.print(" Arduino!");
 
 // Add a delay and clean the display
 delay(5000);
 lcd.clear();
 
 // Write information on the LCD 
 lcd.home();
 lcd.print("Alc:");
 lcd.setCursor(8, 0);
 lcd.print("Ben:");
 lcd.setCursor(0, 1);
 lcd.print("CO :");
}

void loop()
{
 // Array variable containing tension measured 
 // at the analog pin on the sensor
 float vol[3];
 // Array variable containing value read 
 // at the analog pin on the sensor on a scale [0...1024]
 int sensorValue[3];
 
 // Value assignment
 sensorValue[0] = analogRead(A1);
 sensorValue[1] = analogRead(A2);
 sensorValue[2] = analogRead(A0);
 
 // Calculate tension value
 for (int i=0; i<3; i++){
 vol[i]=(float)sensorValue[i]/1024*5.0;
 }
 
 // Data presentation on the display
 lcd.setCursor(4,0);
 lcd.print(" "); //clean area
 lcd.setCursor(4,0);
 lcd.print(sensorValue[0], DEC); //write value
 lcd.setCursor(12,0);
 lcd.print(" "); //clean area
 lcd.setCursor(12,0);
 lcd.print(sensorValue[1], DEC); //write value
 lcd.setCursor(4,1);
 lcd.print(" "); //clean area
 lcd.setCursor(4,1);
 lcd.print(sensorValue[2], DEC); //write value
 
 // delay before next reading
 delay(1000);
}

Credits

pluisi

pluisi

1 project • 0 followers
Riccardo

Riccardo

1 project • 0 followers
Hi| I'm Riccardo and i'm an IT student at the University of Verona! I love Arduino and i'm a member of AUGMAN, Arduno User Group Mantova!

Comments

Add projectSign up / Login