Reputation: 68
I'm working on a battery-powered environmental monitoring system using an Arduino Nano 33 IoT with a LoRa module (RFM95W). I need to implement an adaptive sleep interval algorithm that adjusts based on sensor reading variations. Currently, my code uses fixed intervals:
void loop() {
float currentTemp = readTemperature();
float currentHumidity = readHumidity();
sendLoRaData(currentTemp, currentHumidity);
LowPower.deepSleep(SLEEP_INTERVAL); // Fixed 15-minute interval
}
How can I modify this to implement dynamic sleep intervals that:
I've tried using simple thresholds, but this leads to frequent wake-ups during minor fluctuations. What would be an efficient algorithm for this?
I implemented this approaches to solve this:
const float TEMP_THRESHOLD = 0.5; // Celsius
const float HUMIDITY_THRESHOLD = 2.0; // Percent
unsigned long calculateSleepTime() {
float tempDiff = abs(currentTemp - lastTemp);
float humDiff = abs(currentHumidity - lastHumidity);
if (tempDiff > TEMP_THRESHOLD || humDiff > HUMIDITY_THRESHOLD) {
return MIN_SLEEP_TIME; // 5 minutes
}
return MAX_SLEEP_TIME; // 30 minutes
}
This led to frequent wake-ups due to normal sensor noise.
Upvotes: -1
Views: 28