the aim of the project I'm working on is to water my bonsai automatically, depending on numerous sensor inputs. So basically I have Arduino Nano with huminity and light sensor, a relay to switch the water pump and ESP8266 wifi module, which I use to check the data from the sensors in the Blynk app on my phone. I use two isolated circuits. The first one is used only by the DC motor (water pump) and is supplied by a 5V 600 mA power source. The second takes care of the rest (arduino, ESP, sensors, relay) while it's supplied by a 5V 1A power source. I'm using this with the ESP8266 board.
Once I run the program, it connects to the Blynk server and I can read data from the sensors on my phone. The problem comes when I want to switch the relay from the Blynk app. Than the ESP8266 disconnects (nearly immediately, or after few seconds). I tried a different DC motor (not a water pump) and it worked fine. I also tried to switch the pump without using EPS8266, that worked as well (so the code should be ok). I think this has something to do with the current draw caused by the water pump, but that makes no sense - I'm using two independent circuits, the pump draws maximally 300 mA from the 600 mA source, while the rest of the electronics draws no more than 200 mA from the 1 A power supply. Neither different power supplies, nor another relay worked.
Here's my code:
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <BH1750.h>
#include <Time.h>
#include <SoftwareSerial.h>
#define PUMP 10
#define SENSOR A0
#define BUTTON 2
char ssid[] = "XXXXX";
char pass[] = "XXXXXXXXXXXXXXXXXX";
SoftwareSerial EspSerial(11, 12);
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
BH1750 lightMeter;
int humidity;
int light;
bool pressed = 0 ;
bool pump=1;
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
void sendData(){
humidity=analogRead(SENSOR);
light=lightMeter.readLightLevel();
Blynk.virtualWrite(V0,humidity);
Blynk.virtualWrite(V1,light);
// Serial.print("humidity: ");
// Serial.println(humidity);
// Serial.print("light: ");
// Serial.println(light);
}
void checkConnection(){
if(!Blynk.connected()){
digitalWrite(PUMP,1);
Blynk.begin(auth, wifi, ssid, pass);
}
}
void checkButton(){
if(digitalRead(BUTTON) && pressed){
Blynk.virtualWrite(V3,digitalRead(BUTTON));
pump=!pump;
// Serial.println("pump from button");
}
else if(digitalRead(BUTTON) && !pressed){
pressed=1;
}
else{
pressed=0;
}
}
BLYNK_WRITE(V2)
{
Serial.println("switching pump");
pump=!param.asInt();
digitalWrite(PUMP,pump);
}
void setup() {
Serial.begin(9600);
delay(10);
EspSerial.begin(9600);
delay(10);
lightMeter.begin();
pinMode(PUMP, OUTPUT);
pinMode(BUTTON, INPUT);
digitalWrite(PUMP, pump);
Blynk.begin(auth, wifi, ssid, pass);
timer.setInterval(5000L, sendData);
//timer.setInterval(5L, checkButton);
// timer.setInterval(2000L, checkConnection);
}
void loop() {
if (Blynk.connected()) {
Blynk.run();
timer.run();
}
}
and the Blynk log:
[2631095] <[06|05|14|00|00]
[2631389] >[00|05|14|00|C8]
[2632112] <[14|05|15|00|08]vw[00]0[00]632
[2632280] <[14|05|16|00|07]vw[00]1[00]28
[2637109] <[14|05|17|00|08]vw[00]0[00]630
[2637214] <[14|05|18|00|07]vw[00]1[00]28
[2641393] <[06|05|19|00|00]
[2651445] Cmd error
[2656470] Cmd skipped:20
[2656471] Cmd skipped:20

