Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- #include <DHT.h>
- int moisture;
- int percentage;
- int analogPin = A0;
- int map_low = 1000;
- int map_high = 250;
- int screen_type = 1;
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "X5Exdyiqw7MfwclUS5YDjc6ZaVeKtk3N";
- // Your WiFi credentials.
- // Set password to "" for open networks.
- char ssid[] = "justpixit";
- char pass[] = "Pixit123";
- #define DHTPIN D5 // D3
- // Uncomment whatever type you're using!
- #define DHTTYPE DHT11 // DHT 11
- //#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
- //#define DHTTYPE DHT21 // DHT 21, AM2301
- DHT dht(DHTPIN, DHTTYPE);
- BlynkTimer timer;
- // This function sends Arduino's up time every second to Virtual Pin (5).
- // In the app, Widget's reading frequency should be set to PUSH. This means
- // that you define how often to send data to Blynk App.
- void sendSensor()
- {
- float h = dht.readHumidity();
- float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
- moisture = analogRead(analogPin);
- percentage = map(moisture, map_low, map_high, 0, 100);
- if (isnan(h) || isnan(t)) {
- Serial.println("Failed to read from DHT sensor!");
- return;
- }
- // You can send any value at any time.
- // Please don't send more that 10 values per second.
- Blynk.virtualWrite(V1, t);
- Blynk.virtualWrite(V2, h);
- Blynk.virtualWrite(V3, percentage);
- Serial.print("Temperature = ");
- Serial.println(t);
- Serial.print("Humidity = ");
- Serial.println(h);
- Serial.print("Moisture = ");
- Serial.println(percentage);
- }
- void setup()
- {
- // Debug console
- Serial.begin(9600);
- Blynk.begin(auth, ssid, pass);
- // You can also specify server:
- //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
- //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
- dht.begin();
- // Setup a function to be called every second
- timer.setInterval(3000L, sendSensor);
- }
- void loop()
- {
- Blynk.run();
- timer.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement