#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6EgypHU1j"
#define BLYNK_TEMPLATE_NAME "DHT Potentiometer"
#define BLYNK_AUTH_TOKEN "oNjTXHR9Jamm0LyG_MNx36CB7ReUzKBJ"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>;
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define DHTPIN 0 // What digital pin we're connected to
#define analogPin 12 //tesitng using potentionmeter
// Uncomment whatever type you're using!
#define DHTTYPE DHT22 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
// reading value from potentiometer at analog pin
void readAnalogPin()
{
int val = analogRead(analogPin);
Blynk.virtualWrite(V12, val); // potentiometer value
Serial.println(val);
}
// This function sends Arduino's up time every second to Virtual Pin (0,1,2,3).
// 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.
// Set function calling frequency at timer.setInterval()
void sendSensor()
{
int h = dht.readHumidity();
int t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println(F("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(V0, h); // Humidity for display
Blynk.virtualWrite(V1, t); // Temperature for display
Blynk.virtualWrite(V2, h); // Humidity for gauge
Blynk.virtualWrite(V3, t); // Temperature for gauge
//for debugging
Serial.println(h);
Serial.println(t);
}
void setup()
{
// Setup software serial for debug console
pinMode(analogPin,INPUT);
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
dht.begin(); //setup dht sensor
// Setup a function to be called every second.
// Each timer can be use to call multiple functions
timer.setInterval(2000L, sendSensor);
//timer.setInterval(1000L, readAnalogPin);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}