I think it’s important that i start out explaining a little about my project, so i am currently designing a cheap, reliable hydroponics system, i’m planning on making it all open source when it’s done.
but i needed a micro-controller for the watering system, and possible future additions, i have a some basic understanding about how code works, but it’s very limited and basic, i had literally no idea what i was doing, but i wrote the code below took me 5 hours to look through the community for my desired functions and get something that worked so bear with me it’s a mess.
i tried commenting the functions that i understand, to help myself in the future and to show you guys what i understand of the code
as you see in the code i uncommented all the DHT sensor stuff, because that’s what’s been annoying me i got all the other code working, but now i can’t get the DHT sensor written in there, any feedback on my code, what am i doing wrong, is it formatting, or simply a question of how i’m placing my code, also i’m experiencing connection issues with the app?
appreciate all help <3
//Defining Pins and Serial
#define BLYNK_PRINT Serial //Defines using the Blynk print serial function, and send commands to the Serial Monitor
//#define DHTPIN 1 //Defines what Pin the DHT Sensor is using
//#define DHTTYPE DHT11 //Defines which type of DHT Sensor is used
//Including libraries
#include <ESP8266WiFi.h> //Including the ESP8255WiFi Library
#include <BlynkSimpleEsp8266.h> //Including the BlynkSimpleEsp8266 Library
//#include <DHT.h> //Including the DHT Library
//Userinformation
char auth[] = "*************************************"; //Authentication code
char ssid[] = "***********"; //WiFi SSID
char pass[] = "**********"; //WiFI Password
//my variables
int ONOFF; //this variable is used to track the On/Off State
int timerID =1; //this is the timer used for the delay counter
BlynkTimer timer; //
//DHT dht(DHTPIN, DHTTYPE); //
//My Delay Timer code
BLYNK_WRITE(V1) //Recieve Slider variable from Virtual pin 1
{
int minutes = param.asInt(); //Saves Value from Virtual pin 1 to minutes
Serial.println(minutes); //Prints the Value from minutes
timer.deleteTimer(timerID); //Deletes old timer
timerID = timer.setInterval(minutes * 60000L, Pumpe); //Sets new timer to minutes * 60000L (miliseconds) and runs the Pump Void
Serial.print("V1 Slider Value: "); //Prints Text to Serial Monitor
Serial.print("Countdown timer: "); //Prints Text to Serial Monitor
}
//My Pump On code
void Pumpe(){ //Creates a Custom void for my Pump On code
if (timerID < 0); //Triggers if the timer is below zero
digitalWrite(D0, LOW); //Turns desired Pin On
digitalWrite(ONOFF, LOW); //Turns the On/Off state tracker On
Blynk.virtualWrite(V2, 255); //Attempting to turn On a virtual LED
timer.setTimeout(10000L, Off); //Sets a timeout for this void (amount of time for pump to be On, and runs the Off Void
}
//My Pump Off code
void Off(){ //Creates a Custom void for my Pump off code
if (ONOFF = LOW); //Reads the state of the On/Off tracker
digitalWrite(D0, HIGH); //Turns Desired Pin Off
digitalWrite(ONOFF, HIGH); //Turns the On/Off state tracker Off
Blynk.virtualWrite(V2, 0); //Attempting to turn Off a virtual LED
}
//my DHT Sensor code
//void Sensor(){ //Creates a Custom void for my DHT Sensor code
// float h = dht.readHumidity(); //Tell Blynk that h is a float number used to store latest humidity reading
// float t = dht.readTemperature(); //Tell Blynk that t is a float number used to store latest temperature reading
//
// if (isnan(h) || isnan(t)) { //If h or t isn't a number
// Serial.println("Failed to read Sensor!"); //Print "Failed to read Sensor" to Serial Monitor
// return; //Try again
// }
// Blynk.virtualWrite(V5, h); //Writes humidity readings to Virtual Pin 5
// Blynk.virtualWrite(V6, t); //Writes temperature readings to Virtual Pin 5
//}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
//my delay timer setup
timerID = timer.setInterval(60000L, Pumpe);
pinMode(D0, OUTPUT);
//my DHT timer setup
//dht.begin();
//timer.setInterval(1000L, Sensor);
}
void loop()
{
Blynk.run();
timer.run();
}