Hello to everyone,
I know it is not a big deal what the title says but I have ZERO knowledge about programming but I still love this systems and trying to do something…
So I have terrarium and I want to turn on of lights and misting shower. All nice, I found a great instructables at http://www.instructables.com/id/TerraControl-V30-ESP8266-BLYNK/
I modified a code a little so it fits my needs and it works nice. Also programmed timer with inventor.
But I don’t know how to prevent runing water pump if there is no water in a tank.
I search a lot for something similar but didn’t find what I would recognize as usable for me-my knowledge.
I would really appreciate if some nice guy could help me on modifying code
I have NodeMCU ESP-E12
What I would like to do is that when red LED - named Voda, is on (water alarm) water pump is not allowed to start.
Here we can see it is connected to virtual pin6
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial
/*------------------ YOUR WIFI AND BLYNK SETTINGS ------------------*/
const char ssid[] = "xxxxx";
const char pass[] = "xxxx";
char auth[] = "xxxxx";
/*------------------ DEFINE DHT SENSOR PIN ------------------*/
#define SENSOR_IN D6
#define SENSOR_IN_Type DHT22
#define SENSOR2_IN D7
#define SENSOR2_IN_Type DHT22
const int sensorPin= A0; //sensor pin connected to analog pin A0
/*------------------ DEFINE RELAY PINS ------------------*/
#define relayLight D1
#define relayPump D2
//#define relayFan D9 //RX pin on NodeMCU
//#define relayHeat2 D5
/*---------- OTHER ----------*/
float humIN, tempIN;
DHT dht_IN(SENSOR_IN, SENSOR_IN_Type);
float hum2IN, temp2IN;
DHT dht2_IN(SENSOR2_IN, SENSOR2_IN_Type);
SimpleTimer timer;
float liquid_level;
int liquid_percentage;
int top_level = 600;//Maximum water level
int bottom_level = 6;//Minimum water level
/*---------- SYNC ALL SETTINGS ON BOOT UP ----------*/
bool isFirstConnect = true;
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
isFirstConnect = false;
}
}
/*---------- LIGHT CONTROL ----------*/
BLYNK_WRITE(V10)
{
if (param.asInt()) {
digitalWrite(D1, LOW);
Blynk.virtualWrite(V0, 255);
} else {
digitalWrite(D1, HIGH);
Blynk.virtualWrite(V0, 0);
}
}
/*---------- PUMP CONTROL ----------*/
BLYNK_WRITE(V11)
{
if (param.asInt()) {
digitalWrite(D2, LOW);
Blynk.virtualWrite(V1, 255);
} else {
digitalWrite(D2, HIGH);
Blynk.virtualWrite(V1, 0);
}
}
// /*---------- HEAT2 CONTROL ----------*/
//BLYNK_WRITE(V12)
//{
// if (param.asInt()) {
// digitalWrite(D5, LOW);
// Blynk.virtualWrite(V2, 255);
// } else {
// digitalWrite(D5, HIGH);
// Blynk.virtualWrite(V2, 0);
// }
//}
// /*---------- FAN CONTROL ----------*/
//BLYNK_WRITE(V13)
//{
// if (param.asInt()) {
// digitalWrite(D9, LOW);
// Blynk.virtualWrite(V3, 255);
// } else {
// digitalWrite(D9, HIGH);
// Blynk.virtualWrite(V3, 0);
// }
//}
/*----------READ DHT SENSOR ----------*/
void sensorRead() {
tempIN = dht_IN.readTemperature();
humIN = dht_IN.readHumidity();
temp2IN = dht2_IN.readTemperature();
hum2IN = dht2_IN.readHumidity();
Blynk.virtualWrite(V8, tempIN);
Blynk.virtualWrite(V9, humIN);
Blynk.virtualWrite(V12, temp2IN);
Blynk.virtualWrite(V13, hum2IN);
Blynk.virtualWrite(V4, liquid_level); //Virtualni pin za nivo vode direktna vrednost
Blynk.virtualWrite(V5, liquid_percentage);//This wil show the percentage of water in the container in a virtual pin V1
// Blynk.run();
}
void setup()
{
Blynk.begin(auth, ssid, pass);
Blynk.notify("Terarij uspesno povezan v: " + String(ssid));
pinMode(relayLight, OUTPUT);
pinMode(relayPump, OUTPUT);
pinMode(sensorPin, INPUT);
// pinMode(relayFan, OUTPUT);
// pinMode(relayHeat2, OUTPUT);
timer.setInterval(1000L, sensorRead);
}
void loop()
{
liquid_level = analogRead(sensorPin);
liquid_percentage = ((liquid_level-bottom_level)/top_level)*100;//Percentage of water in the container
Serial.println(liquid_level);//This will print the liquid level in the monitor
Serial.println(liquid_percentage);//This will print the percentage of liquid in the monitor
Blynk.virtualWrite(V4, liquid_level);
Blynk.virtualWrite(V5, liquid_percentage);
delay(100);
Blynk.run();
timer.run();
}