Wemos D1 Humidity-Moisture Fan Control

In the Morning a think about the Moisture in our Bathroom.

Why buy a ready Product for 30-50 € or $. I have a DHT22 and any Fan of old PC´s.

Its simple to Coding, on Cayenne Dashboard is the Temperature, Humidity and the State of the Fan.

On the Board its just one LED to show if the Fan is working or not.

Hardware you need

1 Wemos or else with WIFI

1 DHT22 or similar

1 Fan

1 Resistor

1 LED

The Code

Blockquote

#include <CayenneMQTTESP8266.h>
#include “DHT.h”
#define DHTPIN 5
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

// WiFi network info.
char ssid = “i";
char wifiPassword[] = "
*”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “***";
char password[] = "";
char clientID[] = "
”;
unsigned long lastMillis = 0;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
dht.begin();
pinMode(4, OUTPUT);
digitalWrite(4, LOW);

}

void loop() {

Cayenne.loop();

delay(1000);
float h = dht.readHumidity();
float t = dht.readTemperature();

Cayenne.virtualWrite(2, h, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
Cayenne.virtualWrite(3, t, TYPE_TEMPERATURE, UNIT_CELSIUS);

if (isnan(h) || isnan(t)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
{
if (h > 45.00) (digitalWrite(4, HIGH)), Cayenne.virtualWrite(1, 1, “digital_sensor”, “d”);

else (digitalWrite(4, LOW)), Cayenne.virtualWrite(1, 0, "digital_sensor", "d");

}

// show in serial monitor
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t”);
Serial.print(“Temperature: “);
Serial.print(t);
Serial.print(” *C \n”);
delay(500);
}

I honestly hope each and every one of you have the best year ever in New Year :sparkler::fireworks::earth_africa:

2 Likes

A good project for the new year! Thanks for sharing @Sven. We all love seeing these.

~Benny

Nice project!