Delay problem

Dear friends,

I have written a program to send a digital value from an input pin to an output pin. My objective is to " read the status of a sensor connected to an input pin and write this status to an output pin. If the input pin is high, I wish to set the output pin high and keep it high for 2 seconds. Then, turn the output pin pin off after 2 seconds and wait for 5 minutes. Again, check the status of the input pin. If it is high, set the output pin high again and keep it high for 2 seconds..." I like to repeat this procedure over and over again.

The problem is: For a few times (once or twice), the 5 minutes delay is caccurate. After a few time, the five-minutes delay get longer and longer. I checked it with a one-minute long delay. There is the same problem as the five-minutes delay. The very first few times, one-minute delay works fine. After several time, the accuracy goes down and the delay time gets longer. The program is as follows:

const int inputPin = 12;
const int outputPin = 13;

void setup(){

void loop(){
    delay(1000L*2L); // 2 sec
    delay(1000L*60L*1L); // 1 min

You don't enable pullups on output pins. Fix or remove the faulty comment.

Evidence? I don't see any evidence of your claim.

digitalWrite(inputPin,LOW); //pull-up enable

...and you don't enable pullups on input pins by writing a LOW.


Thank you very much for the comments. I removed the comments regarding the pull-up enabling. However, I do not see anything wrong with the program itself. It should work as far as I see. I have the transmitter and receiver part. In the receiver part, I have the Arduino to control the ON/OFF switching. The whole circuitry and the Arduino are powered with a 5 V battery. How can be a problem with the grounding?


You've still offered no evidence that you have a problem. Add some Serial.print() statements, to print millis() at the start and end of the delay()s. Show us that there is a problem.


Actually, I do not know such functions. Let me study a little bit to understand what you are talking about. I modify the program and post it again tomorrow.

Thank you very much all.