Power efficiency is crucial for many embedded applications, especially those relying on battery power. In this guide, we explore how to put CodeCell into a low-power sleep mode and wake it up using a proximity sensor.
For applications that require complete power shut-off, you can add a switch in series with the battery. This allows you to manually turn the device on and off. Alternatively, you can put CodeCell into sleep mode and wake up when there is sensor activity.
CodeCell has an average sleep current of 689μA. While this may be higher than some ultra-low-power applications require, we are actively working on optimizing power consumption in the next version while still keeping the same size.
Due to the small size and limited number of pins of the ESP32C3, we could not include a dedicated interrupt pin for the sensors to wake up the device. While a true hardware interrupt would be ideal, you can still put CodeCell into sleep mode by periodically check for sensor activity before waking up.
The following code illustrates how CodeCell enters sleep mode and wakes up when proximity is detected.
#include <CodeCell.h>
CodeCell myCodeCell;
void setup() {
Serial.begin(115200);
delay(60); // Waking up from Sleep - add a small delay for Serial
if (myCodeCell.WakeUpCheck()) {
// Initialize light sensor
while (myCodeCell.Light_Init() == 1) {
delay(1);
myCodeCell.LightReset(); // If sensor not responding, reset it
}
delay(40);
myCodeCell.Light_Read(); // Read value from light sensor
if (myCodeCell.Light_ProximityRead() < 10) {
myCodeCell.Sleep(1); // If proximity is still not detected, go back to sleep & check again after 1 sec
}
}
myCodeCell.Init(LIGHT); // Time to wake up - Initializes all CodeCell peripherals
}
void loop() {
if (myCodeCell.Run(10)) { // Run every 10Hz
if (myCodeCell.Light_ProximityRead() < 10) {
myCodeCell.Sleep(1); // If proximity is not detected, go to sleep & check again after 1 sec
}
}
}
How It Works:
Upon booting, CodeCell initializes the light sensor and checks for proximity.
If no proximity is detected, CodeCell enters sleep mode for 1 second.
Every second, CodeCell briefly wakes up, checks for proximity, and goes back to sleep if necessary.
If proximity is detected, CodeCell fully wakes up and initializes all peripherals.
With this example you can add significant power savings to CodeCell, making it more viable for battery-powered applications. We are continuously working on making CodeCell more optimized for low-power applications. Stay tuned for updates and improvements!
Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.