SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <ESP8266WiFi.h> | |
| 2 | - | /* Comment this out to disable prints and save space */ |
| 2 | + | |
| 3 | - | #define BLYNK_PRINT Serial |
| 3 | + | |
| 4 | ||
| 5 | #define BLYNK_PRINT Serial // Comment this out to disable prints and save space | |
| 6 | ||
| 7 | // You should get Auth Token in the Blynk App. | |
| 8 | // Go to the Project Settings (nut icon). | |
| 9 | char auth[] = "xxxxxxxxxx"; | |
| 10 | ||
| 11 | ||
| 12 | // Your WiFi credentials. | |
| 13 | // Set password to "" for open networks. | |
| 14 | char ssid[] = "xxxx"; | |
| 15 | char pass[] = "xxxx"; | |
| 16 | ||
| 17 | ||
| 18 | #define DHTPIN 4 // What digital pin we're connected to | |
| 19 | #define DHTTYPE DHT11 // DHT 22, AM2302, AM2321 | |
| 20 | ||
| 21 | DHT dht(DHTPIN, DHTTYPE); | |
| 22 | BlynkTimer timer; | |
| 23 | ||
| 24 | // MW: Declare variable out here so they can be accessed in other sub-function, such as checkDelayTimer. I think if you declare them inside the sub-function it is only accessible there. So these would be called global variables. | |
| 25 | float h = 0; | |
| 26 | float t = 0; | |
| 27 | int delayCountdown = 0; // Use this for countdown timing | |
| 28 | ||
| 29 | void sendSensor() | |
| 30 | {
| |
| 31 | h = dht.readHumidity(); | |
| 32 | t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit | |
| 33 | ||
| 34 | Serial.print(t); | |
| 35 | Serial.print(h); | |
| 36 | ||
| 37 | // You can send any value at any time. | |
| 38 | // Please don't send more that 10 values per second. | |
| 39 | Blynk.virtualWrite(V5, t); | |
| 40 | Blynk.virtualWrite(V6, h); | |
| 41 | ||
| 42 | if ( (t > 30) && (delayCountdown == 0) ) | |
| 43 | {
| |
| 44 | delayCountdown = 60; | |
| 45 | digitalWrite(5, LOW); | |
| 46 | Blynk.virtualWrite(V2, LOW); | |
| 47 | - | Blynk.virtualWrite(V5, t); |
| 47 | + | |
| 48 | - | Blynk.virtualWrite(V6, h); |
| 48 | + | |
| 49 | if (delayCountdown == 1) // slutet av den aktiva fasen | |
| 50 | - | void checkTemp() |
| 50 | + | |
| 51 | digitalWrite(5, HIGH); | |
| 52 | - | if ( (t > 30) && (delayCountdown == 0) ); |
| 52 | + | |
| 53 | delayCountdown = 0; // tillbaka till startläge | |
| 54 | } | |
| 55 | ||
| 56 | if (delayCountdown > 0) | |
| 57 | {
| |
| 58 | delayCountdown--; | |
| 59 | } | |
| 60 | - | if (delayCountdown == 1); |
| 60 | + | |
| 61 | ||
| 62 | void setup() | |
| 63 | {
| |
| 64 | // Debug console | |
| 65 | Serial.begin(9600); | |
| 66 | - | if (delayCountdown > 0); |
| 66 | + | |
| 67 | dht.begin(); // Start DHT22 communication | |
| 68 | ||
| 69 | // Setup a function to be called every second | |
| 70 | timer.setInterval(1000L, sendSensor); | |
| 71 | ||
| 72 | pinMode (5, OUTPUT); | |
| 73 | } | |
| 74 | ||
| 75 | BLYNK_WRITE(V2) {
| |
| 76 | int buttonState = param.asInt(); | |
| 77 | digitalWrite(13, buttonState); // Just do manual on and off here | |
| 78 | } | |
| 79 | ||
| 80 | void loop() | |
| 81 | {
| |
| 82 | Blynk.run(); | |
| 83 | - | timer.setInterval(1000L, checkTemp); // MW: Check temp and how much time has passed every second so we don't block the main loop from running |
| 83 | + | |
| 84 | } |