Control delay with Potentiometer

Hello everyone.
I recently built myself a IR remote shutter release for my Nikon camera.

Here is how it works and what I want to add:

It triggers the camera with a certain series of pulses made from square waves. These IR pules is sent to te camera with an IR led.
First, it has 2 modes, first, Single Shot, and second, Timelapse Mode.
In the fist mode it just takes an image when I press the button on my remote.
In time lapse mode, it takes a photo every x amount of seconds. The startup or default time is one second for a reason. This delay can then be controlled in the field with what is no more the shutter button, but now the interval timer. So in Single shot mode, the button is used as a shutter button, simple, and in the time lapse mode, the button can be pressed and held for a certain amount of seconds and then when depressed the arduino takes that time and puts it into a variable that determines the delay or interval between shots in a time lapse.
So basically if I want to change the interval, I just press the button and hold it while looking at a timer on my phone. Really easy way and I'm not limited by presets. That is working.

But now, what I want to add is a feature where the arduino controls the shutter opening and closing therefore giving the arduino the ability to change the shutterspeed (exposure).
Let me just mention, when shooting time lapses, you always want to be in manual mode, to eliminate flickering. What happens when the camera automatically chooses an exposure. What pro time lapsers do is they use manual and when the light changes, they just manually change the exposure. And then use expensive software to even out those manual exposure updates.

But I don't have that software, but I can make my arduino control the exposure. I can set my camera to time mode, where it wants to receive one signal to open the shutter and then another one to end the exposure. (the same signal, but sent twice, it might sound like I said the camera wants different signals one for open and one for close, but it only takes one)

So I built in some new hardware to my remote, another toggle switch, and a potentiometer.

So this is the hardware that is installed:

  1. The on and off switch, that just cuts power to the arduino from the battery.
  2. The shutter button, a normal push button that controls the shutter in single shot mode, and the interval in time lapse mode.
  3. The mode toggle switch, that switches the arduino between interval or time lapse mode, and single shot mode.
  4. The manual shutter control toggle switch, that tells the arduino to use 2 delays, one for the shutter speed control (the delay between the pulses that opens and closes the camera) and then the other delay to control the interval (between shots).
  5. The potentiometer that I want to use to control the delay that controls the shutter speed. (at first I just want this to control the physical shutter speed, because that is what I can't get to work now, and then later I will just add some code which wouldn't be to hard, that actually makes the potentiometer control the amount of milliseconds that the arduino adds/subtracts from the shutterspeed. Basically the rate at which the arduino makes the exposure longer or shorter)

Basically I already wrote all the code, but I just can't get it to use two different delays between when the manual shutter speed control toggle switch (hardware installed nr. 4 above) is turned on.
And if I tell it to print the value it gets from the potentiometer if the switch 4. is turned on, it weirdly only prints that value if I press the button to assign a different interval, which should be totally independent of the shutter speed delay, they are totally different delays in separate places. And then on the serial monitor it only returns a 0 no matter where my potentiometer is set. So I can't get it to properly read the potertiometer with analogread. There is nothing wrong with my hardware because the example sketch that reads the potentiometer works perfectly.

Everything works, except the new feature that adds another delay to control the shutter speed also. This is just a reminder, this feature should allow me to get smooth timelapses where the exposure slowly changes to compensate for the change in lighting when the sun rises or sets.

Thanks to anyone willing to take a look.

Code attached

Nikon_IR_Remote_Control.ino (4.81 KB)

I was willing to help but I cannot see your code on my mobile device because you posted improperly. The forum tells me that you have posted three times. By now you should have read the locked posts at the top of this forum and posted properly. Good Luck and goodbye.

The OP's code posted in the preferred manner

// Nikon Remote Emulator
// A1 = IR +
// A0 = IR -

int count = 0;
const int buttonPin = 2;  //shutter release button
const int modePin = 12;   //toggle switch to switch between single shot mode (uses button to release shutter) and time lapse mode (automatically releases the shutter every x seconds)
const int mShutterPin = 7;
const int potentPin = A4;

int buttonState = 1;  //reads if the shutter button is pressed
int modeState = 1;   //reads in what mode the remote is set (single shutter release/time lapse)
int tlinterval = 1000;
int mShutterState = 0;
int potentValue = 0;
int shutterSpeed = 0;
//////////////////////////////
int lastButtonState = 1;
unsigned long startMillis = 0;
unsigned long endMillis = 0;



void setup()
{
  pinMode(A3, OUTPUT); //5V to potentiometer
  digitalWrite(A3, HIGH);
  pinMode(A5, OUTPUT);  //ground to potentiometer
  digitalWrite(A5, LOW);
  pinMode(6, OUTPUT);
  digitalWrite(6, LOW);
  pinMode(A0, OUTPUT); //negative output to IR led
  digitalWrite(A0, LOW);
  pinMode(A1, OUTPUT); //positive outuput to IR led
  digitalWrite(A1, LOW);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(modePin, INPUT_PULLUP);
  pinMode(mShutterPin, INPUT_PULLUP);
  pinMode(potentPin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  // Send code three times, as the clone remote does
  // Delays are tuned to account for overhead of library code.
  modeState = digitalRead(modePin);
  buttonState = digitalRead(buttonPin);
  mShutterState = digitalRead(mShutterPin);
  potentValue = analogRead(potentPin);
  if (buttonState != lastButtonState && modeState == 1)
  {
    if (buttonState == LOW)
    {
      startMillis = millis();
      //Serial.print("Button Pressed");
      Serial.print(buttonState);
    }
    else
    {
      endMillis = millis();
      //Serial.print("Button Depressed");
      tlinterval = endMillis - startMillis;
      //Serial.print(tlinterval);
    }
    lastButtonState = buttonState;
  }
  if (modeState == 0)   //Single shot mode
  {
    while (buttonState == 0)   //Checks if shutter button is pressed
    {
      //while(count<3) {     //the following lines are just the one signal to trigger a Nikon camera
      tone(A1, 38000);
      delay(2);
      noTone(A1);
      delay(28);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(1500);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(3300);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(100);
      delay(63);
      count++;
      //}
      buttonState = digitalRead(buttonPin);
      count = 0;
    }
  }
  if (modeState == 1)      //set to time lapse mode
  {
    //while(count<3) {
    if (mShutterState == 0)
    {
      //
      digitalWrite(A3, HIGH);
      digitalWrite(A5, LOW);
      potentValue = analogRead(potentPin);
      tone(A1, 38000);
      delay(2);
      noTone(A1);
      delay(28);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(1500);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(3300);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(100);
      delay(63);
      //count++;
      delay(potentValue);   //I want this time value to be a variable and therefore easily controlled
      Serial.println(potentValue);
      tone(A1, 38000);
      delay(2);
      noTone(A1);
      delay(28);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(1500);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(3300);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(100);
      delay(63);
      //  count++;
      delay(tlinterval);   //I want this time value to be a variable and therefore easily controlled
      //
    }
    if (mShutterState == 1)
    {
      tone(A1, 38000);
      delay(2);
      noTone(A1);
      delay(28);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(1500);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(3300);
      tone(A1, 38000);
      delayMicroseconds(200);
      noTone(A1);
      delayMicroseconds(100);
      delay(63);
      delay(tlinterval);
      count++;
      //}
      count = 0;
    }
  }
}

Yes. I wanted to post the code like that but it said I've reached my maximum word count. So I added the file. But thank you. Now everyone can see.

it said I've reached my maximum word count.

Combined with your actual post I am sure it did, but in a separate post like mine it is OK. At least you attached it, which was a good second best, rather than providing a link to somewhere where it was hosted

What are the values you get from the potentiometer?
How did you connect the potentiometer to the arduino?
post a hand drawn schematic

OK I have looked into your code
reading in the analog-value looks OK

the analog-read has a max value of 1023. if you code

delay(potentValue);

the maximum delay-time will be 1023 microseconds = 1,023 seconds.
To get larger times you can use the map-function

the map-function translates an value to a different value-range

best regards Stefan

"the maximum delay-time will be 1023 microseconds = 1,023 seconds"

Actually, that should be

the maximum delay-time will be 1023 microseconds = 1.023 milliseconds

(Yes, I understand that some locales use a comma instead of a period. The important part is the use of milliseconds and not seconds.)

Hallo everyone. Thanks for coming back.

Yes I understand that my maximum shutter speed will be just over one second. But that is how I wanted it to be for testing purposes. Then later I can let it add to the shutter speed value every time the loop completes therefore slowly increasing or decreasing the shutter speed.
But the thing is if I let it print in the serial monitor, the value, it only prints 0, and it also only prints that if I decide to press the push button that is used to change the second variable, the one that changes the interval, so I can't understand why that is interfering with a totally different variable. So the button should not be determining if it should print the potentiometer value at all, nevermind print a 0, no matter how the potentiometer is set. And as I said, I did test the hardware, everything works just fine. To be exact, I think the potentiometer returns an 8 or 9 when it is turned all the way down.

I see now that I didn't put the pin 7 as an input and then also not as an input pullup. But this did not fix the problem.

Here is the updated setup part of the code:

pinMode(A3, OUTPUT); //5V to potentiometer
  digitalWrite(A3, HIGH);
  pinMode(A5, OUTPUT);  //ground to potentiometer
  digitalWrite(A5, LOW);
  pinMode(6, OUTPUT);
  digitalWrite(6, LOW);
  pinMode(7, INPUT_PULLUP);
  pinMode(A0,OUTPUT);  //negative output to IR led 
  digitalWrite(A0,LOW);
  pinMode(A1,OUTPUT);  //positive outuput to IR led
  digitalWrite(A1,LOW);
  pinMode(buttonPin, INPUT_PULLUP); 
  pinMode(modePin, INPUT_PULLUP);
  pinMode(mShutterPin, INPUT_PULLUP);
  pinMode(potentPin, INPUT);
  Serial.begin(9600);

Attached is a picture of the schematic.

The problem must be narrowed down. This means check everything. Even the most obvious things.

So did you test reading your potentiometer with a small testcode that does nothing else than analogRead and print
and this is working?
I mean an extra-sketch with just this small funcionality

Do you have a digital multipmeter to check if the voltage on the potentiometers middle-pin is changing when turning the potentiometer?

best regards Stefan

pinMode(A3, OUTPUT); //5V to potentiometer
  digitalWrite(A3, HIGH);
  pinMode(A5, OUTPUT);  //ground to potentiometer
  digitalWrite(A5, LOW);

Why use digital pins to provide 5V and GND when you can simply connect the ends of the pot between 5V and GND ?

  pinMode(A0,OUTPUT);  //negative output to IR led
  digitalWrite(A0,LOW);
  pinMode(A1,OUTPUT);  //positive outuput to IR led
  digitalWrite(A1,LOW);

Does the second comment match what the code does ?