Need help simple timelapse slider

Hello all.
This is my second post, my first was when I was a total noob. This one I still am.
I’m trying to write the code to run a timelapse slider to be run using a “DFRobot” LCD with keypad. I have been searching the net for well over 6 weeks, with no luck.

The slider is reasonable simple, and I can make the changes I need through the IDE. But for this I need to carry the laptop around with me to do so.

The slider is 3m long. It is drawn along by geared belt run by a 12v 8RPM DC motor. Panning is another 12v DC motor at .6RPM which is also geared down with the use of gears I have got out of several printers which should bring it down to .1RPM (or lower). The motors run from relays which both are connected to pulse width modulators to further reduce speed.

I’m using a Arduino Mega as the controller with the LCD stacked on top. The pins I am using for the DC motors are; 47 for the slide, 45 for the pan. 51 for the shutter and 53 for the focus (Controlling a Nikon D800)

It all works well, but I’d like to control the “delay” time for the pins with the LCD if possible, so I don’t have to carry around the laptop.

As you can see in the code the I’m almost there… (Works fine without all the LCD stuff)

There is heaps of info on the net for stepper motors, but very little for the setup I’m using.

//  Code for Camera slider
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4,5,6,7);

#define RELAY1  47                        
#define RELAY2  45                         
#define SHUTTER 51
#define FOCUS   53
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
//define button values
const int btnUp = 0;
const int btnDn = 1;
const int btnL = 2;
const int btnR = 3;
const int btnSel = 4;
const int btnNone = 5;

//define button-reading variables
int btnVal = 5;
int adcIn = 0;

//declare button poll function
int readLcdButtons() {
  delay(90); //debounce delay, tuned experimentally. delay is fine as program shouldn't be doing anything else 
  //at this point anyway
  adcIn = analogRead(0); //read value from pin A0


  if (adcIn > 1023) return btnNone;
  if (adcIn < 0)   return btnR;
  if (adcIn < 99)  return btnUp;
  if (adcIn < 256)  return btnDn;
  if (adcIn < 408)  return btnL;
  if (adcIn < 639)  return btnSel;


void setup()


// Initialise the Arduino data pins for OUTPUT

  pinMode(RELAY1, OUTPUT);        

  pinMode(RELAY2, OUTPUT);


  pinMode(FOCUS, OUTPUT);


 void loop()

   digitalWrite(RELAY1,LOW);           // Turns ON Relays 1

   delay(3000);                        // wait 2 seconds
   digitalWrite(RELAY2,LOW);           // Turns ON Relays 2
   delay(1000);                        // wait 1 seconds
   digitalWrite(RELAY1,HIGH);          // Turns Relay Off

   digitalWrite(RELAY2,HIGH);          // Turns Relay Off

   delay(500);                        // Wait 15 seconds

  digitalWrite(SHUTTER,LOW);           // Turns ON Shutter 

   delay(500);                         // wait 0.5 seconds

digitalWrite(SHUTTER,HIGH);           // Turns off shutter

   delay(500);                         // wait 1 seconds


When you use your laptop to configure the delay times, what variable(s) do you set or otherwise, how do you make changes through your laptop ?

Thanks 6v6gt for the reply.
All I do is alter the delay times.
Example... If I want the slider to move for say 5 seconds, I change the delay to (5000). same with pan and shutter, then upload.

Just had a thought. All this time I have been searching for timelapse type codes. I think I should be looking at codes for relays.

If you store the value 5000 in a variable you could send a new value from the laptop to the Arduino without the need to recompile the code.

You could also add a couple of push-button switches to the Arduino and when you press one button the value in the variable would increase and when you press the other button it would decrease.

I think you need to make a decision about this before it makes sense to offer further advice.

You may find some ideas in Planning and Implementing a Program. Note that it uses millis() rather than delay() to manage timing.


Thankyou Robin2 for your reply as well..

I have a menu in mind. Pretty simple really.

  1. A start up -- "Simple Slider" (Line 1)
    -- "Press Select" (Line 2)

  2. Relay 1 -- "Slide Time" (Line 1)
    -- " Milli: 00000" *Adjustable between 1000 and 99000 milliseconds (Line 2) Adjust then press select

  3. Relay 2 -- "Pan Time" (Line 1)
    -- " Milli: 00000" *Adjustable between 500 and 99000 milliseconds (Line 2) Adjust then press select

  4. Shutter & Focus
    -- "Exposure Time" (Line 1)
    -- " Milli: 00000" *Adjustable between 200 and 99000 milliseconds (Line 2) Adjust then press select

  5. Start -- "Begin" (Line 1)
    -- "Press Select" (Line 2) *This starts the system running

*Optional -- "Loop Count" (Line 1)
-- "00000" (Line 2) *Number of shots taken

I hope this makes more sense... I am a noob remember... :slight_smile: