Skipping one loop


Am a newbie,

Am using my Arduino mega to control my greenhouse (30'x65'), am saving the temperature to a database via mysql_connector, that woks fin, but right now am saving the data every minute with Delay() function, is there a way I can skip that loop with a timer instead?

Thanks for you help


//**************  Void loop   ******************************************

void loop() {

 buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    Serial.println ( "Rekay On*********************" );
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    Serial.println ( "Rekay Off**********************" );

    saveTempData(); //need to run this only once a minute 


What do you mean, "skip that loop with a timer instead"?

You say, "right now am saving the data every minute with Delay() function" but there is no delay() function in the code you posted. Please post your most up to date code, all of it! While you are at it, remove the superfluous blank lines in your sketch.

Here’s my code
Thanks for your help

sketch_mar17a.ino (11.5 KB)

Please post the whole sketch in code tags. Many members do not have the IDE or any app to view .ino files on their devices (phones, tablets) so they will not be able to respond with help. You are missing out on some good assistance.

You want to get rid of this?


read this:

Please post the whole sketch in code tags.

I think it's too big to post inline. Use of arrays could make it probably 1/6 the size or less. :wink:


I will read the tread you posted

Thanks for your help


Hello Frank,

++Karma; // For posting your code in code tags on your first post.

Please can you read
General guidance
And How to use this forum

The difficulty in helping you is we need complete code and we need what you say to match what the code is.

You also need to learn to not use delay(), it causes problems with slow, unresponsive code. Have a read of
Using millis for timing
Demonstration for several things at the same time

Sorry for not being clear on my post, I will read what you suggested me.

Thanks again