Here are 3 ways to use a MEM2313 Flip-Flop Latch Relay Module to make your microcontroller sleep.
This module is easy to use, just plug a button to T and GND to toggle Vo ON/OFF
The trigger is active when the INPUT fall to LOW. (Falling Edge Triggered)
There are probably better way to do all of these, but I just wanted to share my discovery.
Turn ON/OFF any board using a tactile switch (0.18µA)Issue
You need a way to toggle on/off your project, using a tactile switch
Solution
Not the most interesting issue, as you could simply use a on/off switch to disconnect your board from your power supply.
- Just plug a tactile switch on T/G
- Vi : Power supply
- Vo : Board VCC
Test:
Turn ON Board using a tactile switch and turn it off once your task is doneIssue
You want your board to perform a task when you press a button and then turn off by itself
Solution
Same as before, but we added a gpio on the Trigger Pin.You need to add a small capacitor (10µf for example) or you will need to press the tactile switch twice to power it on.
Code example:
void setup() {
Serial.begin(115200);
Serial.println("ON BY SWITCH");
delay(5000); // Your task (for example send a MQTT message here)
pinMode(16,OUTPUT); // If you put your GPIO on OUTPUT it will trigger the toggle
Serial.println("OFF BY MCU");
}
void loop() {
//Code will never go here
}
Test:
Test failed (without a capacitor)
Turn OFF peripherals before deep sleepIssue
Let's say you have 16 neopixels plugs on your board, if you put it in deep sleep, your neopixels will still use 7.62mA
Solution
This one is harder, as our module is a toggle module and we want to be sure, we don't turn on our LED instead of turning it off.So we will plug on Vi a input GPIO to check if the power is on or off.
I used a Lolin D32 which uses ~140µA in deep sleep
Test
Test failed (without the mosfet)
Here is the code I used for my test
#include <Adafruit_NeoPixel.h>
#define PIN 16 // On Trinket or Gemma, suggest changing this to 1
#define NUMPIXELS 16 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50 // Time (in milliseconds) to pause between pixels
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */
RTC_DATA_ATTR int bootCount = 0;
void on() {
if (!digitalRead(15)) {
pinMode(17, OUTPUT);
digitalWrite(17, LOW);
delay(100);
digitalWrite(17, HIGH);
Serial.println("Turning ON");
} else {
Serial.println("Already ON");
}
}
void off() {
if (digitalRead(15)) {
pinMode(17, OUTPUT);
digitalWrite(17, LOW);
delay(100);
digitalWrite(17, HIGH);
Serial.println("Turning OFF");
} else {
Serial.println("Already OFF");
}
}
void setup() {
Serial.begin(115200);
pinMode(15, INPUT);
on();
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear(); // Set all pixel colors to 'off'
for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
pixels.setPixelColor(i, pixels.Color(0, 150, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
pixels.clear();
pixels.show();
off();
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds");
Serial.println("Going to sleep now");
Serial.flush();
esp_deep_sleep_start();
}
void loop() {
// Code will never reach here.
}
Make your own Latch Circuit to do thisWhile this module makes it really easy to do all of this, if you want to understand how to do it yourself, check out Electronoobs video on the subject:
Comments