Hello,
I am currently making an automated plant waterer, using the Arduino Mega2560 along with the ESP2866. Letting the Arduino run would waste too much battery, so I am trying to use a low power mode. When I try to use it, my Arduino doesn’t respond to the Blynk’s commands. Does anybody know what sleep modes work with ESP2866 and Blynk, or if I am doing something wrong? My code is posted below
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxxx";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
#include <avr/sleep.h>
int trigPin = 6;
int echoPin = 7;
int containerDepth = 50;
int solenoidPin = 2;
int wateringTime = 5;
int solenoidState = 0;
void Sleep(){
sleep_enable(); //Enabling sleep mode
attachInterrupt(0, activate, RISING);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_cpu();
}
void activate () {
sleep_disable();
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2000);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
int duration = pulseIn(echoPin, HIGH);
// Calculating the distance
int distance = duration * 0.034/2;
int waterLevel = 50 - distance;
int percentage = waterLevel/containerDepth;
Blynk.virtualWrite(V1, waterLevel);
if (digitalRead(solenoidPin)) {
delay(5000);
digitalWrite(solenoidPin, LOW);
}
if (waterLevel < 10) {
Blynk.notify("Water level running low! Please refill soon!");
}
}
void setup()
{
// Debug console
Serial.begin(112500);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
Blynk.run();
Sleep();
}