Upgrade

Air Quality monitor - Temperature - Humidity

CODE


#include <Arduino.h>

#include <MQ135.h>

#include <SPI.h>

#include <Wire.h>


#include <Adafruit_GFX.h> // Adafruit core graphics library

#include <Adafruit_ST7789.h> // Adafruit hardware-specific library for ST7789

#include <DHT.h> // Adafruit DHT library code




// ST7789 TFT module connections

#define TFT_CS 10 // define chip select pin

#define TFT_DC 8 // define data/command pin

#define TFT_RST 9 // define reset pin, or set to -1 and connect to Arduino RESET pin

// initialize Adafruit ST7789 TFT library with hardware SPI module

// MOSI(SDA) ---> Arduino digital pin 11

// SCK (SCL) ---> Arduino digital pin 13

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);


#define DHTPIN 6 // DHT11 data pin is connected to Arduino analog pin 2

#define DHTTYPE DHT11 // DHT11 sensor is used

DHT dht11(DHTPIN, DHTTYPE); // initialize DHT library


int LED = 2;

void setup(void) {

pinMode(LED, OUTPUT);

digitalWrite(LED, LOW);


// initialize the ST7789 display (240x240 pixel)

// if the display has CS pin try with SPI_MODE0

tft.init(240, 240, SPI_MODE2);

// if the screen is flipped, remove this command

tft.setRotation(2);

// fill the screen with black color

tft.fillScreen(ST77XX_BLACK);


tft.setTextColor(ST77XX_YELLOW);

tft.setCursor(45, 90);

tft.setTextSize(7);

tft.println("Wait");

delay(25000);


tft.fillScreen(ST77XX_BLACK);


tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);

tft.setCursor(15, 0);

tft.setTextSize(3);

tft.print("TEMPERATURE");


tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);

tft.setCursor(15, 85);

tft.setTextSize(3);

tft.print("AIR HUMIDITY");


tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK);

tft.setCursor(15, 166);

tft.setTextSize(3);

tft.print("AIR QUALITY");



// initialize DHT11 sensor

dht11.begin();

}

char _buffer[7];

// main loop


void loop() {

digitalWrite(LED,LOW);


// read humidity in rH%

int Humi = dht11.readHumidity() * 10;

// read temperature in degrees Celsius

int Temp = dht11.readTemperature() * 10;


// print temperature (in °C)

tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);

if (Temp < 0) // if temperature < 0

sprintf(_buffer, "-%02u.%02u", (abs(Temp) / 10) % 100, abs(Temp) % 10);

else // temperature >= 0

sprintf(_buffer, "%02u.%02u", (Temp / 10) % 100, Temp % 10);


tft.setCursor(20, 35);

tft.setTextSize(5); // text size

tft.print(_buffer);

tft.drawCircle(181, 47, 4, ST77XX_CYAN); // print degree symbol ( ° )

tft.setCursor(190, 35);

tft.print("C");


sprintf(_buffer, "%02u.%02u%%", (Humi / 10) % 100, Humi % 100);

tft.setCursor(30, 116);

tft.setTextSize(5); // text size

tft.print(_buffer);



int sensorValue = analogRead(A0);

tft.setCursor(70, 200);

if (sensorValue < 260)tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);

if (sensorValue < 260)digitalWrite(LED,LOW);

tft.setTextSize(5);

if (sensorValue > 260)tft.setTextColor(ST77XX_MAGENTA, ST77XX_BLACK);

if (sensorValue > 260)digitalWrite(LED,LOW);

tft.setTextSize(5);

if (sensorValue > 360)tft.setTextColor(ST77XX_RED, ST77XX_BLACK);

if (sensorValue > 360)digitalWrite(LED,HIGH);

tft.setTextSize(5);

tft.println(sensorValue);

delay(500);


}

Air Quality to TFT monitor

MQ-135 sensor introduction:

The gas sensitive material used with the MQ135 gas sensor is tin dioxide (SnO2), which has a lower conductivity in clean air. When contaminated gas is present in the environment

where the sensor is located, the conductivity of the sensor increases as the concentration of contaminated gas in the air increases. A simple circuit converts the change in conductivity into an output signal that corresponds to the gas concentration.

The MQ135 sensor is highly sensitive to ammonia, sulphides and benzene vapors and is also ideal for smoke and other harmful monitoring. This sensor can detect a variety of harmful gases, is a low-cost sensor for a variety of applications.


Module application:

It is suitable for the detection of harmful gases such as ammonia, aromatics, sulfides, benzene vapor, smoke and other harmful gas detection devices, gas sensor testing range of concentration: 10 to 1000ppm

CODE

/*

MQ135 with ST7789 IPS SPI 240X240 display without CS pin.

by somtips.com

*/

#include <Arduino.h>

#include <MQ135.h>

#include <SPI.h>

#include <Wire.h>

#include <Adafruit_GFX.h> // Core graphics library by Adafruit

#include <Adafruit_ST7789.h>

// ST7789 TFT module connections

#define TFT_CS 10 // define chip select pin

#define TFT_DC 8 // define data/command pin

#define TFT_RST 9 // define reset pin, or set to -1 and connect to Arduino RESET pin

// initialize Adafruit ST7789 TFT library with hardware SPI module

// MOSI(SDA) ---> Arduino digital pin 11

// SCK (SCL) ---> Arduino digital pin 13

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

int led1 = 2; // Red

int analogPin = 0;

int val = 0;

void setup() {

pinMode(led1, OUTPUT);

digitalWrite(led1, LOW);

tft.init(240, 240, SPI_MODE2); // initialize a ST7789 chip, 240x240 pixels

tft.setRotation(3);

tft.fillScreen(ST77XX_YELLOW);

tft.setCursor(45, 90);

tft.setTextColor(ST77XX_BLACK);

tft.setTextSize(7);

tft.println("Wait");

delay(25000);

tft.fillScreen(ST77XX_GREEN);

tft.setCursor(20, 10);

tft.setTextColor(ST77XX_BLACK);

tft.setTextSize(3);

tft.println("Air Quality");

tft.setCursor(80, 200);

tft.setTextColor(ST77XX_BLACK);

tft.setTextSize(4);

tft.println("PPM");

}

void loop() {

int sensorValue = analogRead(A0);

digitalWrite(led1, LOW);

if (sensorValue > 0 && sensorValue < 200) tft.fillRect(0,40,240,150,ST77XX_BLUE);

if (sensorValue > 200 && sensorValue < 400)tft.fillRect(0,40,240,150,ST77XX_MAGENTA);

if (sensorValue > 400)tft.fillRect(0,40,240,150,ST77XX_RED);

tft.setCursor(45, 90);

tft.setTextColor(ST77XX_WHITE);

tft.setTextSize(9);

tft.println(sensorValue);

delay(100);

if (sensorValue > 400)digitalWrite(led1, HIGH);

delay(1000);

}

Air Quality monitor - led bar indicator - to power outlet

commercial version

code

/*

MQ135 with ST7789 IPS SPI 240X240 display without CS pin.

by somtips.com

*/

#include <Arduino.h>

#include <MQ135.h>

#include <SPI.h>

#include <Wire.h>


int led2 = 2;

int led3 = 3;

int led4 = 4;

int led5 = 5;

int led6 = 6;

int led7 = 7;

int led8 = 8;

int led9 = 9;

int led10 = 10;

int led11 = 11;

int led12 = 12;

int led13 = 13;


int analogPin = 0;

int val = 0;


void setup() {

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

pinMode(led5, OUTPUT);

pinMode(led6, OUTPUT);

pinMode(led7, OUTPUT);

pinMode(led8, OUTPUT);

pinMode(led9, OUTPUT);

pinMode(led10, OUTPUT);

pinMode(led11, OUTPUT);

pinMode(led12, OUTPUT);

pinMode(led13, OUTPUT);


delay(25);

}


void loop() {

int sensorValue = analogRead(A0);



digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

digitalWrite(led8, HIGH);

digitalWrite(led9, HIGH);

digitalWrite(led10, HIGH);

digitalWrite(led11, HIGH);

digitalWrite(led12, HIGH);

digitalWrite(led13, LOW);




if (sensorValue > 0)digitalWrite(led2, LOW);

if (sensorValue > 50 )digitalWrite(led3, LOW);

if (sensorValue > 100)digitalWrite(led4, LOW);

if (sensorValue > 150)digitalWrite(led5, LOW);

if (sensorValue > 200)digitalWrite(led6, LOW);

if (sensorValue > 250)digitalWrite(led7, LOW);

if (sensorValue > 300)digitalWrite(led8, LOW);

if (sensorValue > 300)digitalWrite(led13, HIGH);

if (sensorValue > 350)digitalWrite(led9, LOW);

if (sensorValue > 400)digitalWrite(led10, LOW);

if (sensorValue > 450)digitalWrite(led11, LOW);

if (sensorValue > 500)digitalWrite(led12, LOW);


delay(10);

}