Programming Time Management

There are a lot of nice tutorials online covering the use of Arduino Uno and nearly any sensor or peripheral device you can find.  Most tutorials focus on using an Arduino Uno (or variant) and a single sensor or peripheral.  In this project, we will be using three sensors.

Download and install libraries:


Before we start working on the source-code for this project, we need to make sure we are ready.  You should have the Arduino IDE installed and be familiar with installing libraries.  Personally, I have found Atmel’s Visual Studio to be more useful for managing large projects than using the Arduino IDE as a standalone development environment.

Include needed libraries:

#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <BH1750/BH1750.h>

#include "TimeMan.h"
#include "CoreSensors.h"

In my article, Why Arduino when you can Pi?, I explain that after trying many different timer and time management libraries I felt they were either too much or not enough of what I was wanting in my timers.  A set of timers that are easy to set, keep track of their own state, and each have their own trigger flags (“TimeMan.h”).

/* Timers */
//Timer Object = { (type), (interval in millis), ready, triggered, timestamp, (pointer to next object)
Timer Timer_txData = { TIMER_TX_DATA, 30000UL, true, false, 0, NULL };
Timer Timer_Save_Settings = { TIMER_SAVE_SETTINGS, 3600000UL, true, false, 0, &Timer_txData };
Timer Timer_Sensor_Read = { TIMER_SENSOR_READINGS, 7000UL, true, false, 0, &Timer_Save_Settings };
Timer Timer_rxData = { TIMER_RX_DATA, 6000UL, true, false, 0, &Timer_Sensor_Read };

Additionally, the sensors can be objectified and their functions can be moved to their own library file (“CoreSensors.h”) allowing us to keep our main code much cleaner.

void setup()

void loop()
  // Start at the very beginning, a very good place to start
  if ( checkTimer( &Timer_Sensor_Read ) )
  • The source-code is compiled and uploaded to the Arduino Nano.
  • Use the serial console to view the sensor readings.

As I receive feedback from you, I will update these sections, so don’t be afraid to comment or send me your questions directly.


Controlling Appliances based on sensor readings using remote controlled AC outlets.

More Info:

Please share with friends and follow to receive a notification when I publish a new article.