millis()

I've got 2 outputs that can be turned ON at any time I want. It will automatically turn OFF after 1 minute. I am using the millis() function. My problem is I can turn ON the outputs at different time but they always turn OFF at the same time.

I turned ON output1 first, then after 10 seconds while output1 is still turned ON, I turn ON my output2. Since I set that they will automatically turn off after 1 minute from the time they are turned ON, my output1 should be OFF first then after 10 secs my output2 then will be turned OFF. But what I encounter is that by the time my output1 is turned OFF, my output2 is also turned off simultaneously with output1. What do I need to do to fix this?

Please post your full sketch.

If possible, you should always post code directly in the forum thread as text using code tags:

  • Do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code. This will make it easier for you to spot bugs and make it easier for us to read.
  • In the Arduino IDE or Arduino Web Editor, click on the window that contains your sketch code.
  • Press "Ctrl + A". This will select all the text.
  • Press "Ctrl + C". This will copy the selected text to the clipboard.
  • In a forum reply here, click the "Reply" button.
  • click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum's code tags markup to your reply.
  • Press "Ctrl + V". This will paste the sketch between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.
  • Repeat the above process if your sketch has multiple tabs.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the 9000 characters maximum allowed by the forum, then it's OK to add it as an attachment. After clicking the "Reply" button, you will see an "Attachments and other settings" link.

When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Every millis-timer needs its own 'previousMillis'.
In my single shot timer every added single shot timer needs its own 'previousMillis', 'enable' and 'interval'.

Post your sketch, it seems that you are using millis() in the wrong way.

My problem is I can turn ON the outputs at different time but they always turn OFF at the same time.

A wild guess would be that you are using the same variable to hold the start time of the 2 separate 1 minute periods, but until we see your code, who knows ?