How long or how much power is consumed by this if connected to either a Doiting 8266 or a Lolin ESP8266 . Trying to see if it can run on a battery and for how long, so far I have used a 2000ma battery pack and it last part of a day . Closed it should last awhile I assume
Hi.
I haven’t tested that. So, I don’t know how it will consume.
You can consider adding deep sleep to your code, or use an ESP-01 (consumes less power than the other boards).
Regards,
Sara
Thanks, thought of that , just wasn’t sure how to do that, I guess I will investigate that .
Thanks again
So I am trying to use a deep sleep function for a motion sensor and I have tried my project without adding the deep sleep ,it works fine. Now I added
Serial.begin(115200);
Serial.setTimeout(2000);
while(!Serial){}
Serial.println(“I’m awake , but going to sleep until Reset pin is connected to Low pin.”);
ESP.deepSleep(0);
I connected a jumper from rst to D0 , removed the jumper to send the code but after that with the motion connected to D5 nothing happens. Can you tell me where i went wrong? Thanks
Start your code here
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
// Replace with your network credentials
const char* ssid = “xxxx”;
const char* password = “xxxxxxx”;
// Initialize Telegram BOT
#define BOTtoken “xxxxxxxxxxxx” // your Bot Token (Get from Botfather)
// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click “start” on a bot before it can
// message you
#define CHAT_ID “xxxxx”
X509List cert(TELEGRAM_CERTIFICATE_ROOT);
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
const int motionSensor = 14; // PIR Motion Sensor
bool motionDetected = false;
// Indicates when motion is detected
void ICACHE_RAM_ATTR detectsMovement() {
//Serial.println(“MOTION DETECTED!!!”);
motionDetected = true;
}
void setup() {
Serial.begin(115200);
Serial.setTimeout(2000);
//Wait for serial to initilaze.
while(!Serial){}
//Deep sleep mode for 30 seconds.
//Serial.println(“I’m awake, but but will go to sleep for 30 sec.”);
//ESP.deepSleep(30e6);
//Deep sleep mode until Reset pin is connected to low signal.”);
Serial.println(“I’m awake , but going to sleep until Reset pin is connected to Low pin.”);
ESP.deepSleep(0);
configTime(0, 0, “pool.ntp.org”); // get UTC time via NTP
client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org
// PIR Motion Sensor mode INPUT_PULLUP
pinMode(motionSensor, INPUT_PULLUP);
// Set motionSensor pin as interrupt, assign interrupt function and set RISING mode
attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);
// Attempt to connect to Wifi network:
Serial.print(“Connecting Wifi: “);
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(“.”);
delay(500);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.print(“IP address: “);
Serial.println(WiFi.localIP());
bot.sendMessage(CHAT_ID, “Bot started up”, “”);
}
void loop() {
if(motionDetected){
bot.sendMessage(CHAT_ID, “Motion detected!!”, “”);
Serial.println(“Motion Detected”);
motionDetected = false;
}
}
You have your deep-sleep inside your setup function. When the board starts it will put the board to sleep. When it wakes up it starts the setup function again and goes back to sleep. You should be using interrupts. Check out this tutorial.
Steve is right.
You have to think that the code will run and execute the code line by line from the beginning. When it finds the deep sleep function, it goes to sleep, and doesn’t run the rest of the code.
Any code that you want to run before deep sleep, or when it wakes up, should go before the deep sleep command.
This is the deep sleep tutorial for an ESP8266 board: https://randomnerdtutorials.com/esp8266-deep-sleep-with-arduino-ide/
Regards,
Sara