Advertisement
mikroavr

dht22_server_code

Feb 7th, 2022
2,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. #include "DHT.h"
  4. #define DHTPIN 32
  5. #define DHTTYPE DHT22
  6. DHT dht(DHTPIN, DHTTYPE);
  7. unsigned long cur_time, old_time;
  8.  
  9. int ledState = LOW;
  10. const byte pin_set = 18;
  11. const byte pin_pln = 33;
  12. const byte pin_key = 12;
  13.  
  14. #define BLYNK_PRINT Serial
  15. #include <WiFi.h>
  16. #include <WiFiClient.h>
  17. #include <BlynkSimpleEsp32.h>
  18.  
  19. char auth[] = "ll9Ckm9Q3hQFzqA3sVlNFtuZFZ91qXKw";
  20. char ssid[] = "your_wifi_ssid";
  21. char pass[] = "your_pass_wifi";
  22.  
  23. void setup() {
  24.   pinMode(16, OUTPUT);
  25.   pinMode(17, OUTPUT);
  26.   pinMode(pin_key, OUTPUT);
  27.   digitalWrite(pin_key, HIGH);
  28.   pinMode(pin_set, INPUT_PULLUP);
  29.   pinMode(pin_pln, INPUT_PULLUP);
  30.  
  31.   Serial.begin(115200);
  32.   Serial.println();
  33.   dht.begin();
  34.   Blynk.begin(auth, ssid, pass);
  35. }
  36.  
  37. void loop() {
  38. Blynk.run();
  39.   cur_time = millis();
  40.   if (cur_time - old_time >= 1000) {
  41.      if (ledState == LOW) {
  42.       ledState = HIGH;
  43.     } else {
  44.       ledState = LOW;
  45.     }
  46.     digitalWrite(16,ledState);
  47.     digitalWrite(17,!ledState);
  48.    
  49.     float h = dht.readHumidity();
  50.     float t = dht.readTemperature();
  51.     Blynk.virtualWrite(V0, h);
  52.     Blynk.virtualWrite(V1, t);
  53.      
  54.     Serial.print("suhu: ");
  55.     Serial.println(t);
  56.     Serial.print("humiity: ");
  57.     Serial.println(h);
  58.    
  59.     Serial.print("set: ");
  60.     Serial.println(digitalRead(pin_set));
  61.     Serial.print("pln status: ");
  62.     Serial.println(digitalRead(pin_pln));
  63.  
  64.     Blynk.virtualWrite(V3, digitalRead(pin_pln));
  65.          
  66.     old_time = millis();
  67.   }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement