-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coldstorage.ino
101 lines (100 loc) · 3.09 KB
/
Coldstorage.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <DHT.h>
const char *ssid = ""; // Enter your WiFi Name
const char *pass = ""; // Enter your WiFi Password
#define DHTPIN D1 // GPIO Pin where the dht11 is connected
#define relay D2
#define solenoid D0
#define buzzer D4
DHT dht(DHTPIN, DHT11);
WiFiClient client;
float h;
float t;
float leakage = 0;
int smokeSensorPin = A0; // Analog input pin for smoke sensor
unsigned int sensorValue; // Variable to store sensor reading
// Variable to store sensor voltage
// Parts per million of gas concentration
unsigned int outputValue;
void setup()
{
Serial.begin(9600);
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,LOW);
pinMode(relay,OUTPUT);
digitalWrite(relay, LOW);
pinMode(solenoid,OUTPUT);
digitalWrite(solenoid, LOW);
delay(100);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
h = dht.readHumidity(); // read humidity
t = dht.readTemperature(); // read temperature
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" °C, Humidity: ");
Serial.print(h);
Serial.println(" %");
Serial.println("Ammonia in ppm:");
sensorValue = analogRead(smokeSensorPin); // Read sensor value
outputValue = map(sensorValue,0,1023,0,255);
Serial.println(outputValue);
if(outputValue>=130){
digitalWrite(buzzer,HIGH);
leakage=1;
}
if(outputValue<130){
digitalWrite(buzzer,LOW);
leakage=0;
}
delay(1000); // Wait for 1 second
if(h>45){
Serial.println("Chamber Humidity is High");
Serial.println("Compressor pump is OFF");
Serial.println("Ammonia valve is closed");
digitalWrite(relay, HIGH);
digitalWrite(solenoid, HIGH);
delay(10000);
}
if(h<=45){
Serial.println("Chamber Humidity is Low");
Serial.println("Compressor pump is ON");
Serial.println("Ammonia valve is open");
digitalWrite(relay, LOW);
digitalWrite(solenoid, LOW);
delay(10000);
}
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
unsigned long currentMillis = millis(); // grab current time
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
String url = "http://.com/api.php?ammonia=" + String(outputValue) + "&leakage=" + String(leakage)+ "&humidity=" + String(h) + "&temperature=" + String(t);
Serial.println(url);
http.begin(client, url); //Specify request destination
delay(5000);
int httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
Serial.println(payload); //Print the response payload
}
http.end(); //Close connection
}
}