ARDUINO Projects

  • laser counter

    The main idea of this project is how can you know how many people come in or out from your office ,
    or shop and it's can be also for cars garage to know how many cars exist in the garage.
    this system working from a far distance because it's use laser diode as an interrupt when the first laser diode cut that's mean someone comes in ,
    and after cutting the second laser the processor counts one person or anything has been enter.
    and when the second laser cutting the processor activates the out flag and waiting for cutting the first laser and when that happened the counter
    decrease the number of the people or anything else.
    If the only first laser cutting and the second not,then the order for counting it
    will be canceled and the second one also work the same way.

    Demonstration

    We connect the LDR with the VCC and 10k ohm to analog pin2 A1.
    And we connect the second one the same way but to analog pin2 A2.
    The laser diode you can install it independently from a far distance.

    Post
    We need to install timer one library for timer interrupt:- TimerOne.h
    Arduino code
    #include <TimerOne.h>
    #define L A0
    #define R A1
    int counter;
    volatile int flagL;
    volatile int flagR;
    void setup() {
      Serial.begin(9600);
     Timer1.initialize(3000000);
     Timer1.attachInterrupt(flags);
      Timer1.stop();
    }
    
    void loop() {
      if(analogRead(L)>=90)
      {
        if(flagR==1)
        {
          Timer1.stop();
          counter++;
          Serial.print("people out:");
          Serial.println(counter);
          flagL=0;flagR=0; 
        }
        else
        {
        flagL=1;
        Timer1.resume();
        }
        while(analogRead(L)<=90){};delay(250);
      }
      if(analogRead(R)>=90)
      {
        if(flagL==1)
        {
          Timer1.stop();
          counter--;
          Serial.print("people In:");
          Serial.println(counter);
          flagL=0;flagR=0;
          }
        else
        {
        flagR=1;
       Timer1.resume();
      }
      while(analogRead(R)<=90){};delay(250); 
    }
    }
    void flags()
    {
      Serial.println("flags off");
      flagL=0;flagR=0;Timer1.stop();
    }