using optical gates to count how many peapole are in a room with(b83609)

Heres my code so far.

int encoder1_pin = 2;
int encoder2_pin = 4;
unsigned int bentiek;
#define RELAY1  7
#define RELAY2  6
void setup() {
 // put your setup code here, to run once:
 pinMode(encoder1_pin, INPUT);
 pinMode(encoder2_pin, INPUT);
 bentiek=0;
 Serial.begin(9600);
 pinMode(RELAY1, OUTPUT);   
 
}
void loop() {
 if(encoder1_pin == LOW){
   if(encoder2_pin == LOW){
     bentiek + 1;
   }else{digitalWrite(RELAY2,0);
          delay(10000);
          digitalWrite(RELAY2,1);};
 }
 if(encoder2_pin == LOW){
   if(encoder1_pin == LOW){
     bentiek - 1; 
   } else{digitalWrite(RELAY2,0);
          delay(10000);
          digitalWrite(RELAY2,1);};
 };
if(bentiek == 0 ){digitalWrite(RELAY1,0);} else  {delay(60000);
 digitalWrite(RELAY1,1);}
Serial.print (bentiek
                 );
}

(bentiek stands for peapole inside the room )
Heres the data sheet: www.ekt2.com/pdf/412_CH_SMART_SHAFT_ENCODER_KIT.pdf
And the code also sets of a second relay that turns on a siren if someone has onli gone half way through or if another peolple started entering the room before the other one had gone through the second gate.
Sory but i for some reson cant upload a pictere of the wiraing.

May be describe how this code is supposed to work and what you are doing with the relays. Supply a picture of how it is wired up and explain your choice of B83609 sensors for counting people in a room.

Please post a link to the datasheet for the B83609.

Also tell us what your program actually does when you run it and what you want it to do that is different.

…R

PS … To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

The delays prevent your code from working properly.

Answer to yourself:

  • How many sensors can be covered by one person?
  • How do the signals change if one person goes through, goes back, a second person enters...

What you need is a state machine, with states like
empty, one_in, one_through, one_back, two_in

Then determine whether changes in the sensor values allow to determine the new state of that machine, and to count the persons properly.

Tanks DrDiettrich!
For the sugeston but is there a way to make the code so if someone there was a person in the room but left that the relay only turns of whena cearin time has pased

That's possible, of course. But before that you should implement the state machine, which is the base for all further actions.