Hello guys.
I have a problem with my Blynk project that i made for my friend and his bees. All sensor are working well and also with the blynk app it goes well but if i put the deep sleep function in the sketch for battery consumption saving the board get online only at the beginning, then goes offline and never gets online again. When i had on the beginning of the project the sketch only with the voltage sensor and a DHT sensor, the deep sleep funktion was running well but when i put all my sensors in the sketch, the deep sleep is not running and the board is then still offline.
I have googled for hours but not solved this problem. I have tried the deep sleep function also in the void setup section but nothing works.
Can ou please help me? I’m a beginner with programming so i need help from you experts
Thank you very much
I use a Wemos D1 mini pro board.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
#include <HX711.h>
#include <Adafruit_ADS1015.h>
// _________________________________ //
//ADS1115:
Adafruit_ADS1115 ads;
float Voltage0 = 0.0;
float Voltage1 = 0.0;
float Voltage2 = 0.0;
float Voltage3 = 0.0;
//HX711 scale:
const int SCALE_DOUT_PIN = D7;
const int SCALE_SCK_PIN = D8;
HX711 scale(SCALE_DOUT_PIN, SCALE_SCK_PIN);
float weight;
float calibration_factor = -21000;
//Voltage sensor:
float Vsensor = A0;
float vout = 0.00;
float vin = 0.00;
float R1 = 30000;
float R2 = 7500;
float value = 0.00;
//Light sensor:
int Lsensor;
int light;
int brightness;
//Temperature and humidity sensors:
#define DHT1PIN D3
#define DHT2PIN D4
#define DHT1TYPE DHT22
#define DHT2TYPE DHT11
DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);
//Blynk app:
int sendingtime = 1000L;
char auth[] = "xxxxxxxx";
char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxx";
#define BLYNK_PRINT Serial
BlynkTimer timer;
// ________________________________ //
void sendDHT()
{
float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
Blynk.virtualWrite(V1, h1);
Blynk.virtualWrite(V2, t1);
Blynk.virtualWrite(V7, h2);
Blynk.virtualWrite(V6, t2);
}
void sendWeight()
{
weight = (scale.get_units(20));
weight = weight - 23.60;
Blynk.virtualWrite(V4, weight);
}
void sendAnalogs()
{
int16_t adc0, adc1, adc2, adc3;
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
Voltage0 = (adc0 * 0.125)/1000;
Voltage1 = (adc1 * 0.125)/1000;
Voltage2 = (adc2 * 0.125)/10;
Voltage3 = (adc3 * 0.125)/1000;
Voltage3 = 4.1 - Voltage3;
float sensorVal = 0;
float smoothedVal = 0;
int samples = 10;
sensorVal = Voltage2;
smoothedVal = smoothedVal + ((Voltage2 - smoothedVal)/samples);
smoothedVal = map(smoothedVal, 10, 50, 100, 0);
Blynk.virtualWrite(V10, Voltage0);
Blynk.virtualWrite(V11, Voltage1);
Blynk.virtualWrite(V12, smoothedVal);
Blynk.virtualWrite(V13, Voltage3);
}
void sendVoltage()
{
float sdata = 0;
value = analogRead(Vsensor);
vout = (value * 5.0) / 1640.0;
vin = vout / (R2/(R1+R2));
Serial.print("INPUT V= ");
Serial.println(vin,4);
sdata = vin;
Blynk.virtualWrite(V3, sdata);
}
void goToSleep(){
ESP.deepSleep(5 * 3 * 1000000); //sleep for 15 seconds
}
void setup()
{
Serial.begin(9600);
pinMode(Vsensor, INPUT);
Blynk.begin(auth, ssid, pass);
scale.set_scale(calibration_factor);
//scale.tare();
dht1.begin();
dht2.begin();
ads.setGain(GAIN_ONE);
ads.begin();
timer.setInterval(sendingtime, sendDHT);
timer.setInterval(sendingtime, sendVoltage);
timer.setInterval(sendingtime, sendWeight);
timer.setInterval(sendingtime, sendAnalogs);
timer.setInterval(5000L, goToSleep);
}
void loop()
{
Blynk.run();
timer.run();
}