Hi, I am pretty new to Arduino and I was wondering how I would have a specific length of time for one of my codes. I am running a DC Motor using Arduino, but I only want it to spin for a duration.
I want it to spin for 5 seconds and then stop for 2 minutes and that is on a loop.
Can anyone assist me in writing this code?
Thank you
Assuming you have taken care of the electrical aspects, like using a mosfet say to switch the motor off and on based on an Arduino pin, and further assuming that the code doesn't need to do anything else like react to buttons in real time, you could surely simply adapt the blink (with delay) example to match your on and off times.
If the code does need to do other things and not get blocked by such delays, look at blink without delay.
gary-tran:
I want it to spin for 5 seconds and then stop for 2 minutes and that is on a loop.
Can anyone assist me in writing this code?
void loop()
{
digitalWrite(MotorPin, HIGH); // I want it to spin...
delay(5000); // ... for 5 seconds ...
digitalWrite(MotorPin, LOW); // ... and then stop ...
delay(2UL * 60UL * 1000UL); // ... for two minutes ...
} // ... and that is on a loop