Hello all!
A few weeks back I had come up with the idea to create a hydroponics system, for fun of course. long before short I realized that the device needed to be automated because I won’t be at home all the time to switch on/off lights etc etc.
I then discovered the Arduino Uno + ESP8266 + Blynk combination. I am an engineering student so I have had exposure to writing code as well as the electronics and all that kind of thing.
After dipping my toe into the water I am all of a sudden neck deep and the project has gone from a single growing unit to (what I think is) a very neat little setup
This is the situation…
- Arduino Uno
- ESP8266 WiFi Shield (to connect to my home network obvs)
- 2 x growing units
- 2 x 12v DC brushless fans (one for each unit)
- Breadboard
- Breadboard power supply with 5V and 3.3V rails
- 2 x DHT11 sensors to measure temp + humidity (one for each unit)
- 2 x 5V relays (to control the lights for each unit)
- L293D motor driver to drive the fans
It’s pretty simple, I have wired it all up and it is working 100% functionally.
I had run into problems from day 1 and searching this forum has helped me make it what it is today, so I would like to thank you all in advance for that.
I also want to note that I have tried everything to fix my problem so this really is my last resort.
Now. The problem.
My device goes offline in the app randomly, but continues to run and do its thing.
It used to disconnect after a few hours like I have seen many people struggle with as well, I just used to power cycle it by switching off the mains and switching everything back on again because the button on the Arduino never made a difference.
I considered writing code for it to reconnect but was hesitant because I didn’t really understand it so I wasn’t just going to guess.
I of course could not control any buttons through the app while it wass in the offline state (just to clarify).
I added the second DHT11 sensor recently and had to rewrite the code for it.
The code I have written is just for the DHT11 sensors because I have just used the app widgets and selected the correct digital pins for the relays and whatnot as I thought it would be less room for error as I don’t really back my coding all that much.
Since I have given it the new code (yesterday) it randomly went offline, but then for some reason had reconnected itself. I was okay with this because it seemed to have found it’s own solution.
This must have happened 4 or 5 times since I uploaded the new code, but as of this morning has been offline and seemed to be stuck in the same offline loop and I now have to power cycle again.
Extra Information that might be useful:
- I have added snubbers for the relays to absorb kickback voltage
- I have added a 100 micro farrad capacitor across the ESP8266 in case it had power problems there
- I am using iOS (the latest version of the app)
- I am using the Blynk server
- My internet has not had problems as I am always connected to it
- My code may have unnecessary libraries as I have changed it so many times I have lost track of what needs to be there although I don’t think this matters I am aware of it
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
#include <blynk.h>
SimpleTimer timer;
char auth[] = "xxxxxxxxxxxxxxxxxxx"; //Blynk App auth Token
char server [] = "blynk-cloud.com";
char ssid[] = "xxxxxxxxxx"; //WiFi name
char pass[] = "xxxxxxxxx"; //WiFi password, set password to "" for open networks
unsigned int port = 8442;
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define DHT1PIN 5 // What digital pin we're connected to (sensor 1)
#define DHT2PIN 12 // Sensor 2
#define DHT1TYPE DHT11 // Sensor 1 type DHT 11
#define DHT2TYPE DHT11 // Sensor 2 type DHT 11
DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);
void sendSensor1()
{
float h = dht1.readHumidity();
float t = dht1.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}
void sendSensor2()
{
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h2) || isnan(t2)) {
Serial.println("Failed to read from DHT sensor 2!");
return;
}
Blynk.virtualWrite(V7, h2);
Blynk.virtualWrite(V8, t2);
}
void setup()
{
Serial.begin(9600); // Debug console
EspSerial.begin(ESP8266_BAUD); // Set ESP8266 baud rate
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
dht1.begin();
dht2.begin();
timer.setInterval(1000L, sendSensor1); // Call sensors every second
timer.setInterval(1000L, sendSensor2);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer
}
I really hope someone can help with why it keeps going offline. Eventually I would like to pre-set light cycles that run off timers but I would like the device to be stable first.
I also apologize for the lack of serial monitor output, I have thought about keeping my PC connected until it goes offline to try and see why but I haven’t gotten around to it.
Please don’t hesitate to ask if more information is needed.
Thanks in advance