trouble using delay()

I’m very newby with arduino… I’m currently trying to use small servos (as gates) related to infra-red gates. Long story short: each time a honeybee breaks the IR beam, it closes the doors (monitored by servos) for 8 sec. and then reopen it. I’ve got 2 of those gates + IR beam, that are susceptible to work in the same time.
I’ve got in mind to use the ‘delay()’ function in order to specify the 8 sec of closing door. But I can’t use the 2 systems in parrallelle as soon as one IR beam is broken and 1 gate is closed, as it shut all the system down for 8 sec…

Here is my code. If someone has any idea, please let me know :slight_smile:

#include <Servo.h>
Servo myservo2; // creating myservo1 object
Servo myservo4;
int openpos = 120;
int closedpos = 60;
int piPin1 = 4;
int piPin4 = 1;
int servoPin1 = 10;
int servoPin3 = 8;
int piState1 = 1; // set piState1
int piState4 = 1; // set piState1

void setup()
pinMode(piPin1, INPUT);
pinMode(piPin4, INPUT);

void loop()
{ piState1 = digitalRead(piPin1);
if (piState1 == LOW){

piState4 = digitalRead(piPin4);
if (piState4 == LOW){

See the "Blink Without Delay" example. You're going to have to record the time returned by millis() and add a condition to the if statements that checks to see if it has been 8 seconds since the door was closed or not.

Or a more complex version how to do many things at the same time.


PS As a newbie forget that delay() exists.


holmes4: Or a more complex version how to do many things at the same time.

an extended :) :) :)