Hello guys
Here I am, the Portuguese who can not write English (only with the help of my friend Google) and are learning ESP 8266.
I ask again for help for the following:
I want to make a detector for door opening and closing a battery powered using any model of the ESP 2866, in this case the model 12.
The needs are as follows:
- Inform the opening or closing of the door as soon as possible. At this stage I use BLYNK.
- Use the previous point to know the battery status using ADC_MODE (ADC_VCC) and ESP.getVcc ().
- Use deep sleep to “numb” the ESP 8266 indefinitely until motion is detected on the door (open or close).
- When detecting door movement, it reads the status of the door, reads the battery voltage, sends this information (in this case via BLYNK) and returns to “sleep”.
To detect the opening of the door I use a magnetic reed, connected to the gpio 12 and to wake up another reed connected between the reset and the negative.
I did not make the connection between reset and gpio16 because I do not want the ESP 8266 to wake at the end of x time, but stay permanently “out of service” until the door moves.
This second reed, to reset, must be installed so that it is always open and only closes momentarily when the door is moving. That is, either with the door open or closed the magnetic must always be out of reach of the reset reed and only when the door opens or closes to pass momentarily by the reed. Ideally the same magnetic would act the two reeds, which is difficult, but that’s another story. I will use two reeds and two magnetic ones for now.
I was able to program the ESP 8266 to meet all the needs, but I can not lower the consumption below 195mA. This consumption is unacceptable because I do not want to constantly change batteries.
I have researched and everything I find that using ESP.deepSleep (0), the ESP 8266 gets sleep" indefinitely (because the time setting is “0”) and consumption should drop to 10μA.
As I already said in terms of programming everything is solved and I am sure that the ESP 8266 is in deep sleep because immediately following ESP.deepSleep (0), I put the instruction Serial.println ("******** ***** ") that is never executed.
As an additional note, the ESP 8266 warms up considerably, which seems to contradict what I said in the previous paragraph.
I can not figure out why I can not get consumption down to 10μA as everything I’ve read says.
Someone can help me ?
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
ADC_MODE(ADC_VCC); // Activates internal voltage measurement function
char auth[] = "xxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
const int DoorGpioPin = 12; // [D6 on NodeMCU] pin we're connected to Door
const int ledGpioPin = 13; // [D7 on NodeMCU] pin we're connected to LED
void setup() {
Blynk.begin(auth, ssid, pass);
Serial.begin(115200);
Serial.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); // Simulates the serial monitor cleaning
Serial.println("");
// prepare GPIOs
pinMode(DoorGpioPin, INPUT);
pinMode(ledGpioPin, OUTPUT);
// Checks the status of the door
if ( digitalRead(DoorGpioPin) == HIGH ) //closed
{
String doorState = " Porta Fechada";
Blynk.notify(doorState); // Notifies Blynk
Blynk.virtualWrite (V2, doorState); // String for LCD Blynk
digitalWrite(ledGpioPin, 1); // Turns off the local Led on GPIO 13 [D2]
Blynk.virtualWrite(V4, 1); // turn app LED on V4 OFF
Serial.print(doorState + " \t");
}
if ( digitalRead(DoorGpioPin) == LOW ) //opened
{
String doorState = "**PORTA ABERTA**";
Blynk.notify(doorState); // Notifies Blynk
Blynk.virtualWrite (V2, doorState); // String for LCD Blynk
digitalWrite(ledGpioPin, 0); // Turns on the local Led on GPIO 13 [D2]
Blynk.virtualWrite(V4, 255); // turn app LED on V4 ON
Serial.print(doorState + " \t");
}
//***********************************************************
//Reads Battery
float bat = ((float (ESP.getVcc()) / 954.545)); // Reads voltage on ESP8266 [954.545=ESP.getVcc/3.3v
Blynk.virtualWrite (V3, bat); // Sends battery status to Blynk
String batState = ("Bateria= " + String (bat));
//***********************************************************
// Print for Serial Monitor - See the connection status in Serial Monitor
Serial.print (batState + " \t");
//Serial.println ("ESP.getVcc: " + String (ESP.getVcc())); // Option to discover the value of ESP.getVcc()
Serial.println("");
Serial.println("I'm gooooing to sleeeeeeeeep....ZZZZzzzzzzzzz");
ESP.deepSleep(0);
Serial.println("*************");
}
void loop() {
}