Components and supplies
5V Power Supply
Arduino Nano R3
DHT22 Temperature Sensor
Siple Push button
2.2" TFT LCD Display
MQ 135 Sensor
Tools and machines
Soldering iron (generic)
Drill / Driver, Cordless
Project description
Code
Sensor_Station.ino
arduino
This code is to monitor the quality of the air in your home.
1/* 2 Sensor Station 3 Station for visuazing in the air the following components: 4 - Temperature 5 - Humidity 6 - Heat Index 7 - CO 8 - Alcohol 9 - CO2 10 - Toluene 11 - NH4 12 - Acetone 13 14 Integration with DHT22, MQ 135, Display DFRobot DFR0529 15 Carlo Stramaglia 16 15 March 2021 17 https://www.youtube.com/c/CarloStramaglia 18 Thanks to Miguel Califa for the MQUnifiedsensor Library - reading an MQ135 19*/ 20 21#include <DHT.h> 22#include <DHT_U.h> 23#include "DFRobot_ST7687S_Latch.h" 24#include "SPI.h" 25#include <MQUnifiedsensor.h> 26 27//Definitions for MQ 135 28#define placa "Arduino Nano" 29#define Voltage_Resolution 5 30#define pin A0 //Analog input 0 of your arduino 31#define type "MQ-135" //MQ135 32#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO 33#define RatioMQ135CleanAir 3.6//RS / R0 = 3.6 ppm 34MQUnifiedsensor MQ135(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type); 35 36 37//Definition for DHT 22 38#define DHTPIN 4 // Pin which is connected to the DHT sensor. 39char temp[8]; 40char umid[8]; 41char heat[8]; 42#define DHTTYPE DHT22 // DHT 22 (AM2302) 43DHT dht(DHTPIN, DHTTYPE); 44 45//Definition for DFRobot Display 46uint8_t pin_cs = 3, pin_rs = 5, pin_wr = 6, pin_lck = 7; //Display PIN connetors 47DFRobot_ST7687S_Latch tft(pin_cs, pin_rs, pin_wr, pin_lck); 48 49 50void setup() { 51 Serial.begin(9600); 52 dht.begin(); 53 tft.begin(); 54 tft.fillScreen(DISPLAY_BLACK); 55 tft.setTextColor(DISPLAY_WHITE); //set text color to white 56 tft.setTextBackground(DISPLAY_BLACK); //set text background to black 57 tft.setTextSize(1); //1 * text size, default text size: 6 * 8 58 59 //MQ 135 Setup Section 60 MQ135.setRegressionMethod(1); //_PPM = a*ratio^b 61 MQ135.init(); 62 Serial.print("Calibrating please wait."); 63 float calcR0 = 0; 64 for(int i = 1; i<=10; i ++) 65 { 66 MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin 67 calcR0 += MQ135.calibrate(RatioMQ135CleanAir); 68 Serial.print("."); 69 } 70 MQ135.setR0(calcR0/10); 71 Serial.println(" done!."); 72 if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);} 73 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);} 74 //MQ Setup and calibration finished 75} 76 77void loop() { 78 // Read temperature 79 float t = dht.readTemperature(); 80 // Read Humidity 81 float h = dht.readHumidity(); 82 83 // Check if any reads failed and exit early (to try again). 84 if (isnan(h) || isnan(t) ) { 85 Serial.println(F("Failed to read from DHT sensor!")); 86 return; 87 } 88 89 // Compute the heat Index 90 float hic = dht.computeHeatIndex(t, h, false); 91 92 tft.fillScreen(DISPLAY_ORANGE); 93 tft.setTextBackground(DISPLAY_ORANGE); 94 tft.setTextColor(DISPLAY_WHITE); 95 tft.drawCircle(0, 0, 64, DISPLAY_BLUE); 96 tft.drawCircle(0, 0, 63, DISPLAY_BLUE); 97 tft.setCursor(20, 25); //set text position 98 tft.print("AIR TEMPERATURE"); 99 //Display Temperature and Humidity 100 Serial.print("Temperature: "); 101 Serial.print(t); 102 Serial.println("C"); 103 dtostrf(t, 2, 2, temp); 104 temp[5]=byte(0x20); 105 temp[6]='C'; 106 temp[7]='\\0'; 107 tft.setCursor(25, 55); //set text position 108 tft.print("TEMP: "); 109 tft.print(temp); 110 111 Serial.print("Humidity: "); 112 Serial.print(h); 113 Serial.println("%"); 114 dtostrf(h, 2, 2, umid); 115 umid[5]=byte(0x20); 116 umid[6]='%'; 117 umid[7]='\\0'; 118 tft.setCursor(25, 65); //set text position 119 tft.print("HUMI: "); 120 tft.print(umid); 121 122 Serial.print("Heat Index: "); 123 Serial.print(hic); 124 Serial.println("C"); 125 dtostrf(hic, 2, 2, heat); 126 heat[5]=byte(0x20); 127 heat[6]='C'; 128 heat[7]='\\0'; 129 tft.setCursor(25, 75); //set text position 130 tft.print("HEAT: "); 131 tft.print(heat); 132 133 delay(5000); 134 135 // MQ Reading and updating section 136 MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin 137 MQ135.setA(605.18); MQ135.setB(-3.937); // Configurate the ecuation values to get CO concentration 138 float CO = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 139 MQ135.setA(77.255); MQ135.setB(-3.18); // Configurate the ecuation values to get Alcohol concentration 140 float Alcohol = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 141 MQ135.setA(110.47); MQ135.setB(-2.862); // Configurate the ecuation values to get CO2 concentration 142 float CO2 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 143 MQ135.setA(44.947); MQ135.setB(-3.445); // Configurate the ecuation values to get Toluene concentration 144 float Toluene = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 145 MQ135.setA(102.2 ); MQ135.setB(-2.473); // Configurate the ecuation values to get NH4 concentration 146 float NH4 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 147 MQ135.setA(34.668); MQ135.setB(-3.369); // Configurate the ecuation values to get Acetone concentration 148 float Acetone = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 149 150 tft.fillScreen(DISPLAY_ORANGE); 151 tft.setTextBackground(DISPLAY_ORANGE); 152 tft.setTextColor(DISPLAY_WHITE); 153 tft.drawCircle(0, 0, 64, DISPLAY_BLUE); 154 tft.drawCircle(0, 0, 63, DISPLAY_BLUE); 155 //Display CO, Alcohol, CO2, Toluene, NH4, Acetone 156 tft.setCursor(18, 25); //set text position 157 tft.print("AIR QUALITY DATA"); 158 159 Serial.print("CO: "); 160 Serial.println(CO); 161 dtostrf(CO, 2, 2, temp); 162 temp[5]=byte(0x20); 163 temp[6]='\\0'; 164 tft.setCursor(25, 40); //set text position 165 tft.print("CO : "); 166 tft.print(temp); 167 168 Serial.print("ALCOHOL: "); 169 Serial.println(Alcohol); 170 dtostrf(Alcohol, 2, 2, temp); 171 temp[5]=byte(0x20); 172 temp[6]='\\0'; 173 tft.setCursor(25, 50); //set text position 174 tft.print("ALCOHOL: "); 175 tft.print(temp); 176 177 Serial.print("CO2: "); 178 Serial.println(CO2); 179 dtostrf(CO2, 2, 2, temp); 180 temp[5]=byte(0x20); 181 temp[6]='\\0'; 182 tft.setCursor(25, 60); //set text position 183 tft.print("CO2 : "); 184 tft.print(temp); 185 186 Serial.print("TOLUENE: "); 187 Serial.println(Toluene); 188 dtostrf(Toluene, 2, 2, temp); 189 temp[5]=byte(0x20); 190 temp[6]='\\0'; 191 tft.setCursor(25, 70); //set text position 192 tft.print("TOLUENE: "); 193 tft.print(temp); 194 195 Serial.print("NH4: "); 196 Serial.println(NH4); 197 dtostrf(NH4, 2, 2, temp); 198 temp[5]=byte(0x20); 199 temp[6]='\\0'; 200 tft.setCursor(25, 80); //set text position 201 tft.print("NH4 : "); 202 tft.print(temp); 203 204 Serial.print("ACETONE: "); 205 Serial.println(Acetone); 206 dtostrf(Acetone, 2, 2, temp); 207 temp[5]=byte(0x20); 208 temp[6]='\\0'; 209 tft.setCursor(25, 90); //set text position 210 tft.print("ACETONE: "); 211 tft.print(temp); 212 213 delay(5000); 214 215} 216
Sensor_Station.ino
arduino
This code is to monitor the quality of the air in your home.
1/* 2 Sensor Station 3 Station for visuazing in the air the following components: 4 - Temperature 5 - Humidity 6 - Heat Index 7 - CO 8 - Alcohol 9 - CO2 10 - Toluene 11 - NH4 12 - Acetone 13 14 Integration with DHT22, MQ 135, Display DFRobot DFR0529 15 Carlo Stramaglia 16 15 March 2021 17 https://www.youtube.com/c/CarloStramaglia 18 Thanks to Miguel Califa for the MQUnifiedsensor Library - reading an MQ135 19*/ 20 21#include <DHT.h> 22#include <DHT_U.h> 23#include "DFRobot_ST7687S_Latch.h" 24#include "SPI.h" 25#include <MQUnifiedsensor.h> 26 27//Definitions for MQ 135 28#define placa "Arduino Nano" 29#define Voltage_Resolution 5 30#define pin A0 //Analog input 0 of your arduino 31#define type "MQ-135" //MQ135 32#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO 33#define RatioMQ135CleanAir 3.6//RS / R0 = 3.6 ppm 34MQUnifiedsensor MQ135(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type); 35 36 37//Definition for DHT 22 38#define DHTPIN 4 // Pin which is connected to the DHT sensor. 39char temp[8]; 40char umid[8]; 41char heat[8]; 42#define DHTTYPE DHT22 // DHT 22 (AM2302) 43DHT dht(DHTPIN, DHTTYPE); 44 45//Definition for DFRobot Display 46uint8_t pin_cs = 3, pin_rs = 5, pin_wr = 6, pin_lck = 7; //Display PIN connetors 47DFRobot_ST7687S_Latch tft(pin_cs, pin_rs, pin_wr, pin_lck); 48 49 50void setup() { 51 Serial.begin(9600); 52 dht.begin(); 53 tft.begin(); 54 tft.fillScreen(DISPLAY_BLACK); 55 tft.setTextColor(DISPLAY_WHITE); //set text color to white 56 tft.setTextBackground(DISPLAY_BLACK); //set text background to black 57 tft.setTextSize(1); //1 * text size, default text size: 6 * 8 58 59 //MQ 135 Setup Section 60 MQ135.setRegressionMethod(1); //_PPM = a*ratio^b 61 MQ135.init(); 62 Serial.print("Calibrating please wait."); 63 float calcR0 = 0; 64 for(int i = 1; i<=10; i ++) 65 { 66 MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin 67 calcR0 += MQ135.calibrate(RatioMQ135CleanAir); 68 Serial.print("."); 69 } 70 MQ135.setR0(calcR0/10); 71 Serial.println(" done!."); 72 if(isinf(calcR0)) {Serial.println("Warning: Conection issue founded, R0 is infite (Open circuit detected) please check your wiring and supply"); while(1);} 73 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);} 74 //MQ Setup and calibration finished 75} 76 77void loop() { 78 // Read temperature 79 float t = dht.readTemperature(); 80 // Read Humidity 81 float h = dht.readHumidity(); 82 83 // Check if any reads failed and exit early (to try again). 84 if (isnan(h) || isnan(t) ) { 85 Serial.println(F("Failed to read from DHT sensor!")); 86 return; 87 } 88 89 // Compute the heat Index 90 float hic = dht.computeHeatIndex(t, h, false); 91 92 tft.fillScreen(DISPLAY_ORANGE); 93 tft.setTextBackground(DISPLAY_ORANGE); 94 tft.setTextColor(DISPLAY_WHITE); 95 tft.drawCircle(0, 0, 64, DISPLAY_BLUE); 96 tft.drawCircle(0, 0, 63, DISPLAY_BLUE); 97 tft.setCursor(20, 25); //set text position 98 tft.print("AIR TEMPERATURE"); 99 //Display Temperature and Humidity 100 Serial.print("Temperature: "); 101 Serial.print(t); 102 Serial.println("C"); 103 dtostrf(t, 2, 2, temp); 104 temp[5]=byte(0x20); 105 temp[6]='C'; 106 temp[7]='\\0'; 107 tft.setCursor(25, 55); //set text position 108 tft.print("TEMP: "); 109 tft.print(temp); 110 111 Serial.print("Humidity: "); 112 Serial.print(h); 113 Serial.println("%"); 114 dtostrf(h, 2, 2, umid); 115 umid[5]=byte(0x20); 116 umid[6]='%'; 117 umid[7]='\\0'; 118 tft.setCursor(25, 65); //set text position 119 tft.print("HUMI: "); 120 tft.print(umid); 121 122 Serial.print("Heat Index: "); 123 Serial.print(hic); 124 Serial.println("C"); 125 dtostrf(hic, 2, 2, heat); 126 heat[5]=byte(0x20); 127 heat[6]='C'; 128 heat[7]='\\0'; 129 tft.setCursor(25, 75); //set text position 130 tft.print("HEAT: "); 131 tft.print(heat); 132 133 delay(5000); 134 135 // MQ Reading and updating section 136 MQ135.update(); // Update data, the arduino will be read the voltage on the analog pin 137 MQ135.setA(605.18); MQ135.setB(-3.937); // Configurate the ecuation values to get CO concentration 138 float CO = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 139 MQ135.setA(77.255); MQ135.setB(-3.18); // Configurate the ecuation values to get Alcohol concentration 140 float Alcohol = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 141 MQ135.setA(110.47); MQ135.setB(-2.862); // Configurate the ecuation values to get CO2 concentration 142 float CO2 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 143 MQ135.setA(44.947); MQ135.setB(-3.445); // Configurate the ecuation values to get Toluene concentration 144 float Toluene = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 145 MQ135.setA(102.2 ); MQ135.setB(-2.473); // Configurate the ecuation values to get NH4 concentration 146 float NH4 = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 147 MQ135.setA(34.668); MQ135.setB(-3.369); // Configurate the ecuation values to get Acetone concentration 148 float Acetone = MQ135.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup 149 150 tft.fillScreen(DISPLAY_ORANGE); 151 tft.setTextBackground(DISPLAY_ORANGE); 152 tft.setTextColor(DISPLAY_WHITE); 153 tft.drawCircle(0, 0, 64, DISPLAY_BLUE); 154 tft.drawCircle(0, 0, 63, DISPLAY_BLUE); 155 //Display CO, Alcohol, CO2, Toluene, NH4, Acetone 156 tft.setCursor(18, 25); //set text position 157 tft.print("AIR QUALITY DATA"); 158 159 Serial.print("CO: "); 160 Serial.println(CO); 161 dtostrf(CO, 2, 2, temp); 162 temp[5]=byte(0x20); 163 temp[6]='\\0'; 164 tft.setCursor(25, 40); //set text position 165 tft.print("CO : "); 166 tft.print(temp); 167 168 Serial.print("ALCOHOL: "); 169 Serial.println(Alcohol); 170 dtostrf(Alcohol, 2, 2, temp); 171 temp[5]=byte(0x20); 172 temp[6]='\\0'; 173 tft.setCursor(25, 50); //set text position 174 tft.print("ALCOHOL: "); 175 tft.print(temp); 176 177 Serial.print("CO2: "); 178 Serial.println(CO2); 179 dtostrf(CO2, 2, 2, temp); 180 temp[5]=byte(0x20); 181 temp[6]='\\0'; 182 tft.setCursor(25, 60); //set text position 183 tft.print("CO2 : "); 184 tft.print(temp); 185 186 Serial.print("TOLUENE: "); 187 Serial.println(Toluene); 188 dtostrf(Toluene, 2, 2, temp); 189 temp[5]=byte(0x20); 190 temp[6]='\\0'; 191 tft.setCursor(25, 70); //set text position 192 tft.print("TOLUENE: "); 193 tft.print(temp); 194 195 Serial.print("NH4: "); 196 Serial.println(NH4); 197 dtostrf(NH4, 2, 2, temp); 198 temp[5]=byte(0x20); 199 temp[6]='\\0'; 200 tft.setCursor(25, 80); //set text position 201 tft.print("NH4 : "); 202 tft.print(temp); 203 204 Serial.print("ACETONE: "); 205 Serial.println(Acetone); 206 dtostrf(Acetone, 2, 2, temp); 207 temp[5]=byte(0x20); 208 temp[6]='\\0'; 209 tft.setCursor(25, 90); //set text position 210 tft.print("ACETONE: "); 211 tft.print(temp); 212 213 delay(5000); 214 215} 216
Downloadable files
Sensor Station PDF
You can check the schematics and the connections from this file.
Sensor Station PDF
Comments
Only logged in users can leave comments
cstram
0 Followers
•0 Projects
Table of contents
Intro
14
0