I´m stuck with a wierd problem. My delay isn´t delaying when it should.
#include <Servo.h>
Servo trigger;
void setup() {
trigger.attach(3);
digitalWrite(10,LOW);
delay(10000); //Here is no delay
trigger.write(90);
delay(750); //The servo waits 10s here
trigger.write(0);
delay(750);
digitalWrite(10,HIGH);
}
Please help, I´m lost.
Of course delay() works. Why do you think it is not?
Note that a servo might move upon startup. You should send a neutral or other position command right after attach(), so you know that the servo is properly adjusted.
But at the wrong position. The first 10s delay does nothing and the second 750ms delay goes for 10s. Also the digital write does nothing.
system
June 24, 2018, 9:20pm
4
Also the digital write does nothing.
It turns off, then later on, the pull-up resistor for pin 10
It should turn on a relay which has worked before. But why are the delays shifted
system
June 24, 2018, 9:25pm
6
Woodpeckerfpv:
It should turn on a relay which has worked before.
For that, it would have to be an output pin.
You have still not provided any evidence that delay() is not working.
Since you have no idea what the servo is going to do (especially if you are mistakenly trying to power it from the Arduino 5V, instead of from an independent servo power supply), you should test the delay function by turning on and off an LED instead.
The servo is powered by the 5v and every thing worked flawless untill I added the the line of code that activates the relay.
system
June 24, 2018, 9:35pm
9
Which line activates the relay?
The servo is powered by the 5v
You will eventually destroy the Arduino doing that, guaranteed.
Use a 4xAA battery pack, or other 5-6V power supply capable of providing at least 1 Ampere, and connect the grounds.
digitalWrite(10, LOW);
thanks for the advice about the servo
system
June 24, 2018, 9:41pm
12
That line turns off the input pin's pull-up resistor.
I've already mentioned this.
Pin 10 has to be GND to trigger the relay. The internet says thats the way to go
system
June 24, 2018, 9:47pm
14
And how does that work, on an input pin?
I´ve read that an input/output pin set to LOW works as gnd. And it worked preveosly for me.
system
June 24, 2018, 9:53pm
17
Previously, perhaps, you told it to be an output pin
Ok I got that fixed but the delays are still the wrong durations. The Relay activates and the servo at almost the same time
system
June 24, 2018, 9:58pm
19
Let's see the code, and let's hear your observations and reasoning.
#include <Servo.h>
Servo trigger;
void setup() {
trigger.attach(3);
pinMode(10, OUTPUT);
digitalWrite(10,LOW);
delay(10000);
trigger.write(90);
delay(750);
trigger.write(0);
delay(750);
digitalWrite(10,HIGH);
}
void loop() {
}
Relay activates
imedeatly
2.servo turns to 90°
10s delay
3.servo turns to 0°
750ms delay
4.relay deactivates