Example Code for Arduino - Sleep and Wake-up

Last revision 2026/03/05

This tutorial on Firebeetle 2 ESP32-E covers implementing timed sleep and wake-up using a gesture sensor. It includes hardware setup, Arduino IDE software installation, and step-by-step code execution for seamless project integration.

Hardware Preparation

Software Preparation

Wiring Diagram

I²C Connection (The following examples all use I²C communication)
SEN0670-I2C Wakeup

Connection Description:

Sensor Pin: VCC Connect to Main Controller Pin: 5V
Sensor Pin: GND Connect to Main Controller Pin: GND
Sensor Pin: C Connect to Main Controller Pin: 22/SCL
Sensor Pin: D Connect to Main Controller Pin: 21/SDA
Sensor Pin: WAKEUP Connect to Main Controller Pin: 13/D7

UART Connection
SEN0670-UART Wakeup

Connection Description:

Sensor Pin: VCC Connect to Main Controller Pin: 5V
Sensor Pin: GND Connect to Main Controller Pin: GND
Sensor Pin: R Connect to Main Controller Pin: 26/D3
Sensor Pin: T Connect to Main Controller Pin: 25/D2
Sensor Pin: WAKEUP Connect to Main Controller Pin: 13/D7

Note:

  • The default communication method of the sensor is I²C. If you need to switch to UART, use the on‑board DIP switch to change the communication method.
  • After switching, the sensor must be powered off and on again for the change to take effect.

Sample Code

Example Code: Control the WAKEUP pin of the sensor to achieve low‑power sleep and wake‑up.

// Sensor EN/WAKE pin connected to ESP32-E pin D7
const int WAKEUP_PIN = D7;

void setup() {
  Serial.begin(115200);
  pinMode(WAKEUP_PIN, OUTPUT);  // Set as output mode
}

void loop() {
  // 1. Sensor sleep (low power)
  digitalWrite(WAKEUP_PIN, LOW);
  Serial.println("Sensor is sleeping → Low power mode");
  delay(3000);  // Keep sleeping for 3 seconds

  // 2. Sensor wake‑up
  digitalWrite(WAKEUP_PIN, HIGH);
  Serial.println("Sensor is awake → Normal operation");
  delay(5000);  // Keep working for 5 seconds
}

Result:

From the serial output, you can see the sensor switching between operating states according to the set timing.

SEN0670-WAKEUP

Was this article helpful?

TOP