Serial Monitor take readings every 5 mins while loop continues

Hi everyone,

I have completed my fan controller to run a vent fan for:

1 hour on and 1 hour off each day
To only run at day time
To only run at 60% normal speed

you can view it here:
https://github.com/Jasontwd/Remote-Fan-control

However the code I have written only writes to the serial monitor each hour as you would expect.

Im keen to take readings every 5 or 10mins.

What way can I do this.
cheers
jason

My current code is:

#include “DualVNH5019MotorShield.h”

const long oneSecond = 1000; // a second is a thousand milliseconds
const long oneMinute = oneSecond * 60;
const long oneHour = oneMinute * 60;
const long oneDay = oneHour * 24;

DualVNH5019MotorShield md;

int sensorPin = A0; // select the input pin for LDR//
int sensorValue = 0; // variable to store the value coming from the sensor
/*int analogPin = 6;
int val = 0; */

void setup()
{
Serial.begin(115200);
Serial.println(“Dual VNH5019 Motor Shield”);
md.init();
pinMode(6, OUTPUT); //pin connected to the VNH5019 M1EN//
}

void loop()
{
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.print("LDR light reading of ");
Serial.println(sensorValue); //prints the values coming from the sensor on the screen

if(sensorValue < 300) //setting LDR threshold value//
digitalWrite(6,LOW); //turn VNH5019 off//

else digitalWrite(6,HIGH); //turn VNH5019 ON//
delay(2);

//motor startup//
md.setM1Speed(200);
Serial.println(“M1 Speed 50% Forward”);// 400 is 100%//
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());

Serial.print("Delay: ");
Serial.println(“delay for 1 Hour ON”);
delay(oneHour);

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.print("LDR light reading of ");
Serial.println(sensorValue); //prints the values coming from the sensor on the screen

if(sensorValue < 300) //setting LDR threshold value
digitalWrite(6,LOW); //turn VNH5019 OFF//

else digitalWrite(6,HIGH); //turn VNH5019 ON//
delay(2);

//motor shutdown//
md.setM1Speed(0);
Serial.println(“M1 Speed 0% stopped”);
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());

Serial.print("Delay: ");
Serial.println(“delay for 1 Hour OFF”);
delay(oneHour);

}

Don't use delays for timings longer than a couple of ms.

The demo Several Things at a Time illustrates the use of millis() to manage timing. It may help with understanding the technique.

That technique will allow you to operate different things at different time intervals.

...R