-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesp8266.ino
50 lines (37 loc) · 1.03 KB
/
esp8266.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
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define DHTTYPE DHT11
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include "DHT.h"
SimpleTimer timer;
// Token generated by Blynk app
char auth[] = "token_from_Blynk";
// PINS
int RELAY = 12;
int DHT_PIN = 16;
// Initialize DHT sensor.
DHT dht(DHT_PIN, DHTTYPE);
void sendDHT() {
//Read the Temp and Humidity from DHT
int t = (int) dht.readTemperature();
int h = (int) dht.readHumidity();
Blynk.virtualWrite(1, t);
Blynk.virtualWrite(2, h);
}
void setup() {
Serial.begin(115200);
Serial.println("*** ESP8266 Remote Control Fimware ***");
Serial.println("%\t Begin Connection...%\n");
timer.setInterval(2000, sendDHT);
dht.begin();
// Replace "ssid" and "pwd" with the credential of the wifi in which you you want to log into
Blynk.begin(auth, "ssid", "pwd");
pinMode(RELAY, OUTPUT);
pinMode(LIGHT,OUTPUT);
}
void loop() {
digitalWrite(LIGHT, HIGH);
Blynk.run();
timer.run();
}