Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Digital Visitor Counter using Pic18f4520

Status
Not open for further replies.

105adarsh

Newbie level 5
Joined
Jul 17, 2012
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,396
Hi everyone, How u guys doing??
i'm doing a Digital visitor counter using pic18f4520 as my project. i've an idea of doing it n it is like this, i'l keep two sensors S1 and S2 in entry-cum-exit door, if the person crosses sensorS1 and then sensor S2, the counter get incremented,similarly, if the sensor S2 is active and then the sensor S1, it gets decremented. but i've one problem, how should i program ? how can say whether the person has entered the room or exited?? plz guys give me an idea in programming the project. i'm using C programming n MPLAB IDE tool. plz reply ASAP.

thank u guys:)
 

Start by building some test hardware with two LEDs (each with a 470 Ohm series resistor) on suitable outputs. Get each LED to light in response to one sensor activation.

Once this test circuit is working perfectly, then move on to the logic puzzle, which will be the easy part.

Get the basics working first - that may be the hard part of the project.

Presumably you will want to display the count somehow. What display device will you be using?
 

thank u for replying,
in programming part shall i make use of polling or interrupt. ?? which one is better ?? i tried doing the part u said on proteus but i'm not getting the output... help me plz
thank u
 

First you want to consider false triggers and how you will prevent false counting and missing counts.
Define the range of signal you need to verify a person interrupted the path...= OFF1= Min, Max (valid)
Define the range of signal between invalid changes. to ignore duration.between OFF state to ignore and count if exceeded
Define the time interval between OFF 1 and OFF 2 to distinguish one (1) person from two (2) people.
Min , Max interval for 1 =
Min, Max interval for 2 =

A valid ENTRY count is one that meets the criteria for exiting OFF1 then OFF2 in that order within a reasonable time.
A valid EXIT count is same as entry exit phase sequence is reversed.

- ___-_------_-___________________-_-_-----_________
________--------_-_-________-_-_---------_______
__________________-_____________________________ valid enter =1
_______________________________________-________ valid exit = 1
Armed after N consecutive OFF (hi) to ON (lo) while other sensor is blocked (OFF).
so both must be blocked to consider human.. rather than hand wave.
Once both sensors are Armed. trigger is exiting the sensor for N counts and the sensor last armed is the direction of count

THis is a software debounce. plus direction sequence method that is fool-proof having done it before ...if done correctly.
zero missed counts and zero false counts in 10K tested.

Various methods use count/reset or count/up~down reset depending on which sensor is used. Hysteresis can make it reliable. YOu can choose as simple or reliable a solution as you want over a wide path from 1 meter to 2 meter path.
 
Last edited:

Sorry, but I think that this is pure waste of 18F family chip, this is job for 8051 family, but ok if you whant to learn and try.



Digital Visitor Counter (AT89C2051)
https://www.8051projects.info/proj.asp?ID=36

Digital visitor counter is a reliable circuit that takes over the task of counting Number of Persons/ Visitors in the Room very Accurately. When somebody enters into the Room then the Counter is Incremented by one and when any one leaves the room then the Counter is Decremented by One. The total number of Persons inside the Room is displayed on the seven segment displays.

The microcontroller do the above job it receives the signals from the sensors, and this signals operated under the control of software which is stored in ROM

room1.GIF visitor.GIF




Automatic bidirectional visitor counter using 8051 microcontroller (AT89C51)

**broken link removed**

**broken link removed**
 

You might like to take a look at similar projects for counting bees entering a hive.

Someone might have devised a method to avoid counting bees exiting.
 

Last edited:

I used my design to detect shopping carts and rejected skirts , hands and people across an aisle in full sunlight or full Fluorescent light hum. It was design for low mistake-ability and low error rate.

Jpetals does your design have sufficient debounce filter and sensor dither rejection? range 1 ft? 1m? with crosstalk or isolated channels with Fluorescent light noise or without?

Actually my design was tested with many sensors to pick the shape of a cart in checkstand and detect a loaf of bread in the Bottom of the Basket (BOB) and ignore false triggers. It worked very well and used a $1 8 bit PIC.
 
  • Like
Reactions: tpetar

    tpetar

    Points: 2
    Helpful Answer Positive Rating
Polling is simpler to start with.

Show your C code and we will tell you where the mistakes are.
 
SunnySkyguy you mean for counting bees in hive ?


I think for sure that I do not want to eat that honey where hives have fluorescent light near or inside.
:smile:
 
Last edited:

Uhh sorry I didnt catch question is for me, you write "Jpetals" :

Jpetals does your design have sufficient debounce filter and sensor dither rejection? range 1 ft? 1m? with crosstalk or isolated channels with Fluorescent light noise or without?

Its not my project. :-?

- - - Updated - - -

Sunny how you mean :
I used my design to detect shopping carts and rejected skirts , hands and people across an aisle in full sunlight or full Fluorescent light hum. It was design for low mistake-ability and low error rate.

Do people have RFID in hands ? I know for that in US, but is this often case in Canada ?

- - - Updated - - -

What you think about this, whats your opinion :

RFID 'Powder' - World's Smallest RFID Tag
http://www.technovelgy.com/ct/science-fiction-news.asp?newsnum=939

hitachi-mu-chip.jpg
1807398663_3c567f59c3.jpg


- - - Updated - - -

You might like to take a look at similar projects for counting bees entering a hive.

Someone might have devised a method to avoid counting bees exiting.


For hives can be used measuring of hives weight, we measure several bees and take average value, I think they should be almost the same weight all from that hives.

For people can be used FLIR or CCTV camera with nice managing and counting software. Even to make difference from kids and adults. Some CCTV companies already have counting of car on parking with licence table database.
 
thank u al for replying....
i've written C code. can you guys tell me whether my code is right or not.. plz let me know any changes i should make to the program.
thank u...


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
////////////////////////Include Header Files/////////////////////
#include<p18f4520.h>
#include<stdlib.h>
#include<XLCD.h>
#include<delays.h>
 
///////////////////////Pragma Files/////////////////////////////
#pragma config WDT = OFF // Watch timer off
#pragma config OSC = HS // External High Speed crystal
#pragma config PBADEN = OFF // Analogue I/O port B disabled
#pragma config MCLRE = ON // Master clear enabled
 
//////////////////////Defines LCD functions///////////////////////
#define CLR_LCD 1 // Clear LCD command code
#define HOME_LCD 2 // Cursor home command code
#define LINE2_LCD 0xC0 // Position cursor on line 2 command
#define CURS_OFF 0x0c // Cursor off command code
#define CURS_L 0x10 // Cursor left command code
#define CURS_R 0x14 // Cursor right command code
#define SHIFT_L 0x18 // Scroll display left command code
#define SHIFT_R 0x1C // Scroll display right command code
 
///////////////////////FUNCTION PROTOTYPE/////////////////////////
 
void increment(void);
void decrement(void);
 
/////////////////////LCD Delays////////////////////////////////
 
void DelayFor18TCY(void) // This particular LCD needs longer than the suggested 18 cycle delay
{
Delay1KTCYx(2);
}
void DelayPORXLCD(void)
{
Delay10KTCYx(50); // 15ms delay suggested , however longer delay is used here
}
void DelayXLCD(void)
{
Delay10KTCYx (30); // 5ms delay suggested, however longer delay is used here
}
 
////////////////////////////////DEFINING THE PORTS///////////////////////////////
 
#define S1 PORTAbits.RA0;
#define S2 PORTAbits.RA1;
#define LCD PORTD;
 
////////////////////////////////GLOBAL VARIABLES//////////////////////////////
 
int flag=1,flag1,flag2;
int total;
char ch[10];
int counter;
int cntr;
 
////////////////////////////////MAIN PROGRAM///////////////////////////////
void main()
{
        TRISA=0xFF;//setting the port A as input
        TRISD=0x00;//setting the portD as output
        OpenXLCD(FOUR_BIT & LINES_5X7); // Set LCD for 4-bit 5x7 matrix
        while(1)            //repeats the loop forever
     {
            while(flag == 1)    //repeats the loop forever
            {         
              char msg[] = "WELCOME";       // Define message string 1
              OpenXLCD(FOUR_BIT & LINES_5X7); // Set LCD for 4-bit 5x7 matrix
              WriteCmdXLCD(CLR_LCD);         // Clear LCD display
              while(BusyXLCD());            // wait till ready
              putsXLCD(msg);                // Sent message Press Button
              Delay10KTCYx(1000); 
              flag1= S1;
              flag2= S2;
 
                    if (flag1!=1)// when sensor 1 S1 is active
                    {
                        increment();
                    }
                        if(flag2!=1)//when sensor 2 S2 is active
                        {
                            decrement();
                        }
            }
        total = counter - cntr;// calculates the total number of people in the hall
        OpenXLCD(FOUR_BIT & LINES_5X7); // Set LCD for 4-bit 5x7 matrix
        WriteCmdXLCD(CLR_LCD);       // Clear LCD display
        while(BusyXLCD());          // wait till ready
        putsXLCD(ch);// displays the total number of people in the hall
    }
 
}
///////////////////////////////////INCREMENT////////////////////////////
 
void increment()
{
int counter;
int entry;
while(1)
        {
            if((flag1&&flag2)==1)
                {
                    counter++;
                    entry = counter[B];//i've a doubt in this line, will the incremented counter value is stored in entry??[/B]
                    OpenXLCD(FOUR_BIT & LINES_5X7);
                    WriteCmdXLCD(CLR_LCD);
                    while(BusyXLCD());
                    putsXLCD(ch);//displays the incremented number
                    Delay10KTCYx(50);
                }
            else
                {
                    char msg1[]= " False entry ";
                    OpenXLCD(FOUR_BIT & LINES_5X7);
                    WriteCmdXLCD(CLR_LCD);
                    while(BusyXLCD());
                    putsXLCD(msg1);//displays the false entry
                    Delay10KTCYx(50);
                }
        }   
 
}
//////////////////////////////////DECREMENT/////////////////////////////
 
void decrement()
{
 int cntr;
 while(1)
            {
                if((flag2&&flag1)==1)// [B]is this intruction same as if((flag1&&flag2)==1)??[/B]
                    {
                        cntr--;
                        OpenXLCD(FOUR_BIT & LINES_5X7);
                        WriteCmdXLCD(CLR_LCD);
                        while(BusyXLCD());
                        putsXLCD(ch);//displays the decremented number
                        Delay10KTCYx(50);
                    }
                else
                {
                    char msg2[]= " False exit ";
                    OpenXLCD(FOUR_BIT & LINES_5X7);
                    WriteCmdXLCD(CLR_LCD);
                    while(BusyXLCD());
                    putsXLCD(msg2);//displays the false exit
                    Delay10KTCYx(50);
                }
    
            }
}



plz help me
how can i write the code where i can find the direction of the person(like entering or exiting)?
 
Last edited by a moderator:

You should be wrapping the quote tags around your code,
Code:
like this
because your code is appearing unreadable due to the missing indentation.

Unfortunately the code is pretty bad, you've not really taken any of the suggestions from SunnySkyGuy earlier. Also, your code
has infinite while(1) loops in the increment() and decrement() functions as far as I can tell (the code is hard to
read without the indentation).
You've missed out on many situations (e.g. two people walking closely together), as mentioned by SunnySkyGuy,
or a person aborting and turning back in-between sensor 1 and 2. These need timers implemented.
Possibly best to draw a state machine and have arrows showing the events (timer expiry or sensor event) that cause
transitions from one state to the next. Or at least do it in pseudo-code first. Only then is it worth constructing it into code.
I think the lack of this planning is why you've got increment() and decrement() functions that actually don't just
increment or decrement but instead contains that logic which really doesn't work and unfortunately isn't suitable
for your requirements.
 
thank u for replying,
sorry but i'm new to the programming. i din't get to know, how to implement SunnySkyguy idea. can i get the syntax for his idea i'l try to do it. should i do the program based on edge detection of the signal? please help me.

- - - Updated - - -

thank u for replying,
sorry but i'm new to the programming. i din't get to know, how to implement SunnySkyguy idea. can i get the syntax for his idea i'l try to do it. should i do the program based on edge detection of the signal? please help me. as per my understanding from the explanation from sunnyskyguy, is the syntax is

Code:
OFF1= min,max(1,10);
OFF2 = min,max(2,12);

[code\]

is this syntax correct??? does sunnyskyguy mean this?? plz correct me if i'm wrong...
 

Unfortunately I don't have the time to write your code for you! But if you have a syntax issue, I can certainly
recommend books so you can learn programming yourself.
However as mentioned before, you have a problem more immediate, unrelated to the syntax. You need to understand and
then design at a high level what you're trying to achieve! Perhaps what may help you is an understanding of what a
state machine can look like. By sketching one, you can "mentally" try out your design and see if it will cater for situations
like a hand passing through, or a person turning back half-way. No offence, but these are obvious things to consider,
and it seems a little lazy that you didn't consider them. It has nothing to do with your programming ability.
Anyway, here is a link to a page that explains state machines quite well. It even shows how a state machine is
translated into code. The example uses C++ but the concepts are clear (and as an Engineer you need to get used to
looking at ideas in pseudocode or in languages that you may not be familiar with, and then implement the idea in
a language of your choice).
If you really want to do as little as possible then I'm afraid you'll just need to search for the work of other people
who may have already tried it. For example the January 2007 issue of this magazine apparently.
 
try logical AND of both sensors to GATE or ARM the trigger after n1 counts (filter)
Then use the trailing edge of both sensors OFF for n2 counts ( filter)
The sequence of sensor 1 vs sensor 2 determines direction If A then B = "exit",, If B then A then "entry"
 

Define the range of signal you need to verify a person interrupted the path...= OFF1= Min, Max (valid)...what is this mean??
Should I first take the waveforms obtained from the IR sensor??so that i can know the range of the signal transmitted by the sensor....can you please be more precise??
thank u..
 

hi,
how to read the data coming from IR receiver side using PIC 18f4520 microcontroller?? please help me guys...Also guys i'm using HIRL5020 IR led at transmitter end and tsop 31238 at the receiver side... Am i using the right components?? Please reply ASAP
 

hi..
i want to capture the falling edge in sensor 1 and sensor2 ... i'm using external interrupt . when the falling edge/rising edge of sensor1 is captured, how to capture falling/rising edge of sensor2 later??
please reply ASAP.
thank u
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top