We can help. If we don’t do this, then previousTime_1 will always be set to 0, and from here forward our if statement will always be true, and the LDR will just continuously be read and displayed. This is where most of you code goes, reading sensors sending output etc. Example Code Let’s use the standard 9600 baud rate. So let’s upload the sketch and test it out. We’re going to create a currentTime variable and it’s going to be constantly updated via the millis function. Well, bear with me if memory serves and most of the time, the vast majority of the time it does what we’ll do is: we’ll have a power supply here, cetera 24 volts, because I remember these numbers and we have a in Arduino microcontroller here. int LED1 = 12; int LED2 = 13; int … to run multiple loop at the same time, independently, you should ... NOT use a second loop ! Second Time Through the Loop. We want the light-dependent resistor to read and display every second and the temperature sensor to read and display every five seconds.So now we have our two separate events. Before we get too crazy, let’s write ourselves a little “to-do list” in comments. Basically just check the millisecond timer and call a couple of functions at the appropriate times - one function to do the fading for one LED, and the other to do the blinking for the other LED. Think of the algorithm as our plan of action. Learn everything you need to know in this tutorial. Change language ... increment: executed each time through the loop when condition is true. ), great!! I would like to plug this in to a few timing projects. Please I have a puestion??? Again, there’s a whole series on using this millis function. We look forward to seeing you next time! Now let’s get into the loop. they will never change, so let’s make these constants. nice tutorial !! Using Arduino: run a loop 10 times, then pause for some time, then repeat. We want to update the current time, and we want to do it frequently, hence why we’re using the loop section. For example, you may want a servo to move every 3 seconds, or to send a status update to a web server every 3 minutes. I currently can only run LED() first and then once LED() is finished, only then the IR() will run. We hope you enjoyed this lesson. We will use the Serial.begin() function from the Serial library to initiate Serial communication. Event 2 will read the temperature sensor and display it’s value every five seconds. The first thing to do is to add a loop timer to keep … Please keep in mind the focus of this lesson is demonstrating how to code timed events with Arduino, so we won’t go into detail on how to set up your actual circuit for this experiment. element14 is the first online community specifically for engineers. More knowledgeable programmers usually avoid the use of delay() for timing of events longer than 10’s of milliseconds unless the Arduino sketch is very simple. Arduino Timers. I already tried making another void loop, but it does not work. Off the top of my head I couldn't say if a while or for was more efficient, but personally for a fixed number of iterations I would go for a for loop, if I had to do a while loop then I would set I to zero so I could do (i