A simple reed switch sketch w/a deep sleep prgram to notify me of sticky fingers


This is the first time I have used the forum. I am an Arduino novice.

I was successfully able to create/patch together a sketch that I used with an ESP32 and a reed switch to alert me, via Blynk, if the safe had opened. Since I am using a battery, I also want to introduce a deep sleep component so that I could extend the battery life. I have attached the combined sketch (blynk notification, and deep sleep) +, as well as the original blynk notification sketch

The issue is that the code works for waking from deep sleep when pin 13 is pulled high, but now the blynk notification does not work.

Any guidance would be appreciated

Setup: an ESP32 with a reed switch connected to GPIO 13 and a lipo battery connected to Gnd and Vin

sticky_fingers.ino (941 Bytes)

sticky_fingers_with_sleep.ino (2.59 KB)

Welcome to the Forum. Did you read these posts?:

General Guidance and How to use the Forum

Read this before posting a programming question ...

I did. I am unsure of what I did incorrectly other than not being sure if "posting" code is the same as attaching it. Is that what is missing?

Thanks in advance


It’s in “6. Getting help on the forum”…

“When you post your code put it between code... tags. You can do that by hitting the </> button above the posting area.”

I have to admit, it’s not as obvious as I thought it was…

Thanks for the heads up.

Here is my attempt at combining the 2 codes (again - trying to combine a simple reed switch activation/blynk notification with a hibernation sketch):

The issue: the hibernation and wakeup from pin 13 reed switch works, but the blynk notification does not.

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "25cD-K-LkDrV6rmaaYcF0B74aDyRFvY0";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Ellis";
char pass[] = "hummus18";

#define FlamePin 13  // This is for input pin
int Flame;
boolean state = false;

#define BUTTON_PIN_BITMASK 0x2000 // 2^13 in hex

RTC_DATA_ATTR int bootCount = 0;
void sendUptime() {
 Flame = digitalRead(FlamePin);
 if (Flame== HIGH)
    Blynk.notify("STICKY FINGERS!");
    Serial.print("Fire In the House!");
 Serial.println("All Quiet");


void print_wakeup_reason(){
  esp_sleep_wakeup_cause_t wakeup_reason;

  wakeup_reason = esp_sleep_get_wakeup_cause();

    case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
    case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
    case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
    case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
    default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;

void setup() {
    // Debug console
 Blynk.begin(auth, ssid, pass);
 pinMode(FlamePin, INPUT_PULLUP);


void loop()
  Serial.println("Boot number: " + String(bootCount));

  //Print the wakeup reason for ESP32

  First we configure the wake up source
  We set our ESP32 to wake up for an external trigger.
  There are two types for ESP32, ext0 and ext1 .
  ext0 uses RTC_IO to wakeup thus requires RTC peripherals
  to be on while ext1 uses RTC Controller so doesnt need
  peripherals to be powered on.
  Note that using internal pullups/pulldowns also requires
  RTC peripherals to be turned on.
//  esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,1); //1 = High, 0 = Low

  //If you were to use ext1, you would use it like
  //Go to sleep now
  Serial.println("Going to sleep now");
  Serial.println("This will never be printed");