# Timer without delay 2

**URL:** <https://forum.arduino.cc/t/timer-without-delay-2/946505>\
**Category:** Sensors\
**Created:** [January 13, 2022, 8:19am UTC](https://forum.arduino.cc/t/timer-without-delay-2/946505 "2022-01-13T08:19:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leigh1973](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@leigh1973](https://forum.arduino.cc/u/leigh1973)\
**Post date:** [January 13, 2022, 8:19am UTC](https://forum.arduino.cc/t/timer-without-delay-2/946505/1 "2022-01-13T08:19:35Z")

</div>

Hi all. I'm very inexperienced with Arduino. I've made a small submersible. It has a magnetic switch that turns on a motor for a set length of time. To do this I've used a very simple if statement with a delay to time it.

sketch here  
#include \<Servo.h\>

Servo esc;  
Servo servo;  
void setup()  
{  
esc.attach(3);  
servo.attach(2);

Serial.begin(9600);  
// Since the other end of the reed switch is connected to ground, we need  
// to pull-up the reed switch pin internally.  
pinMode(Reed, INPUT\_PULLUP);  
esc.writeMicroseconds(1000); // send "stop" signal to ESC. Also necessary to arm the ESC.  
delay(5000);  
servo.write(90);  
}

void loop()  
{  
esc.writeMicroseconds(1000); // send "stop" signal to ESC. Also necessary to arm the ESC.  
int proximity = digitalRead(Reed); // Read the state of the switch  
if (proximity == HIGH) // If the pin reads low, the switch is closed.  
{

```
esc.writeMicroseconds(1000); // send "stop" signal to ESC.;       

```

delay(15);  
}  
else  
{  
delay(1000);  
esc.writeMicroseconds(2000); // send "stop" signal to ESC. Also necessary to arm the ESC.; // sets the servo position according to the scaled value  
delay(60000);  
}

}

I've since added a servo connected to a rudder that uses an HMC5883L magnetometer sensor to keep the sub in a straight line.

So my question is, how do I time the esc to turn off after a set amount of time while allowing the programme to routinely check the magnetometer and adjusting the servo accordingly

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [January 13, 2022, 8:29am UTC](https://forum.arduino.cc/t/timer-without-delay-2/946505/2 "2022-01-13T08:29:08Z")

</div>

Take a look at the blink without delay example in the IDE, without delay.

Please remember to use code tags when posting code

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 13, 2022, 8:40am UTC](https://forum.arduino.cc/t/timer-without-delay-2/946505/3 "2022-01-13T08:40:44Z")

</div>

> [@leigh1973](#):
>
> sketch here

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'  
  
Use [color = red] **code tags** [/color] (the \</\> icon above the compose window)&nbsp;to make it easier to read and copy for examination

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behavior and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is frus…

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 12, 2022, 8:41am UTC](https://forum.arduino.cc/t/timer-without-delay-2/946505/4 "2022-07-12T08:41:31Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
