Skip to content

Instantly share code, notes, and snippets.

@anoochit
Last active November 29, 2023 19:41
Show Gist options
  • Save anoochit/d9ab7220794283b104f8 to your computer and use it in GitHub Desktop.
Save anoochit/d9ab7220794283b104f8 to your computer and use it in GitHub Desktop.
esp8266-dht22-blynk
/*
* This sketch demonstrates how to scan WiFi networks.
* The API is almost the same as with the WiFi Shield library,
* the most obvious difference being the different file you need to include:
*/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 12
#define DHTTYPE DHT22
DHT_Unified dht(DHTPIN, DHTTYPE);
char auth[] = "xxxxxxxxxx";
SimpleTimer timer;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "xxxxxx", "yyyyyy");
dht.begin();
// Setup a function to be called every second
timer.setInterval(5000L, sendUptime);
}
void sendUptime()
{
Blynk.virtualWrite(V5, millis() / 1000);
sensors_event_t event;
dht.temperature().getEvent(&event);
if (!isnan(event.temperature)) {
Blynk.virtualWrite(V1, event.temperature);
}
dht.humidity().getEvent(&event);
if (!isnan(event.relative_humidity)) {
Blynk.virtualWrite(V2, event.relative_humidity);
}
}
void loop()
{
Blynk.run();
timer.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment