Hi Guys,
I have been doing alot more research and am trying to get my project full operational. My code is as follows:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define DHTPIN 12
#define DHTTYPE DHT22
//Constants
const int airPump = 9;
const int hygrometer = 12;
//Variables
int value;
char auth[] = "************";
SimpleTimer timer;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "ssid", "pass!");
timer.setInterval(1000L, sendUptime);
pinMode(airPump,OUTPUT);
}
void sendUptime()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(10, t); // virtual pin
Blynk.virtualWrite(11, h); // virtual pin
}
void loop()
{
value = analogRead(hygrometer); //Read analog value
value = constrain(value,400,1023); //Keep the ranges!
value = map(value,400,1023,100,0); //Map value : 400 will be 100 and 1023 will be 0
if (value < 50){
digitalWrite(airPump,HIGH);
}
else {
digitalWrite(airPump,LOW);
}
delay(150); //small delay
Blynk.run();
timer.run();
}
I am trying to be able to read temperature and humidity from my phone but also auto trigger a pump through a relay if humidity reaches below 50%. i cant seem to get it right, i think it might be reading temperature instead of humidity, how do i separate the two? What have i done wrong?
Parts:
ESP8266 Sparkfun Thing Dev
DHT22
using a led just to see if it works and it is but wont shut off if above 50%.