Another timing question

I have come to realize the Arduino is a linear machine when to executes code.

I have searched the sphere concerning timing. Darn, some things are just not simple.

All I am trying to do is scroll parameter events on an LCD and turn on a motor (or two) while the LCD scrolling is going on.

Seems the delays I have put in run in sequence but I would like the motor (or two) two run outside of the LCD scrolling sequence.

Would it be easier to run the UNO with an RTC and call on it for the motor event or can I still get this done without the RTC?

Here is my code so far.


This sketch scrolls the parameters through the LCD display
at 5 second intervals.

Also runs motor output to control a motor on and off at set
on/off time intervals.

The circuit:

  • 5V to Arduino 5V pin
  • GND to Arduino GND pin
  • Temp-probe to Analog #0
  • Light sensor to Analog #1
  • CLK to Analog #5
  • DAT to Analog #4
  • Dalls Temp probes to pin #3.
  • Motor output to pin #9.

// include the library code:
#include <Wire.h>
#include <LiquidTWI.h>
#include <OneWire.h>
#include <DallasTemperature.h>

int tempPin = 0;
int lightPin = 1;
int motorPin = 9; //Speed control of Pin #9.

// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidTWI lcd(0);

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.

DeviceAddress insideThermometer = { 0x28, 0x2E, 0x72, 0x48, 0x05, 0x00, 0x00, 0x9C };
DeviceAddress outsideThermometer = { 0x28, 0x61, 0x40, 0x15, 0x06, 0x00, 0x00, 0x6B };

void setup() {

//Set motor pin 9
pinMode(motorPin, OUTPUT);

// set up the LCD's number of rows and columns:
lcd.begin(16, 2);

// Start up the library
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideThermometer, 10);
sensors.setResolution(outsideThermometer, 10);


void printTemperature(DeviceAddress deviceAddress)
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error getting temperature");
} else {
lcd.print(" F:");



void loop()

// Display Temperature in C
int tempReading = analogRead(tempPin);
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
// ----------------
lcd.setCursor(3, 0);
lcd.print("ROOM TEMP ");

delay (5000);


// Display LIGHT SENSOR on first row

lcd.setCursor(2, 0);
lcd.print("LIGHT SENSOR");

// ----------------
int lightReading = analogRead(lightPin);
lcd.setCursor(7, 1);



//lcd.print("Getting temperatures...\n\r");

// Display Dallas TEMP 0 on first row
lcd.setCursor(1, 0);
lcd.print("Dallas TEMP 0 ");
lcd.setCursor(0, 1);



// Display Dallas TEMP 1 on first row
lcd.setCursor(1, 0);
lcd.print("Dallas TEMP 1 ");
lcd.setCursor(0, 1);






  • motorOnThenOff() - turns motor on then off

void motorOnThenOff(){
int onTime = 2500; //the number of milliseconds for the motor to turn on for
int offTime = 1000; //the number of milliseconds for the motor to turn off for

digitalWrite(motorPin, HIGH); // turns the motor On
delay(onTime); // waits for onTime milliseconds
digitalWrite(motorPin, LOW); // turns the motor Off
delay(offTime); // waits for offTime milliseconds


Any direction would be greatly appreciated.


I have come to realize the Arduino is a linear machine when to executes code.

You were expecting . . .asymptotes? Parabolae?

Code tags.
I like code tags.

Have you considered the blink without delay example?

As suggested by AWOL, above...Blink without delay, or Demonstration code for several things at the same time - Project Guidance - Arduino Forum