You need to log in to create posts and topics.

365_AIR QUALITY DISPLAY

365_DISPLAY TEMPERATURE, HUMIDITY AND AIR QUALITY WITH ALARM. (Simulide 1.1.1973 or Higher).

This example shows the main environmental characteristics of the air on an OLED display: Temperature, humidity and air quality. The sensors used are: The HDT22 for temperature (-40 to 80 degrees Celsius) and percentage of humidity (RH) and the MQ135 sensor for gas detection. Other sensors for different gases are:

MQ2: Methane, Butane and Smoke. MQ3: Alcohol and Ethanol. MQ4: Methane. MQ5: Natural Gas. MQ6: Natural Butane. MQ7: Carbon Monoxide. MQ8: Natural Hydrogen. MQ9: Carbon Monoxide and flammable gases. MQ135: Benzene, Alcohol and Smoke.

An audible output has also been added when the air quality is harmful. At all times an LED flashes as an operating indicator and lights up steadily when the air quality begins to become rarefied.

SCHEME:

The schematic is based on the Arduino UNO. It uses an SSD1306 128x64 OLED display connected to the UNO via I2C, the DHT22 and MQ135 sensors and an LED to the D13 terminal of the controller. In the case of the MQ135 Sensor, the digital output is not used because its function is implemented in the program itself.
 

PROGRAMA:

The program is very intuitive with some complementary comments. The external libraries used are:

Adafruit_GFX.h
Adafruit_SSD1306.h
DHT.h

// AIR QUALITY DISPLAY. DEFRAN 24.

// MQ2: Methane, Butane and Smoke.
// MQ3: Alcohol y Ethanol.
// MQ4: Methane.
// MQ5: Natural Gas.
// MQ6: Natural Butane.
// MQ7: Carbon Monoxide.
// MQ8: Natural Hydrogen.
// MQ9: Carbon Monoxide and flammable gases.
// MQ135: Benzene, Alcohol and Smoke.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSans9pt7b.h> 
#include <Fonts/FreeMonoOblique9pt7b.h>
#include <DHT.h>
Adafruit_SSD1306 display(128, 64, &Wire, 4); // WIDTH, HEIGHT, WIRE, RESET.
#define MQ A3                                // GAS Sensor pin
#define DHTPIN 2                             // DHT pin
#define DHTTYPE DHT22
DHT dht(DHTPIN,  DHTTYPE);
String Gas="";
int MQval=0;
int son=7;
int mon=13;
int fijo=0;

void setup() 
{
  dht.begin();
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {while (true);}
  pinMode(MQ,INPUT);
  pinMode(mon, OUTPUT);
  pinMode(son, OUTPUT);
}

void loop() 
{
  digitalWrite(mon,HIGH);
  display.clearDisplay();
  display.drawLine(0,0,126,0,WHITE);       // LINE X,Y,WIDTH, Y FIN
  display.setTextColor(BLACK, WHITE);
  display.setCursor(0,5); display.println(" AIR QUALITY MONITOR ");
  display.setTextColor(WHITE);
  display.drawLine(0,16,126,16,WHITE);    // LINE X,Y,WIDTH, Y FIN
  MQval=analogRead(MQ);
  if(MQval<181) {Gas="  GOOD!"; digitalWrite(son,LOW); fijo=0;}
  else if (MQval>181 && MQval<225) {Gas="  Poor!"; fijo=1;}
  else if (MQval>225 && MQval<300) {Gas="Very bad!"; fijo=1;}
  else if (MQval>300 && MQval<350) {Gas="  Toxic!"; fijo=1; digitalWrite(son,HIGH);}
  else {Gas=" Lethal!"; fijo=1; digitalWrite(son,HIGH);}
  display.setTextColor(WHITE);
  display.drawLine(0,38,126,38,WHITE);          // LINE X,Y,WIDTH, Y FIN
  display.setTextSize(1);
  display.setCursor(1,26);
  display.setFont();                            // Standard Font
  display.println(" AIR:");
  display.setTextSize(1);
  display.setCursor(30,26);
  display.setFont(&FreeMonoOblique9pt7b);       // Big Font
  delay(100);
  if (fijo) digitalWrite(mon,HIGH); else digitalWrite(mon,LOW);
  display.println(Gas);                        // Print Air Gas
  float h=dht.readHumidity();
  float t=dht.readTemperature();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setFont();
  display.setCursor(0,44); display.println(" Temperature: ");
  display.setCursor(84,44);
  display.println(t,1);                            // Print Temperature, 1 ten
  display.setCursor(117,44); display.println("C");
  display.drawRect(112,44,3,3, WHITE);             // Degree symbol
  display.setCursor(0,55); display.println(" RH Humidity:");
  display.setCursor(84,55);
  display.println(h,1);                            // Print humidity, 1 ten
  display.setCursor(117,55); display.println("%");
  display.display(); 
  delay(60); 
} // pjthub insp.
 
SUBCIRCUITS:
 
This example integrates several subcircuits located in the "data" folder into the ZIP attached. This folder must always be next to the "sim1" scheme so that it can be executed. A subcircuit is a “custom” circuit that accumulates a set of Simulide base components (primitive function) to obtain a new or an adapted function. These subcircuits are treated by Simulide as another component of its own structure. User can create his own subcircuits or use the ones published here in your own designs once the procedure is known, explained in detail in the Simulide tutorials: https://simulide.com/p/subcircuits/
 
 
* Communication with the author: Simulide/User/Messages/Defran
P. de Francisco.
 
Uploaded files:
Alex68 has reacted to this post.
Alex68