Hi,
I just (finnaly) finished my Grow Box and wanna share it.
Hardware:
Wemos D1 mini Pro;
3 x DS18B20 One Wire Temperature Sensors;
SI70 - RH & Temp Sensor;
4 Relay module Board
1 TIPP31C for each Fan (For speed control)
Features:
Automatic lamps temperature (I used COB lights with a large radiator cooled by 2 12V fans);
Setting up the box temperature by large 12V fan that blows in air driven by a TIPP31C transistor;
Setting up the upper box temperature by a medium 12V fan that blows out the air driven by other transistor;
Setting up the RH inside the box with a piezo “mist maker”;
Setting up timers for light schedule;
Silent buttons for all the fans;
I will be more than glad for opinions and improvements. I must mention that I am at the very low knowledge of programming world so… I will really be happy if you can see something wrong or something that it could be better.
Thank you!
Code:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
//#define BLYNK_DEBUG
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SPI.h>
#include <Si7021.h>
#define ONE_WIRE_BUS 0 //Data wire plugged to pin (DS18B20 sensor)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
Si7021 si7021;
SimpleTimer timer;
//int test;
int ledsFanSilentModeButton;
int ledsTimerState;
int ledsTimer = 16; //Lamp relay pin for timer widget
int fanInPin = 13;
int fanOutPin = 12;
int boxFansTimerState;
int fanInSilentModeButton;
int fanOutSilentModeButton;
int inMinSetTemp;
int outMinSetTemp;
int humidifierPin = 14; //Humidifier relay pin
int rhSetValue;
char auth[] = "f427bbd267894a08bdd4219axxf46ab1"; //Put your Auth Token in the Blynk App here
char ssid[] = "Vecinu' de deasupra";
char pass[] = "individual";
WidgetLED onOffLedsLed(V20);
WidgetLED humidifierStateLed(V21);
BLYNK_WRITE(V0) {
ledsTimerState = param.asInt();
}
BLYNK_WRITE(V51) {
ledsFanSilentModeButton = param.asInt();
}
BLYNK_WRITE(V52) {
fanInSilentModeButton = param.asInt();
}
BLYNK_WRITE(V53) {
fanOutSilentModeButton = param.asInt();
}
BLYNK_WRITE(V40) {
inMinSetTemp = param.asInt();
}
BLYNK_WRITE(V41) {
outMinSetTemp = param.asInt();
}
BLYNK_WRITE(V42) {
rhSetValue = param.asInt();
}
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass); //insert here your SSID and password
sensors.begin(); //DS18B20 temp. sensors
si7021.begin();
sensors.setResolution(10); //More on resolution: http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/
timer.setInterval(1000, readTemps); //DS18B20 Data reading interval
pinMode(ledsTimer, OUTPUT);
pinMode(fanInPin, OUTPUT);
pinMode(fanOutPin, OUTPUT);
pinMode(humidifierPin, OUTPUT);
Blynk.syncVirtual(V0, V51, V52, V53, V20, V40, V41, V42);
}
void readTemps() {
sensors.requestTemperatures();
float ledTemp = sensors.getTempCByIndex(0); //Stores temperature. Change to getTempFByIndex(0) for F.
float tempTavan = sensors.getTempCByIndex(1);
float tempDataLogger = sensors.getTempCByIndex(2);
float boxTemp = si7021.getTemperatureFromPreviousHumidityMeasurement();
float boxRH = si7021.measureHumidity();
Blynk.virtualWrite(V1, tempTavan); //DS18B20 temperatures
Blynk.virtualWrite(V2, ledTemp);
Blynk.virtualWrite(V3, tempDataLogger);
Blynk.virtualWrite(V4, boxRH);
Blynk.virtualWrite(V5, boxTemp);
//------------PWM Global Fans automatic Settings-------------//
int ledsFanPin = 15;
const int fanSpeedOff = 0;
const int fanSpeedIdle = 60;
const int fanSpeed20 = 100;
const int fanSpeed40 = 200;
const int fanSpeed60 = 400;
const int fanSpeed80 = 800;
const int fanSpeed100 = 1024;
int ledsFanCtrlTemp;
int inFanCtrlTemp;
int outFanCtrlTemp;
//-----------Leds Timer-----------//
if (ledsTimerState == 1) {
digitalWrite(ledsTimer, HIGH);
onOffLedsLed.on();
} else {
digitalWrite(ledsTimer, LOW);
onOffLedsLed.off();
}
//-----Leds Fan silent Mode button-----//
if (ledsFanSilentModeButton) {
ledsFanCtrlTemp = 15;
} else {
ledsFanCtrlTemp = ledTemp;
}
//-------Fan in Silent Mode button------//
if (fanInSilentModeButton == 1) {
inFanCtrlTemp = 15;
} else {
inFanCtrlTemp = boxTemp;
}
//------Fan Out Silent Mode Button------//
if (fanOutSilentModeButton == 1) {
outFanCtrlTemp = 15;
} else {
outFanCtrlTemp = tempTavan;
}
//---------------LED fan automatic control------------------//
if (ledsFanCtrlTemp <= 30) {
analogWrite(ledsFanPin, fanSpeedOff);
Blynk.virtualWrite(V30, "OFF");
}
else if (ledsFanCtrlTemp == 33) {
analogWrite(ledsFanPin, fanSpeedIdle);
Blynk.virtualWrite(V30, "IDLE");
}
else if (ledsFanCtrlTemp == 35) {
analogWrite(ledsFanPin, fanSpeed20);
Blynk.virtualWrite(V30, "20%");
}
else if (ledsFanCtrlTemp == 37) {
analogWrite(ledsFanPin, fanSpeed40);
Blynk.virtualWrite(V30, "40%");
}
else if (ledsFanCtrlTemp == 40) {
analogWrite(ledsFanPin, fanSpeed60);
Blynk.virtualWrite(V30, "60%");
}
else if (ledsFanCtrlTemp == 45) {
analogWrite(ledsFanPin, fanSpeed80);
Blynk.virtualWrite(V30, "80%");
}
else if (ledsFanCtrlTemp >= 50) {
analogWrite(ledsFanPin, fanSpeed100);
Blynk.virtualWrite(V30, "100%");
}
//-----------------Fan In automatic control-------------------//
if (inFanCtrlTemp < inMinSetTemp) {
analogWrite(fanInPin, fanSpeedOff);
Blynk.virtualWrite(V31, "OFF");
}
else if (inFanCtrlTemp == inMinSetTemp) {
analogWrite(fanInPin, fanSpeedIdle);
Blynk.virtualWrite(V31, "IDLE");
}
else if (inFanCtrlTemp == inMinSetTemp + 1) {
analogWrite(fanInPin, 512);
Blynk.virtualWrite(V31, "50%");
}
else if (inFanCtrlTemp >= inMinSetTemp + 2) {
analogWrite(fanInPin, 1023);
Blynk.virtualWrite(V31, "100%");
}
//--------------------Fan Out Automatic Control-----------------//
if (outFanCtrlTemp < outMinSetTemp) {
analogWrite(fanOutPin, fanSpeedOff);
Blynk.virtualWrite(V32, "OFF");
}
else if (outFanCtrlTemp == outMinSetTemp) {
analogWrite(fanOutPin, 19);
Blynk.virtualWrite(V32, "IDLE");
}
else if (outFanCtrlTemp == outMinSetTemp + 1) {
analogWrite(fanOutPin, 40);
Blynk.virtualWrite(V32, "50%");
}
else if (outFanCtrlTemp >= outMinSetTemp + 2) {
analogWrite(fanOutPin, fanSpeed20);
Blynk.virtualWrite(V32, "80%");
}
//--------------------RH Automatic Control---------------------//
if (rhSetValue > boxRH) {
digitalWrite(humidifierPin, HIGH);
humidifierStateLed.on();
}else{
digitalWrite(humidifierPin, LOW);
humidifierStateLed.off();
}
}
void loop() {
Blynk.run();
timer.run();
}
Pictures: