1#include <LiquidCrystal_I2C.h>
2#include <SoftwareSerial.h>
3#include <dht.h>
4#include <Wire.h>
5#include <BMP180.h>
6dht DHT;
7LiquidCrystal_I2C lcd(0x27, 16, 2);
8SoftwareSerial mySerial(10, 11);
9BMP180 myBMP(BMP180_ULTRAHIGHRES);
10#define DHT11_PIN A0
11#define mq135_pin A2
12#define LDR A1
13void ReadDHT(void);
14void ReadBMP(void);
15void ReadAir(void);
16void send_data(void);
17bool BMP_flag = 0;
18bool DHT_flag = 0;
19
20
21void setup()
22{
23 mySerial.begin(115200);
24 pinMode(mq135_pin, INPUT);
25 pinMode(LDR, INPUT);
26 lcd.init();
27 lcd.backlight();
28 lcd.setCursor(0, 0);
29 lcd.print(" IoT Weather ");
30 lcd.setCursor(0, 1);
31 lcd.print("Monitor System");
32 delay(1500);
33}
34
35void loop()
36{
37 ReadDHT();
38 ReadBMP();
39 ReadAir();
40 Readlight();
41 send_data();
42}
43
44void ReadDHT(void)
45{
46 lcd.clear();
47 int chk = DHT.read11(DHT11_PIN);
48 switch (chk)
49 {
50 case DHTLIB_OK:
51 DHT_flag = 1;
52 lcd.setCursor(0, 0);
53 lcd.print("Temp: ");
54 lcd.print(DHT.temperature, 1);
55 lcd.print(" *C");
56 lcd.setCursor(0, 1);
57 lcd.print("Humi: ");
58 lcd.print(DHT.humidity, 1);
59 lcd.print(" %");
60 break;
61 case DHTLIB_ERROR_CONNECT:
62 lcd.setCursor(0, 0);
63 lcd.print("NO DHT11 SENSOR");
64 lcd.setCursor(0, 1);
65 lcd.print(" FOUND! ");
66 break;
67 case DHTLIB_ERROR_CHECKSUM:
68 case DHTLIB_ERROR_TIMEOUT:
69 case DHTLIB_ERROR_ACK_L:
70 case DHTLIB_ERROR_ACK_H:
71 default:
72 DHT_flag = 0;
73 lcd.setCursor(0, 0);
74 lcd.print(" DHT11 SENSOR ");
75 lcd.setCursor(0, 1);
76 lcd.print(" ERROR ");
77 break;
78 }
79 delay(2000);
80}
81
82void ReadBMP(void)
83{
84 lcd.clear();
85 if (myBMP.begin() != true)
86 {
87 lcd.setCursor(0, 0);
88 lcd.print(" BMP180 SENSOR ");
89 lcd.setCursor(0, 1);
90 lcd.print(" NOT FOUND ");
91 BMP_flag = 0;
92 delay(2000);
93 }
94 else
95 {
96 BMP_flag = 1;
97 lcd.setCursor(0, 0);
98 lcd.print("Pa(Grnd):");
99 lcd.print(myBMP.getPressure());
100 lcd.setCursor(0, 1);
101 lcd.print("Pa(sea) :");
102 lcd.print(myBMP.getSeaLevelPressure(115));
103 }
104 delay(2000);
105}
106
107void ReadAir(void)
108{
109 int airqlty = 0;
110 lcd.clear();
111 lcd.setCursor(0, 0);
112 lcd.print("AIR QUALITY:");
113 airqlty = analogRead(mq135_pin);
114 lcd.print(map(analogRead(mq135_pin), 0, 1024, 99, 0));
115 lcd.print("%");
116 lcd.setCursor(0, 1);
117 if (airqlty <= 180)
118 lcd.print("GOOD!");
119 else if (airqlty > 180 && airqlty <= 225)
120 lcd.print("POOR");
121 else if (airqlty > 225 && airqlty <= 300)
122 lcd.print("VERY BAD");
123 else
124 lcd.print("TOXIC");
125 delay(2000);
126}
127
128void Readlight(void)
129{
130 lcd.clear();
131 lcd.setCursor(3, 0);
132 lcd.print("LIGHT :");
133 lcd.print(map(analogRead(LDR), 0, 1024, 0, 99));
134 lcd.print("%");
135 lcd.setCursor(0, 1);
136 lcd.print("****************");
137 delay(2000);
138}
139
140void send_data()
141{
142 mySerial.print('*');
143 if (DHT_flag == 1)
144 {
145 mySerial.print(DHT.temperature, 0);
146 mySerial.print(DHT.humidity, 0);
147 }
148 else
149 {
150 mySerial.print("0000");
151 }
152 if (BMP_flag == 1)
153 {
154 mySerial.print(myBMP.getPressure());
155 }
156 else
157 {
158 mySerial.print("00000");
159 }
160 mySerial.print(map(analogRead(LDR), 0, 1024, 0, 99));
161 mySerial.print(map(analogRead(mq135_pin), 0, 1024, 99, 0));
162 mySerial.println('#');
163}
sharu2005
6 months ago
Hi The above given code is giving error even though we included all libraries. Can u please help with it.