Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define BLYNK_PRINT Serial
  2. #include <ESP8266WiFi.h>
  3. #include <BlynkSimpleEsp8266.h>
  4. #include <DHT.h>
  5.  
  6. int moisture;
  7. int percentage;
  8. int analogPin = A0;
  9. int map_low = 1000;
  10. int map_high = 250;
  11. int screen_type = 1;
  12.  
  13. // You should get Auth Token in the Blynk App.
  14. // Go to the Project Settings (nut icon).
  15. char auth[] = "X5Exdyiqw7MfwclUS5YDjc6ZaVeKtk3N";
  16.  
  17. // Your WiFi credentials.
  18. // Set password to "" for open networks.
  19. char ssid[] = "justpixit";
  20. char pass[] = "Pixit123";
  21.  
  22. #define DHTPIN D5          // D3
  23.  
  24. // Uncomment whatever type you're using!
  25. #define DHTTYPE DHT11     // DHT 11
  26. //#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
  27. //#define DHTTYPE DHT21   // DHT 21, AM2301
  28.  
  29. DHT dht(DHTPIN, DHTTYPE);
  30. BlynkTimer timer;
  31.  
  32. // This function sends Arduino's up time every second to Virtual Pin (5).
  33. // In the app, Widget's reading frequency should be set to PUSH. This means
  34. // that you define how often to send data to Blynk App.
  35. void sendSensor()
  36. {
  37.   float h = dht.readHumidity();
  38.   float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
  39.  
  40.  moisture = analogRead(analogPin);
  41.   percentage = map(moisture, map_low, map_high, 0, 100);
  42.  
  43.   if (isnan(h) || isnan(t)) {
  44.     Serial.println("Failed to read from DHT sensor!");
  45.     return;
  46.   }
  47.   // You can send any value at any time.
  48.   // Please don't send more that 10 values per second.
  49.   Blynk.virtualWrite(V1, t);
  50.   Blynk.virtualWrite(V2, h);
  51.   Blynk.virtualWrite(V3, percentage);
  52.   Serial.print("Temperature = ");
  53.   Serial.println(t);
  54.   Serial.print("Humidity = ");
  55.   Serial.println(h);
  56.   Serial.print("Moisture = ");
  57.   Serial.println(percentage);
  58. }
  59.  
  60. void setup()
  61. {
  62.   // Debug console
  63.   Serial.begin(9600);
  64.  
  65.   Blynk.begin(auth, ssid, pass);
  66.   // You can also specify server:
  67.   //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  68.   //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  69.  
  70.   dht.begin();
  71.  
  72.   // Setup a function to be called every second
  73.   timer.setInterval(3000L, sendSensor);
  74. }
  75.  
  76. void loop()
  77. {
  78.   Blynk.run();
  79.   timer.run();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement