Skip to content
Arduino Sensor monitor library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Arduino Sensor monitor library. This library allows you to get updates from your sensors in a controlled manner. You do not have to keep track of timeouts and deltas to determine if you need to publish an update for a sensor. All you have to do is register sensor IDs with the library, implement the method to get a reading for the sensor, and do something with the value when you are asked to.


Arduino IDE

Download the source code and place inside Arduino libraries folder


See documentation at Platformio - Sensor Monitor

Example use case

Let's say you have temperature sensor, and you publish the readings to a remote server when the value changes. To save power you don't want to send the value every single time if the value stayed the same. If the value changed - lets say by 2 degrees - then you want to imediately send an update to the server. If value didn't change, then you only want to update the server every 5 minutes, basically just to say the sensor is still alive. This can be done without this library, but then you'd have to keep track of timers, last value, delta value etc.

By implementing a getReading function which will be called for you when required, you only have to take care of implementing a way to get the value.

By implementing a onUpdate function you can send the value to your remote server, and it will be called only if the delta was big enough, or a long enough time has passed to do an update.

Short summary of code use

float getReading(uint8_t sensorId){
	 if(sensorId == SENSOR1){
		// Get a reading

void onUpdate(uint8_t sensorId, float value){
	// Do something with a reading

// Create a Sensor Monitor and reference the functions it must use
SensorMonitor sensorMonitor(&getReading, &onUpdate);

void setup(void){

void loop(void){


The following configuration can be done by overriding the #define values from SensorMonitor.h. When using platformio it can be done by adding defines to the build_flags property (e.g. -DSM_NUM_SENSORS=2)


Default: 0
Analog pin to use for a random value. The random value is used to spread the sensors apart so that not all of them are queried at the exact same time.


Default: 15000
Millisecond interval at which all sensors should at least send an update


Default: 1500
Minimum amount to delay before taking readings


Default: 0.5
Delta required before updating immediately


Default: 5
Maximum number of sensors that can be monitored. Keep this as small as required to save memory

You can’t perform that action at this time.