cstram
Published © GPL3+

Sensor Station

Very simple station that shows: Temperature, Humidity, Heat index, Carbon Monoxide, Alcohol, Carbon dioxide, Toluene, Ammonium and Acetone.

BeginnerFull instructions provided30,605
Sensor Station

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
DFRobot 2.2" TFT LCD Display
×1
Siple Push button
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
MQ 135 Sensor
×1
5V Power Supply
×1

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Sensor Station PDF

You can check the schematics and the connections from this file.

Code

Sensor_Station.ino

Arduino
This code is to monitor the quality of the air in your home.
/* 
  Sensor Station
  Station for visuazing in the air the following components:
  - Temperature
  - Humidity
  - Heat Index
  - CO 
  - Alcohol
  - CO2
  - Toluene
  - NH4
  - Acetone
  
  Integration with DHT22, MQ 135, Display DFRobot DFR0529
  Carlo Stramaglia
  15 March 2021
  https://www.youtube.com/c/CarloStramaglia
  Thanks to Miguel Califa for the MQUnifiedsensor Library - reading an MQ135
*/

#include <DHT.h>
#include <DHT_U.h>
#include "DFRobot_ST7687S_Latch.h"
#include "SPI.h"
#include <MQUnifiedsensor.h>

//Definitions for MQ 135
#define placa "Arduino Nano"
#define Voltage_Resolution 5
#define pin A0 //Analog input 0 of your arduino
#define type "MQ-135" //MQ135
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
#define RatioMQ135CleanAir 3.6//RS / R0 = 3.6 ppm 
MQUnifiedsensor MQ135(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type); 


//Definition for DHT 22
#define DHTPIN            4         // Pin which is connected to the DHT sensor.
char temp[8];
char umid[8];
char heat[8];
#define DHTTYPE           DHT22     // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);

//Definition for DFRobot Display
uint8_t pin_cs = 3, pin_rs = 5, pin_wr = 6, pin_lck = 7; //Display PIN connetors
DFRobot_ST7687S_Latch tft(pin_cs, pin_rs, pin_wr, pin_lck);


void setup() {
  Serial.begin(9600);
  dht.begin();
  tft.begin();
  tft.fillScreen(DISPLAY_BLACK);
  tft.setTextColor(DISPLAY_WHITE);  //set text color to white
  tft.setTextBackground(DISPLAY_BLACK);  //set text background to black
  tft.setTextSize(1);  //1 * text size, default text size: 6 * 8
  
  //MQ 135 Setup Section 
  MQ135.setRegressionMethod(1); //_PPM =  a*ratio^b
  MQ135.init(); 
  Serial.print("Calibrating please wait.");
  float calcR0 = 0;
  for(int i = 1; i<=10; i ++)
  {
    MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
    calcR0 += MQ135.calibrate(RatioMQ135CleanAir);
    Serial.print(".");
  }
  MQ135.setR0(calcR0/10);
  Serial.println("  done!.");
  if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);}
  if(calcR0 == 0){Serial.println("Warning: Conection issue founded, R0 is zero (Analog pin with short circuit to ground) please check your wiring and supply"); while(1);}
  //MQ Setup and calibration finished
}

void loop() {
  // Read temperature
  float t = dht.readTemperature();
  // Read Humidity
  float h = dht.readHumidity();

   // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) ) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Compute the heat Index
  float hic = dht.computeHeatIndex(t, h, false);

  tft.fillScreen(DISPLAY_ORANGE);
  tft.setTextBackground(DISPLAY_ORANGE);
  tft.setTextColor(DISPLAY_WHITE);
  tft.drawCircle(0, 0, 64, DISPLAY_BLUE);
  tft.drawCircle(0, 0, 63, DISPLAY_BLUE);
  tft.setCursor(20, 25);  //set text position
  tft.print("AIR TEMPERATURE");
  //Display Temperature and Humidity
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println("C");
  dtostrf(t, 2, 2, temp);
  temp[5]=byte(0x20);
  temp[6]='C';
  temp[7]='\0';
  tft.setCursor(25, 55);  //set text position
  tft.print("TEMP: ");
  tft.print(temp);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.println("%");
  dtostrf(h, 2, 2, umid);
  umid[5]=byte(0x20);
  umid[6]='%';
  umid[7]='\0';
  tft.setCursor(25, 65);  //set text position
  tft.print("HUMI: ");
  tft.print(umid);

  Serial.print("Heat Index: ");
  Serial.print(hic);
  Serial.println("C");
  dtostrf(hic, 2, 2, heat);
  heat[5]=byte(0x20);
  heat[6]='C';
  heat[7]='\0';
  tft.setCursor(25, 75);  //set text position
  tft.print("HEAT: ");
  tft.print(heat);
  
  delay(5000);

  // MQ Reading and updating section
  MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin
  MQ135.setA(605.18); MQ135.setB(-3.937); // Configurate the ecuation values to get CO concentration
  float CO = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
  MQ135.setA(77.255); MQ135.setB(-3.18); // Configurate the ecuation values to get Alcohol concentration
  float Alcohol = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
  MQ135.setA(110.47); MQ135.setB(-2.862); // Configurate the ecuation values to get CO2 concentration
  float CO2 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
  MQ135.setA(44.947); MQ135.setB(-3.445); // Configurate the ecuation values to get Toluene concentration
  float Toluene = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
  MQ135.setA(102.2 ); MQ135.setB(-2.473); // Configurate the ecuation values to get NH4 concentration
  float NH4 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
  MQ135.setA(34.668); MQ135.setB(-3.369); // Configurate the ecuation values to get Acetone concentration
  float Acetone = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup

  tft.fillScreen(DISPLAY_ORANGE);
  tft.setTextBackground(DISPLAY_ORANGE);
  tft.setTextColor(DISPLAY_WHITE);
  tft.drawCircle(0, 0, 64, DISPLAY_BLUE);
  tft.drawCircle(0, 0, 63, DISPLAY_BLUE);  
  //Display CO, Alcohol, CO2, Toluene, NH4, Acetone
  tft.setCursor(18, 25);  //set text position
  tft.print("AIR QUALITY DATA");
  
  Serial.print("CO: ");
  Serial.println(CO);
  dtostrf(CO, 2, 2, temp);
  temp[5]=byte(0x20);
  temp[6]='\0';
  tft.setCursor(25, 40);  //set text position
  tft.print("CO     : ");
  tft.print(temp);

  Serial.print("ALCOHOL: ");
  Serial.println(Alcohol);
  dtostrf(Alcohol, 2, 2, temp);
  temp[5]=byte(0x20);
  temp[6]='\0';
  tft.setCursor(25, 50);  //set text position
  tft.print("ALCOHOL: ");
  tft.print(temp);

  Serial.print("CO2: ");
  Serial.println(CO2);
  dtostrf(CO2, 2, 2, temp);
  temp[5]=byte(0x20);
  temp[6]='\0';
  tft.setCursor(25, 60);  //set text position
  tft.print("CO2    : ");
  tft.print(temp);

  Serial.print("TOLUENE: ");
  Serial.println(Toluene);
  dtostrf(Toluene, 2, 2, temp);
  temp[5]=byte(0x20);
  temp[6]='\0';
  tft.setCursor(25, 70);  //set text position
  tft.print("TOLUENE: ");
  tft.print(temp);

  Serial.print("NH4: ");
  Serial.println(NH4);
  dtostrf(NH4, 2, 2, temp);
  temp[5]=byte(0x20);
  temp[6]='\0';
  tft.setCursor(25, 80);  //set text position
  tft.print("NH4    : ");
  tft.print(temp);

  Serial.print("ACETONE: ");
  Serial.println(Acetone);
  dtostrf(Acetone, 2, 2, temp);
  temp[5]=byte(0x20);
  temp[6]='\0';
  tft.setCursor(25, 90);  //set text position
  tft.print("ACETONE: ");
  tft.print(temp); 
  
  delay(5000);

}

Credits

cstram

cstram

16 projects • 21 followers
Passionate about IT, Electronics and DIY. Strong believer in Raspberry and Arduino devices. Experience in digital television and security.

Comments