Switch to Manuel during Loop

Hi,

I am very new and my programming is in the beginning so i have a short question, hope you can help me out.

I am working on a Motor that is controlled over a relai board, that is allready working...

It shoul be used as Aquarium Filter turn every 24h, so i wrote a code that put operation high for 250ms every 24h 86400000ms

Between Motor and Ralai i have a speed controller with switch between forward and backward.. normal is forward, but to switch filter i need to but it in reverse and than i want to push a botton, during that time the motor should spin.

My problem is during the 24h waiting periot in the [loop] it does not matter if i push my capacitv sensor or not..it will i just have like 1sek a day i could touch the botton :smiley:

I need help to fix that.

It should stay in the normal mode 24h wait / 250ms spin when the botton is NOT pushed,.. if i push it it should spin

MY Code:

int relais1pin = 1;
int relais3pin = 3;
int relais4pin = 4;
int sensorpin = 2;

void setup() {
pinMode(relais1pin,OUTPUT);
pinMode(relais3pin,OUTPUT);
pinMode(relais4pin,OUTPUT);

Serial.begin(9600);
pinMode(sensorpin, INPUT);
pinMode (LED_BUILTIN, OUTPUT);
}

void loop() {

int sensorstate = digitalRead(sensorpin);
if (sensorstate == 1) {
Serial.println("Cap. Sensor active");
digitalWrite(LED_BUILTIN, HIGH);

digitalWrite(relais1pin,HIGH);
digitalWrite(relais3pin,HIGH);
digitalWrite(relais4pin,HIGH);

} else {

Serial.println("Cap. Sensor not active");
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW

// move
digitalWrite(relais1pin,HIGH);
digitalWrite(relais3pin,HIGH);
digitalWrite(relais4pin,HIGH);
delay(15000);

// not move
digitalWrite(relais1pin,LOW);
digitalWrite(relais3pin,LOW);
digitalWrite(relais4pin,LOW);
delay(250);

}

delay(10);

}

My problem is during the 24h waiting periot in the [loop] it does not matter if i push my capacitv sensor or not..it will i just have like 1sek a day i could touch the botton

So, you need to get rid of all the calls to delay
Have a look at the blink without delay example in the IDE.

Please remember to use code tags when posting code.

You can also check out my tutorials on How to code Timers and Delays in Arduino
and Multi-tasking in Arduino
Also if you are using a physical switch, check out my debounce tutorial and code

The functions delay() and delayMicroseconds() block the Arduino until they complete.
Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R

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