-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIot Code.txt
63 lines (53 loc) · 1.6 KB
/
Iot Code.txt
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
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ThingSpeak.h>
#include "DHTesp.h"
#define DHTpin 2
const char* ssid = "lol";
const char* password = "WILLVASA";
DHTesp dht;
WiFiClient client;
int dryValue = 0;
int wetValue = 1023;
int friendlyDryValue = 0;
int friendlyWetValue = 100;
const int analogpin = A0; // Analog input pin that the soil moisture sensor is attached to
int sensorValueA; // store sensor input value
void setup()
{
Serial.begin(115200);
// pinMode(analogpin, INPUT);
delay(10);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Print the IP address
Serial.println(WiFi.localIP());
pinMode(analogpin, INPUT);
dht.setup(DHTpin, DHTesp::DHT11); //for DHT11 Connect DHT sensor to GPIO
ThingSpeak.begin(client);
}
void loop()
{
sensorValueA = analogRead(analogpin); //Soil moisture.
float humidity = dht.getHumidity(); //humidity
float temperature = dht.getTemperature(); //temperature
\
int friendlyValue = map(sensorValueA , dryValue, wetValue, friendlyDryValue, friendlyWetValue);
//Uploading to thingspeak
ThingSpeak.setField(3, temperature);
ThingSpeak.setField(2, humidity);
ThingSpeak.setField(1, abs(friendlyValue-100));
ThingSpeak.writeFields(632047 ,"FLCHQXJX2RAPXHV8");
delay(300);
}