-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAtmega.ino
81 lines (62 loc) · 1.38 KB
/
Atmega.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Including the libraries
#include <dht.h>
#include <MQ2.h>
#include "MQ135.h"
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <ArduinoJson.h>
// Defining pins and creating objects
#define DHT22PIN 7
dht DHT;
MQ2 mq2(A0);
MQ135 mq135(A1);
Adafruit_BMP085 bmp180;
// Setup function
void setup() {
Serial.begin(115200);
mq2.begin();
bmp180.begin();
}
// Declaring variables
float temperature, humidity, co2, lpg, pressure;
// Loop function
void loop() {
DHT.read22(DHT22PIN);
// Calling functions
temperature = readTemperature();
humidity = readHumidity();
co2 = readCO2();
lpg = readLPG();
pressure = readPressure();
// Create a StaticJsonDocument
StaticJsonDocument<40> jsonDoc;
// Assign values to the JSON document
jsonDoc["temperature"] = temperature;
jsonDoc["humidity"] = humidity;
jsonDoc["co2"] = co2;
jsonDoc["lpg"] = lpg;
jsonDoc["pressure"] = pressure;
// Serialize the JSON document to a string
String dataString;
serializeJson(jsonDoc, dataString);
// Print the JSON string
Serial.println(dataString);
// 1 second delay
delay(1000);
}
// Functions to read data from the sensors
float readTemperature() {
return DHT.temperature;
}
float readHumidity() {
return DHT.humidity;
}
float readCO2() {
return mq135.getPPM();
}
float readLPG() {
return mq2.readLPG();
}
float readPressure() {
return bmp180.readPressure();
}