Semi-Noob Having issues with DIY intervalometer

Hey everyone! This is my first post on the forum, so sorry if I sound like an idiot.

I’m building a new program on my arduino that acts as an intervalometer for my nikon d3000, which currently lacks one. It’s completely unnecessary, but instead of using a pushbutton switch I’m using an FSR (force sensitive resistor), but that’s not my problem. The program and circuit work by triggering a relay (connected to a remote shutter release for my camera) and an indicator LED at a user-specified interval. It figures out this interval based on how many times you have pressed the FSR down. This increases the delay variable, and displays it on an LCD.

Here’s what I’m trying to achieve:

I have a rocker switch hooked up to an analog pin. While the pin is LOW, I want the user to be able to select the interval, and display it on the LCD. My code isn’t done, so I don’t have the LCD part done yet for this part. Once the switch is pressed, and an analogRead of HIGH occurs, I want the delay to be put into action, triggering the relay and the LED.

My problem is that whenever the program starts, the relay and LED start immediately. I think this is probably due to a misuse of the “While” function, but I’m not sure. Also, if you are curious about my use of the several “if” statements, it’s because I don’t want completely static increments.

Without further adieu, here’s my probably bug-filled code:

#include <LiquidCrystal.h>

int ledPin =  5;           // LED Pin
int relayPin = 3;          // Relay Pin
int buttonPin = 6;         // Button Pin
int pressurePin = 6;       // FSR Pin
long pressureval = 0;      // Value of FSR Pin
int buttonval;              // Value of button (off or on)
int numberpushes = 0;      // Stores number of presses
int delaytime = 0;         // Stores time of the delay
char buffer [10];    // Buffer for itoa
char buffertwo [10]; // Buffer for the second line of itoa
LiquidCrystal lcd(12, 11, 2, 7, 8, 9, 10);

This line defines the LCD as a display with
rs on pin 12, rw on pin 11, the enabling pin on 10,
with d4, d5, d6, and d7 on pins 5, 4, 3, 2 respectively.

void setup()   {
  pinMode(relayPin, OUTPUT); //Set Relay Pin as output 
  pinMode(ledPin, OUTPUT);   //Set LED Pin as output
  pinMode(buttonPin, INPUT); //Sets button as input
  while (buttonval == LOW) {  //If button is off, then
  buttonval = analogRead(buttonPin);

   pressureval = digitalRead(pressurePin);
   if (pressureval >= 100) {
     numberpushes = (numberpushes + 1);
   if (numberpushes = 1) {
     delaytime = 1000;
   if (numberpushes = 2) {
     delaytime = 5000;
   if (numberpushes = 3) {
     delaytime = 10000;
   if (numberpushes = 4) {
     delaytime = 15000;
   if (numberpushes = 5) {
     delaytime = 20000;
 if (numberpushes = 6) {
     delaytime = 25000;
if (numberpushes = 7) {
     delaytime = 30000;

void loop() { 

  digitalWrite(ledPin, HIGH);   // Turn LED on
  digitalWrite(relayPin, HIGH); // Close the relay
  delay(1000);                  // Hold shutter for 1 second
  digitalWrite(ledPin, LOW);    // Turn LED off
  digitalWrite(relayPin, LOW);  // Open the relay
  delay(pressureval);                // Wait with delay of "pressureval"
  pressureval = pressureval/1000;         // Convert value to number of seconds
  itoa (pressureval, buffer, 10);    // Convert to string "buffer"
  lcd.print(buffer);            // Display buffer
  pressureval = pressureval/60;           // Convert to minutes
  lcd. setCursor(0, 1);         // Move to second line
  itoa (pressureval, buffertwo, 10); // Convert minutes to string in buffertwo
  lcd.print(buffertwo);         // Display buffertwo

Also, if anyone has any other comments about the code, it would be much appreciated.

Thanks everyone!


The setup function is executed once. It may not end until the button is pressed once. But, as soon as the button is pushed, the pressure pin will be read, number pushes will be set to 1, and setup will end. On the other hand, it may end immediately. It depends on how the button is wired.

If the switch is wired so that it is LOW unless pressed, setup will end immediately.

The pressureval variable will have a value between 0 and 1023. Dividing by 1000 will result in a value of 0 or 1.

Dividing by 60 will then result in a value of 0.

if (numberpushes = 1) {

probably wants to be

if (numberpushes [glow]==[/glow] 1) {

And repeat for all the other unintentional assignments.

  while (buttonval == LOW) {  //If button is off, then

Fortunately, buttonval will be initialised to zero, but it is probably better not to rely on this sort of thing.