• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP8266 NodeMcu Door Sensor with telegram

Q&A Forum › Category: ESP8266 › ESP8266 NodeMcu Door Sensor with telegram
0 Vote Up Vote Down
Larry asked 4 years ago

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 

Question Tags: door sensor with telegram.
5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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
 

0 Vote Up Vote Down
Larry answered 4 years ago

Thanks, thought of that , just wasn’t sure how to do that, I guess I will investigate that . 
Thanks again 

0 Vote Up Vote Down
Larry answered 4 years ago

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;
}
}

0 Vote Up Vote Down
Steve Mercer answered 4 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.