So I have a Blynk project that was working fine until I wanted to incorporate a battery and deep sleep. Been reading around the board and incorporated a few changes I thought made a lot of sense, but still don’t work. My board won’t sleep and wake up. Also, onboard ESP LED and JST board LED stay lit once powered (even after reset).
Goal Read value from utrasonic sensor, conduct some math to get gallons and tank level, publish to Blynk, go to deep sleep for 60min (though for testing purposes I think I have this set lower)
HW ESP8266-12E (NODEMCU) + JSNSR04T 2.0 + 3.7V 1000mah LIPO
Only difference in wiring I changed was to add a jumper to RST and D0 pins of ESP
Code (embarrassed to show it but here goes)
//ESP8266 Tank Level Sensor using JSNSR04T 2.0 and 3.7V LIPO
//Goal read level, post to blynk, deep sleep, repeat
//REV 7_13_20 545PM
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define sleepLength 20 //how long to deep sleep in seconds
//ESP8266 Wire Connections to battery and JSNSR04T 2.0 Board
//Vin to LIPO 3.7V battery
//GND to LIPO Bat Gnd
//RST to D0 <----- enables the wake from deep sleep
//D4 to Sensor Trig
//D2 to Sensor Echo
//3V3 to Sensor Vin
//GND to Sensor GND
// defines pins numbers
const int trigPin = D4;//2 for arduino
const int echoPin = D2;//5 for arduino
const int maxDist = 60;
const int r = 35.5; //radius of tank
const long piRsqd = 3959.192; //based on r=35.5
const long pi = 3.14159;
// defines variables
int h; //height of tank
long duration;
long dist_cm;
long dist_in;
long tankLevel;
long tankLevel_ft;
int gallons;
//Set WIFI and Blynk token
char ssid[] = "xxx";
char pass[] = "xxx";
char auth[] = "xxx";
//********************Setup Call
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(115200); // Starts the serial communication
Blynk.begin(auth, ssid, pass);
delay(20);
while (Blynk.connect() == false) {
//Wait until connected
//Serial.print("x");
}
Blynk.run();
}
//********************************Get and Send sensor readings and deep sleep call
void sendSensorReadings() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(15); //Do I really need this delay
// Sets the trigPin on HIGH state for 15 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(15); //Was told this is a trick to get JSNSR04T ultrasonic sensor to work well
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
//Would like to do a do loop whereby if three consecutive readings equal each other , that's the "duration" value
//thoughts?
// Calculating the distance
//58 represents assumption speed of sound = 1,000,000 / 58 * 2 / 100 = 344.8 mps
dist_cm= duration/58;
// multiplied by .39 to get inches
dist_in= dist_cm *0.393701;
//tank level is distance between sensor and bottom of empty tank (maxDistance) - distance reading
tankLevel = maxDist - dist_in;
tankLevel_ft = tankLevel/12;
//Gallons remaining
gallons = piRsqd*tankLevel/231; //231 cubic inches per gallon
//***********SEND INFO TO BLYNK
Blynk.virtualWrite(V1, tankLevel_ft); //send level to Blynk server
Blynk.virtualWrite(V2, gallons); //send gallons to Blynk server
delay(50); //i read somewhere to do this delay
//** Prints the distance on the Serial Monitor
Serial.print("Gallons Remaining: ");
Serial.println(gallons);
Serial.print("Tank Level: ");
Serial.println(tankLevel_ft);
Serial.print("Going to Sleep");
//Adding deep sleep
ESP.deepSleep(sleepLength * 1000000,WAKE_RF_DEFAULT); //default mode
delay(100);
}
void loop() {
//Nothing here
}