Bi-Directional Alarm Device Using Two Photodiodes and LDR

I am working on a project that requires me to use an Arduino Uno to create an alarm system with a On/Off switch, Light detector to determine whether or not the alarm is active( in this case light must be on for it to work - LDR), two photodiodes to determine bi-directional entrance or exit of a person, a potentimometer used as variable resistor, and an 8 ohm speaker. It must also increment and decrement when someone enters or leaves.

This is my code. Please help me out.

/* ON/OFF switch */
int switch1 = 14;
int led4 = 4;
int reading1;
int state = LOW;
int long time = 0;      
int long debouce = 200; 

/* Photocell */
int photocell = A3;
int led3 = 8;

/* Photodiodes */
int led1 = 13;
int led2 = 12;
int sensorpin1 = A1;
int sensorpin2 = A2;                           
int resetteller1 = 0; 
int resetteller2 = 0;
int sens1 = 0;
int sens2 = 0;
int teller1 = 0;
int teller2 = 0;
int basis1 = 1024;
int basis2 = 1024;
int testa = 1024;
int testb = 1024;
int test2a = 1024;
int test2b = 1024;
int test3a = 1024;
int test3b = 1024;
// values to play with to get better (or worse) results
int marge1 = 2;
int marge2 = 2;
int vertraging = 1;
int samples1 = 70; 
int samples2 = 70;
int count = 0;

/* Speaker */
int speakerOut = 6;
int c = 3830;
int b = 32;
int tone_ = 0;
int beat;
int tempo = 10000;
long duration  = 0;
int rest_count = 100;
int MAX_COUNT = sizeof(c) / 2;
int DEBUG = 1; 

void setup() {
  pinMode(switch1, INPUT);
  pinMode(led4, OUTPUT);

  pinMode(photocell, INPUT);
  pinMode(led3, OUTPUT);
  
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(sensorpin1, INPUT);
  pinMode(sensorpin2, INPUT);
  
  pinMode(speakerOut, OUTPUT);
  
  if (DEBUG) {
    Serial.begin(9600);
  }
  
  Serial.begin(9600);  
  
  for(teller1 =0; teller1 < samples1; teller1++) {
   sens1 = analogRead(sensorpin1);
   if (sens1 < basis1){basis1 = sens1;}
   delay(vertraging);                       
   }
   
  for(teller2 =0; teller2 < samples2; teller2++) {
   sens2 = analogRead(sensorpin2);
  if (sens2 < basis2){basis2 = sens2;}
  delay(vertraging);
  }
}

void loop() {
  
reading1 = digitalRead(switch1);
  
int v = analogRead(photocell);

if (reading1 == HIGH){
  if (state == LOW){
    state == HIGH;
    digitalWrite(led4, HIGH);
      
      if( v >= 900 ){
        digitalWrite(led3, HIGH);
        
        for(teller1 = 0; teller1 < samples1; teller1++) {
     sens1 = analogRead(sensorpin1);
     delay(vertraging);
   
     if (sens1 < testa){
       test3a = sens1;
       test2a = test3a;
       testa = test2a;
     } // end if
  }// end for
  
  for(teller2 = 0; teller2 < samples2; teller2++) {
     sens2 = analogRead(sensorpin2);
     delay(vertraging);
     
       if (sens2 < testb){
         test3b = sens2;
         test2b = test3b;
         testb = test2b;
       } // end if
   } // end for
   
   if (testa < basis1 - marge1 && test2a < basis1 - marge1 && test3a < basis1 - marge1){
    digitalWrite(led1, HIGH);
    resetteller1++;      
   } // end if
    else{
      digitalWrite(led1, LOW);
      basis1 = testa;                                        
      resetteller1 = 0;
    } // end else
    
    if (test2b < basis2 - marge2 && test2b < basis2 - marge2 && test3b < basis2 - marge2){
    digitalWrite(led2, HIGH);
    resetteller2++; 
} //end if 
    else{
      digitalWrite(led2, LOW);
      basis2 = testb;                              
      resetteller2 = 0;
    }// end else
      
        incrementSensor(count); 
        
      Serial.print("Number of People: ");
      Serial.print(count);
      Serial.print("\n");
      delay(1000) ;
      }//end if      
       else{
         digitalWrite(led3, LOW);
       }// end else       
   }//end if
}
  else {
  state = LOW;
  digitalWrite(led3, LOW);
  digitalWrite(led4, LOW);     
  time = millis();
} // end else
    testa = 1024;
    testb = 1024;
}// end main
   
/*void incrementSensor() {
  
  int count = 0;
  int val1 = analogRead(sensorpin1);
  int val2 = analogRead(sensorpin2);

  if(val1 < 1000){
      count = count + 1;
      for (int i = 0; i < MAX_COUNT; i++) {
    tone_ = c;
    beat = b;
    duration = beat * tempo;
    playTone();   
    delayMicroseconds(1000);
      }
      delay(500);
    }//end if
    
  if (val2 < 1000){
    count = count - 1;
    for (int i = 0; i < MAX_COUNT; i++) {
    tone_ = c;
    beat = b;
    duration = beat * tempo;
    playTone();   
    delayMicroseconds(1000);
    }
    delay(500);
      if (count == -1){
        count = 0;
      }
  }
}*/

void playTone() {
  long elapsed_time = 0;
  
  if (tone_ > 0) { 
 
    while (elapsed_time < duration) {

      digitalWrite(speakerOut, HIGH);
      delayMicroseconds(tone_ / 2);

      digitalWrite(speakerOut, LOW);
      delayMicroseconds(tone_ / 2);

      elapsed_time += (tone_);
    } // end while
  } // end if
  else {
    for (int j = 0; j < rest_count; j++) { 
      delayMicroseconds(duration);  
    } // end for                               
  } // end else                                
} // end function playTone

 int incrementSensor(int count)
{  
  if (led1 == HIGH){
    
    for(int x = 0; x < 1000; x++){
      delay(10);
      
      if(led2 == HIGH){
        count++;
        
        for (int i = 0; i < MAX_COUNT; i++) {
          tone_ = c;
          beat = b;
          duration = beat * tempo;
          playTone();   
          delayMicroseconds(1000);
        }// end for
      }// end if
    }// end for
  }// end if   
  
 if (led2 == HIGH){
    
    for(int y = 0; y < 1000; y++){
      
      if (led1 == HIGH){
        count--;
        
        for (int i = 0; i < MAX_COUNT; i++) {
          tone_ = c;
          beat = b;
          duration = beat * tempo;
          playTone();   
          delayMicroseconds(1000);
        }
      }
    }
  }
  return count;
}// end function increment

Kensai231:
Please help me out.

Help you with what?

You have not said what the problem is.

And "it doesn't work" is not an appropriate answer - even if it is true.

...R

Please help me out.

Which way did you come in?

I can't get the incrementer or speaker to function. It keeps coming up as zero people entered and the alarm won't sound either way.

What do you think might be the cause of the problem?
What tests have you carried out to verify your guess?

You don't seem to have any Serial.println() statements in your code to allow you to see what is happening and give you some idea where it is failing.

...R