EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Automatic Bidirectional Visitor Counter

Automatic Bidirectional Visitor Counter

|

Microcontroller › 8051 › Automatic Bidirectional Visitor Counter

  • This topic has 14 replies, 9 voices, and was last updated 9 years, 10 months ago by jani.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • April 6, 2012 at 12:31 pm #1522
    Sindujaa
    Participant

     

    I’m currently trying Automatic Bidirectional Visitor Counter project given in your site.
    I request you to explain the program flow of the C coding given.
     
    And also please do let me know asap whether the 7-segment display used here is a Common Anode configuration or a Common Cathode Configuration and whether we can do the project with AT89S52 instead of AT89C51.
    April 16, 2012 at 6:10 am #7460
    hari krishna
    Participant

    Hi Sindujaa

     

    Displays are common anode.

    you can use AT89s52 insted of AT89c51 differences only memory size and one timer added extra in 52.

     

     

    Regards,

    Hari krishna k

    April 18, 2012 at 12:32 pm #7477
    AJISH ALFRED
    Participant

    From the circuit, it can be found that the seven segment is switched to +5V using a transistor. So I think it is common anode

    September 25, 2012 at 6:26 pm #8610
    hariom jangid
    Participant

    There are a problem occuring with up key and down key. If we press up key for few second then counter increse no of visitor.suppose that a men stop at position of up sensor for few second then counter count the many people in room.

     

    October 29, 2012 at 12:04 pm #8699
    kangibnu
    Participant

    I‘ve tried make visitor counter circuit and successful, and I want to combine it with articel read write eeprom (I tried it and succeeded), but when I try to combine both methods the program does not work, please help, I want to store data in the eeprom at24c16 count, and show on seven segment display,

    here the code…

    #include<reg51.h>
    #include<intrins.h>
    #define msec 50
    #define lcd_data_str_pin P0
    bit ack;
    sbit rs = P3^6;  //Register select (RS) pin
    sbit rw = P3^5;  //Read write(RW) pin
    sbit en = P3^7;  //Enable(EN) pin
    sbit sda=P3^1;  //sda
    sbit scl=P3^0; //sck
    sbit led=P1^0;
    sbit led1=P1^1;

    sbit sensor_1=P3^1;  //sensor1

    int max = 0;
    int carry = 0;
    int arr[4];
    //inisialissi varibel eeprom
    unsigned char reead,write,write2,b,k;
    unsigned int temp;

    //
    int count_amt[7],j;
    unsigned int count_1,count_2;
                /*
    void delay(int delay_time)  // Time delay function
    {
    int j,k;
    for(j=0;j<=delay_time;j++)
      for(k=0;k<=1275;k++);
    }
                  */
    void delay(unsigned int count)  // Function to provide time delay in msec.
    {
    int i,j;
    for(i=0;i<count;i++)
      for(j=0;j<500;j++);
    }

    void lcd_cmd(unsigned char cmd_addr)  //Function to send command to LCD
    {
    lcd_data_str_pin = cmd_addr;
    en = 1;
    rs = 0;
    rw = 0;
    delay(1);
    en = 0;
    return;
    }

    void lcd_data_str(char str[50])  //Function to send string
    {
    int p;
    for (p=0;str[p]!=’’;p++)
    {
      lcd_data_str_pin = str[p];
      rw = 0;
      rs = 1;
      en = 1;
      delay(1);
      en = 0;
    }
    return;
    }

    void lcd_data_int(unsigned int count)  
    {
    char dig_ctrl_var;
    int p;
    for (j=6;j>=0;j–)
    {
      count_amt[j]=count%10;
      count=count/10;
    }

    for (p=0;p<=6;p++)
    {
      dig_ctrl_var = count_amt[p]+48;
      lcd_data_str_pin = dig_ctrl_var;
      rw = 0;
      rs = 1;
      en = 1;
      delay(1);
      en = 0;
    }
    return;
    }

    void aknowledge()      //acknowledge condition
    {
        scl=1;
        _nop_();
        _nop_();
        scl=0;
    }
    void start()        //start condition
    {
        sda=1;
        scl=1;
        _nop_();         //No operation
        _nop_();
        sda=0;
        scl=0;
    }
    void stop()            //stop condition
    {
        sda=0;
        scl=1;
        _nop_();
        _nop_();
        sda=1;
        scl=0;
    }

    void send_byte(unsigned char value)    //send byte serially
    {
        unsigned int i;
        unsigned char send;
        send=value;
        for(i=0;i<8;i++)
        {
            sda=send/128;            //extracting MSB
            send=send<<1;            //shiftng left
            scl=1;
            _nop_();
            _nop_();
            scl=0;
        }
       ack=sda;                    //reading acknowledge
       sda=0;
    }

    unsigned char read_byte()            //reading from EEPROM serially
    {
        unsigned int i;
        sda=1;
        reead=0;
        for(i=0;i<8;i++)
        {
            reead=reead<<1;
            scl=1;
            _nop_();
            _nop_();
            if(sda==1)
                reead++;
            scl=0;
        }
        sda=0;
        return reead;                //Returns 8 bit data here
    }        

    void save()                    //save in EEPROM
    {
        start();
        send_byte(0xA0);                        //device address
        aknowledge();
        send_byte(0x00);                        //word address
        aknowledge();
    //    send_byte(5);                            //send data
    //    aknowledge();
    //    send_byte(65);
    //    aknowledge();
        stop();                               
    /*if(ack==0)
        {
            led1=1;
            delay(100);
            led1=0;
            delay(100);
            lcd_command(0x86);
            lcd_data(‘5’);
            lcd_command(0x87);
            lcd_data(‘A’);
        }
        else
            led1=1;
        
        aknowledge();
        */
    }
    void Read()
    {
        /*start();
        send_byte(0xA0);
        aknowledge();
        send_byte(0x00);
        aknowledge();
        */
        start();
        send_byte(0xA1);//device address
        aknowledge();     
        b=read_byte();
        aknowledge();
        k=read_byte();
        aknowledge();
        stop();
        if(b==0)
        {
            led=0;
            delay(100);
            led=1;
            delay(100);
            write=b+count_2;
            lcd_cmd(0x86);
            lcd_data_int(write);    
        }
        else
         led=1;
        if(k!= 0)
        {
            lcd_cmd(0x87);
            lcd_data_int(count_2);
        }
        aknowledge();
        
    }

    void count_count()  //count
    {
    while (sensor_1==0);
    if (sensor_1==1)
    {
      while (sensor_1 == 1);
       {
        count_1 = count_1 + 1;

      // save();
     
      if(count_2==0)
      count_2=count_1;
      if(count_2 !=0){
      count_2=count_2+1;
          start();
        send_byte(0xA0);                        //device address
        aknowledge();
        send_byte(0x00);                        //word address
        aknowledge();
        send_byte(count_2);                            //send data
        aknowledge();
        //send_byte(count_1);
        //aknowledge();
        stop();    
       if(ack==0)
        {
            led1=1;
            delay(100);
            led1=0;
            lcd_cmd(0x38);
            delay(5);
            lcd_cmd(0x01);
            delay(5);
            lcd_cmd(0x80);
            lcd_data_str(“Saved: “);
            lcd_cmd(0x87);
            lcd_data_int(count_2);
        }
        else
            led1=1;
        
        aknowledge();

       }
       }
       
       
    }
    }

    void main()
    {
    //ini_pin = stop_pin = 1;
    count_1= 0;
    sensor_1= 0;
    lcd_cmd(0x38);
    delay(5);
    lcd_cmd(0x0F);
    delay(5);
    lcd_cmd(0x80);
    delay(5);
    lcd_data_str(“COUNT UP”);    
    Read();
    delay(5);
    while(1)
    {
                    //results();
                   
    //lcd_ini();    
    count_count();/*
    lcd_cmd(0x38);
    delay(5);
    lcd_cmd(0x0F);
    delay(5);
    lcd_cmd(0x02);
    delay(5);
    lcd_cmd(0x80);
    delay(5);
    lcd_data_str(“push switch “);    
    */
    lcd_cmd(0x38);
    delay(5);
    lcd_cmd(0x0F);
    delay(5);
    lcd_cmd(0x02);
    delay(5);
    lcd_cmd(0xC0);
    delay(5);
    lcd_data_str( “value :” );
    lcd_cmd(0x38);
    delay(5);
    lcd_cmd(0x0F);
    delay(5);
    lcd_cmd(0xC8);
    delay(5);
    lcd_data_int(count_1);
    delay(5);
    Read();
    delay(5);
                   
        }
    }
     
    please help and advice

     

    wysiwyg_imageupload:6554:

     

    October 29, 2012 at 4:37 pm #8700
    AJISH ALFRED
    Participant

    Hi Kangibnu,

    I can’t see any function call to the eeprom from your main() function. The code will work without calling the eeprom related functions from your main() function.

    November 6, 2012 at 9:58 am #8723
    kangibnu
    Participant

    tank’s for your advise..

     

    I will try this….angain….

    November 10, 2012 at 12:02 pm #8732
    AJISH ALFRED
    Participant

    You are welcome. Please don’t forget to update the result.

    November 12, 2012 at 3:28 am #8742
    kangibnu
    Participant

    The following are the programs I use on a counter circuit (see the picture I attached to the previous post), this program is working normally and can save the result of a calculation to memory IC eeprom, after turn off the power supply circuit and restarted, the count value can are saved and can be updated with a few new ones. But there are several obstacles(problems) that count results can be stored into the eeprom IC at24c16 maximum value 256. after the value could not keep back …. and must be reset IC eeprom memory contents.
    please give advice to me, which part should I change to be able to display and store the result of a calculation to the value of 999 999
    I wait for suggestions from fellow forum

     

    here the code,

     

    /*
    Bissmillahirrohmanirrokhiim…
    rev.2 tes 26 oktober ‘2012
    Program     : Counting up with LCD + eeprom 24c16 + AT89S51
    Tanggal    : 25 September 2012 – 10 Oktober 2012
    Author    : Ibnu Budi R.  ( kangibnu )  Laros-Edu
    Country Org : Indonesia-Jatim
    Compiler    : Raisonance C Compiler 6.1.6
    note    : many variable with Bahasa Indonesia
            : you can translate in english
    */
    #include<reg51.h>
    #include<intrins.h>
    #define msec 50
    #define lcd_data_str_pin P2
    bit ack;
    sbit rs = P3^6;  //Register select (RS) pin
    sbit rw = P3^5;  //Read write(RW) pin
    sbit en = P3^7;  //Enable(EN) pin
    sbit sda=P3^1;  //sda
    sbit scl=P3^0; //sck
    sbit led=P0^3;
    sbit led1=P0^1;

    sbit sensor_1=P3^2;  //sensor1
    sbit sensor_2=P3^3;  //sensor2
    sbit motor=P1^7;     //motor mekanik

    int max = 0;
    int carry = 0;
    int arr[4];
    //inisialissi varibel eeprom
    unsigned char reead,write,write2,b,k;
    unsigned int temp;

    //
    int hitung_amt[7],j;
    unsigned int hitung_1,hitung_2;

    void tunda(int waktu)  // Time delay function
    {
    int s,k;
    for(s=0;s<=waktu;s++)
      for(k=0;k<=20;k++);
    }          

    void delay(unsigned int count)  // Function to provide time delay in msec.
    {
    int i,j;
    for(i=0;i<count;i++)
      for(j=0;j<500;j++);
    }

    void lcd_cmd(unsigned char cmd_addr)  //Function to send command to LCD
    {
    lcd_data_str_pin = cmd_addr;
    en = 1;
    rs = 0;
    rw = 0;
    delay(1);
    en = 0;
    return;
    }

    void lcd_data_str(char str[50])  //Function to send string
    {
    int p;
    for (p=0;str[p]!=’’;p++)
    {
      lcd_data_str_pin = str[p];
      rw = 0;
      rs = 1;
      en = 1;
      delay(1);
      en = 0;
    }
    return;
    }

    void lcd_data_int(unsigned int hitung)  
    {
    char dig_ctrl_var;
    int p;
    for (j=6;j>=0;j–)
    {
      hitung_amt[j]=hitung%10;
      hitung=hitung/10;
    }

    for (p=0;p<=6;p++)
    {
      dig_ctrl_var = hitung_amt[p]+48;
      lcd_data_str_pin = dig_ctrl_var;
      rw = 0;
      rs = 1;
      en = 1;
      delay(1);
      en = 0;
    }
    return;
    }

    void aknowledge()      //acknowledge condition
    {
        scl=1;
        _nop_();
        _nop_();
        scl=0;
    }
    void start()        //start condition
    {
        sda=1;
        scl=1;
        _nop_();         //No operation
        _nop_();
        sda=0;
        scl=0;
    }
    void stop()            //stop condition
    {
        sda=0;
        scl=1;
        _nop_();
        _nop_();
        sda=1;
        scl=0;
    }

    void send_byte(unsigned char value)    //send byte serially
    {
        unsigned int i;
        unsigned char send;
        send=value;
        for(i=0;i<8;i++)
        {
            sda=send/128;            //extracting MSB
            send=send<<1;            //shiftng left
            scl=1;
            _nop_();
            _nop_();
            scl=0;
        }
       ack=sda;                    //reading acknowledge
       sda=0;
    }

    unsigned char read_byte()            //reading from EEPROM serially
    {
        unsigned int i;
        sda=1;
        reead=0;
        for(i=0;i<8;i++)
        {
            reead=reead<<1;
            scl=1;
            _nop_();
            _nop_();
            if(sda==1)
                reead++;
            scl=0;
        }
        sda=0;
        return reead;                //Returns 8 bit data here
    }        
    void Read()
    {
        start();
        send_byte(0xA0);
        aknowledge();
        send_byte(0x00);
        aknowledge();

        start();
        send_byte(0xA1);//device address
        aknowledge();     
        b=read_byte();
        aknowledge();
        k=read_byte();
        aknowledge();
        stop();

            led=0;
            delay(100);
            led=1;
            delay(100);

            lcd_cmd(0xc6);
            lcd_data_int(b);    
         led=1;
            lcd_cmd(0xc7);
            lcd_data_int(k);
        aknowledge();
    }

    void hitung_count()  //hitung ( bahasa indonesia ) = Counting
    {

    while (sensor_1==0);
    if (sensor_1==1)
    {
    //read,counting, save to eeprom
    start();
        send_byte(0xA0);
        aknowledge();
        send_byte(0x00);
        aknowledge();

        start();
        send_byte(0xA1);//device address
        aknowledge();     
        b=read_byte();
        aknowledge();
        k=read_byte();

        aknowledge();
        stop();
            aknowledge();
        //end reading
      while (sensor_1 == 1);
       {
        hitung_1 = hitung_1 + 1;
       //begin save to eeprom
      // save();
      //saving
      if(hitung_2==0)
      hitung_2=b;
      if(b !=0){
      hitung_2=hitung_2+1;
          start();
        send_byte(0xA0);                        //device address
        aknowledge();
        send_byte(0x00);                        //word address
        aknowledge();
        send_byte(hitung_2);                            //send data
        aknowledge();
        send_byte(hitung_2);

        aknowledge();
        stop();    
       if(ack==0)
        {
            led1=1;
            delay(100);
            led1=0;
            lcd_cmd(0x38);
            delay(5);
            lcd_cmd(0x01);
            delay(5);
            lcd_cmd(0x80);
            lcd_data_str(“Saved: “);
            lcd_cmd(0x87);
            lcd_data_int(hitung_2);
           
        }
        else
            led1=1;
        
        aknowledge();
       // end save to eeprom
       }
       }
       
       
    }
    }

    void sedot()//for motor (optional)
    {
        
        motor=1;
        tunda(20); //tunda ( bahasa indonesia = delay for motor )
        motor=0;
        tunda(20);
    }
    void main()
    {
            motor=0;
            hitung_1= 0;
            sensor_1= 1;
            sensor_2=1;
            lcd_cmd(0x38);
            delay(5);
            lcd_cmd(0x0F);
            delay(5);
            lcd_cmd(0x80);
            delay(5);
            lcd_data_str(“Insert  Document”);
            delay(5);
    //Optional for motor control
    while (sensor_2==1);
            if (sensor_2==0)
            {
                motor=1;
                //    
                Read();
                delay(5);

    while(1)
                {
                hitung_count();
                lcd_cmd(0x38);
                delay(5);
                lcd_cmd(0x0F);
                delay(5);
                lcd_cmd(0x02);
                delay(5);
                lcd_cmd(0xC0);
                delay(5);
                lcd_data_str( “Value :” );
                lcd_cmd(0x38);
                delay(5);
                lcd_cmd(0x0F);
                delay(5);
                lcd_cmd(0xC8);
                delay(5);
                lcd_data_int(hitung_1);
                delay(5);
                }        
        }
    }

    November 15, 2012 at 12:46 pm #8749
    AJISH ALFRED
    Participant

    I think your code is writing data to the same single page with adress 0x00. Once the page is full you should write to the next page. Go through the datasheet thoroughly to learn more about memory page aceess for that eeprom.

    November 18, 2012 at 5:05 am #8756
    kangibnu
    Participant

    thanks for advise, I‘ll try it again, is there anything that needs to be changed from the listing program that I attach …?

    give me some example….

    March 10, 2014 at 12:56 pm #11265
    subhashree.r
    Participant

    hi,

    i tried to execute ur code for automatic bidirectional visitor counter but iam getting an error in the line 4…as

     Compiling and Linking the program….

    $sdcc main.c 2>&1


    main.c:4: syntax error: token -> 'dig_ctrl_4' ; column 15

    can u pls help me to resolve this error

     thank u

    March 12, 2014 at 3:32 am #11289
    SHAH DISHANT H.
    Participant

    Hi,

     

    If man will stop at gate, you will face this issue that it will continuously increase because this pin is using level instead of it you can program it to sense a edge.

     

    I am assuming that sensor is giving logic 1 when it detects human and connected at pin P0.1

     

    Try thhis

    sbit sw=P0^1;

    while (sw==0);              // Wait till human is not detected

    while (sw==1);              // Wait till human is standnig in front of sensor

    cnt++;                      // Increase counter value

     

     

    Or something like

    if (sw==1)   // if human is detected

    {

             while (sw==1) ; // if human is standing infront of gate, wait till he moves on

             cnt ++;

     

    }

    September 1, 2014 at 1:46 am #12100
    Arul Verman
    Participant

    I’m working on the bidirectional counter by Himanshu . I’d like to know what are the component codes for IR Transmitter and IR Receiver ?? Is the display common anode in the project ?? Has anyone tried the project ??

    July 15, 2015 at 1:00 pm #13073
    jani
    Participant

    sir, plz send me circuit dia and code for ur project bidirectional visitor counter …plz sir help me 

     

    [email protected]

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Wish to buy Battery, Charger and Buck converter for 12V , 2A router May 13, 2025
  • Electronic Components May 13, 2025
  • Need Help Figuring Out the Schematics Of Circuit Board May 13, 2025
  • applying solder paste from a jar May 12, 2025
  • Question i-nears headphones magnetic drivers May 12, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise