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:

Programmingmmexport1472732631987

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()
{
  dht.begin();
  initializeDTsensors();
  lightMeter.begin(BH1750_CONTINUOUS_HIGH_RES_MODE);
}

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

In Section 3, I will show you how to transmit and receive the data objects wired and wireless.  But first, we go to Section 2, and discuss controlling appliances based on sensor readings using remote controlled AC outlets.

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

Currently under construction: Section 2:  Controlling Appliances

More Info:

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.