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.

Automatic Room Light Controller with visitor counter for single door

Status
Not open for further replies.

mmahfuj

Junior Member level 2
Junior Member level 2
Joined
May 31, 2012
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Chittagong,Bangladesh
Activity points
1,491
I wanna make a project named "Automatic Room Light Controller with visitor counter for single door" using PIC microcontroller(16f877a). I did a programme for it and it is not for single door. Would you please help me by giving the logic of mikro c code for the single door(not for one entrance and another exit door, only for one door). Please help me....I need it badly..if anyone wish to send me the source code(full) then you can send me to this email ID: ""
 

Giving you full source code actually means giving you everything... that's not how people here usually work. If you want to make something but you're stuck somewhere, then you ask for help for the argument you're having troubles - not the whole project ready to go.

I'll start giving you an input. You could use 2 IR sensors and 2 IR receivers and put them at a few centimeters/inches distance from each other (in horizontal). This way, supposing IR sensor A is internal and IR sensor B is external to your desired room, you know if someone is getting in or out by checking which sensor has been activated first. If A then someone is exiting, if B someone is entering. Knowing this implies you can count the number of people visiting that particular room by simply counting the people entering in (achieved the first objective). Although, it has a small bug: if two or more people are able to get in at the same time they'll still be counted as 1, so you might want to check for other methods if you want real count. I wouldn't bother that much though.
Also, now that you know when someone is entering or exiting, you may count the people inside and if there are none you can turn off lights, else, keep lights on (achieved the second objective).

If my words could be understood by some futuristic machine you would have had the program you want ready made by now, by only using my words... although, there's no such machine so, you could start getting dirty with some code, could you? ;)
 

I think it so..I have done a programming code but it doesn't work in proteus simulator...Now i am posting this code:


int frontflag=0, backflag=0, counter;
void main()
{
TRISB = 0b00000011;
counter=0;
while(1)
{
if(RB0_bit==1 && RB1_bit==0)
frontflag=1;
else
frontflag=0;

if(frontflag==1 && RB1_bit==1)
{
counter=counter+1;
frontflag=0;
}
else
counter=counter;

if(RB0_bit==0 && RB1_bit==1)
backflag=1;
else
backflag=0;
if(backflag==1 && RB0_bit==1)
{
counter=counter-1;
backflag=0;
}
else
counter=counter;

if(counter==0)
RB2_bit=0;
else
RB2_bit=1;
}
}


***and the image is


- - - Updated - - -

initially i did the code without using 7 segment. how can i use 7 segment here and count the number of person???????
 

If by "7 segment" you mean a 7 segment display, you have to use some PIC pins to drive an output to the display. If the display has a 4-bit to 7 segment decoder you have to write the number as 4 bits on 4 pins and send it to the display. If it's a simple display then you'll have to properly driver each segment of the display to form the number you want.
Now, about the code, I'm sure that writing:
Code:
counter=counter;
it's useless. For the rest, I actually didn't really understand your logic. Personally, I'd have made it like this:

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
while (1){
    // assuming sensors are variables sA and sB, and lights switch is sL
    unsigned int People=0;  // counter for people inside the room
    char AllowNextCount=0;  // boolean indicating if allowing next count or not
    char InOut;             // 1 = entering; -1 = exiting
    
    if ((sA==0) && (sB==1)){
        // entering
        InOut = 1;
    }
    
    if ((sA==1) && (sB==0)){
        // exiting
        InOut = -1;
    }
    
    if ((sA==1) && (sB==1) && (AllowNextCount==1)){
        // only when both sensors are touched validate the people counter
        People += InOut;
        
        if (People > 0) sL = 1; // Turn/keep lights on as long as People greather than 0
        else sL = 0;            // otherwise, turn them off
        
        // count once then block counting until the same person has finished entering/exiting
        AllowNextCount=0;
    }
    
    if ((sA==0) && (sB==0)){
        // it gets 0;0 only when someone has finished entering/exiting
        // or at turn on; so now allow to counting again
        AllowNextCount=1;
    }
}


I haven't compiled it, I've written it on the fly, but it should be working. Now that I look better at it, it's almost the full source code you were looking for... well, make a good use of it :)
 

Here i modified your programme but still did not work , I used B6 & B7 as input and C0 as output:


// assuming sensors are variables sA and sB, and lights switch is sL
unsigned int People=0; // counter for people inside the room
char AllowNextCount=0; // indicating if allowing next count or not
char InOut; // 1 = entering; -1 = exiting

void main()
{
TRISB=0b11000000;
TRISC=0;
portb=0;


while (1)
{


if ((RB6_bit==0) && (RB7_bit==1))
{
// entering
InOut = 1;
}

if ((RB6_bit==1) && (RB7_bit==0)){
// exiting
InOut = -1;
}

if ((RB6_bit==0) && (RB7_bit==0) && (AllowNextCount==1)){
// only when both sensors are touched validate the people counter
People += InOut;

if (People > 0)
RC0_bit = 1; // Turn/keep lights on as long as People greater than 0
else
RC0_bit = 0; // otherwise, turn them off

// count once then block counting until the same person has finished entering/exiting
AllowNextCount=0;
}

if ((RB6_bit==0) && (RB7_bit==0)){
// it gets 0;0 only when someone has finished entering/exiting
// or at turn on; so now allow to counting again
AllowNextCount=1;
}
}
}
 

which is the compiler your are using.........

and what is purpose of using two push buttons...........
 

Which compiler are you using. Are you using mikroC Pro? You have to add debounce delays in your code for buttons.

Code:
// assuming sensors are variables sA and sB, and lights switch is sL
unsigned int People=0; // counter for people inside the room
char AllowNextCount=0; // indicating if allowing next count or not
char InOut; // 1 = entering; -1 = exiting

void main()
{
TRISB=0b11000000;
TRISC=0;
portb=0;


while (1)
{


if ((RB6_bit==0) && (RB7_bit==1))
{
	delay(100);
	if ((RB6_bit==0) && (RB7_bit==1))
		// entering
		InOut = 1;
	}
}

if ((RB6_bit==1) && (RB7_bit==0))
{
	delay(100);
	if ((RB6_bit==1) && (RB7_bit==0)) {
		// exiting
		InOut = -1;
	}
}

if ((RB6_bit==0) && (RB7_bit==0) && (AllowNextCount==1)){
// only when both sensors are touched validate the people counter
People += InOut;

if (People > 0) 
RC0_bit = 1; // Turn/keep lights on as long as People greater than 0
else 
RC0_bit = 0; // otherwise, turn them off

// count once then block counting until the same person has finished entering/exiting
AllowNextCount=0;
}

if ((RB6_bit==0) && (RB7_bit==0)){
// it gets 0;0 only when someone has finished entering/exiting
// or at turn on; so now allow to counting again
AllowNextCount=1;
}
}
}
 

I am using mikro c compiler...and the two push button means two signal input to microcontroller....I have used these two push button as the alternative of two ir switch
 

Do you know how the data o/p of IR sensor will be? Use Delay_ms(100); instead of delay(100); in the code.
 

one of the push button is for entering the persons into the room and other one is for leaving the person from the room........... and if any person is in your room then light should be on................ right
 

Zip and post your mikroC files and proteus .dsn file

You have to pullup the MCLR pin to Vcc through a 10k resistor.
 

Attachments

  • counter.rar
    12 KB · Views: 126
Last edited:

i have used but not worked

- - - Updated - - -


- - - Updated - - -

i want to use two push button in a single door...if there two button named b1 & b2 then if b1 is on and then b2 is on,the light will be on...if b2 is on first and then b1 is on then then decrease the number but light will be off if there is none in the room

- - - Updated - - -

where is your hex file?
 

b2 is on first and then b1 is on then then decrease the number but light will be off if there is none in the room

explain a little more about the working of buttons, like what happens in the below mentioned conditions

b1 ON, b2 ON
b1 ON, b2 OFF
b1 OFF, b2 ON
b1 OFF, b2 OFF

How to you find whether there is people or not in the room?
 

Attachments

  • counter.jpg
    counter.jpg
    130.3 KB · Views: 155
  • counter.rar
    53.2 KB · Views: 138
Last edited:

think there is nobody in the room, so the lights are off of the room.....and b1 is in outside and b2 is inside the door. if any one wants to enter into the room he/she has to cross both the switch and obviously he/she has to cross b1 switch first and then b2. and this time the light will be on. after that, if another person enter into the room then the light will be still on....if the person goes out of the room then he/she has to cross the b2 switch first and then b1 switch and this time the number of the people will decrease . if all the person of the room goes out from the room then there is nobody in the room and the light will be off..
and the number of the people presented in the room will be shown in a "7 segment display"..


this is my total project..thanks
 

its better to modify your project methodology.....

b1 is placeds outside the room

and b2 is placed inside the room........

now

1.when the person is entering the room then he/she will press only b1 not b2

2. when the person is leaving the room then he/she will press only b2 not b1

this way u can do your programming easy way....

whenever b1 is pressed the persons in room will get incremented

same way if b2 is pressed then persons in room will get decremented

now check the how persons are in room and perform the action

if persons in room is zero then turn off the light

if persons in room is not zero then turn on the light

hope this helps u

- - - Updated - - -

Regarding displaying in 7-segment........

how many 7-segment u are using

if u are using one then u can display maximum number in a room is 9

if two 7-segment then 99 persons........

hope this helps u
 

There was a bug in my code, I misused the char variable type for InOut that would not allow -1 (instead, it'll put 255).
Back to the sensors and how they're working... still assuming sensor A is internal and sensor B external to the room; if someone touches sensor B it doesn't necessarily mean the person has entered, he might leave before completely entering. The same for sensor A when leaving. So I would think to validate enters and exits by touching both sensors. But if you think it's enough counting using only 1 sensor, without validating count by double touching, it's still OK.
I'm attaching here another version of the program with the ISIS simulation DSN file. I made it for PIC16F84 and I have added some status LEDs and an LCD display to actually read what's happening. To use it you must keep pressed the push buttons of the sensors (use the arrow on top of the button); when both sensors will be touched the counting (either increment or decrement, based on which sensor has been touched first) will be made. After the count is made you have to switch off both sensors to allow another next count.
That's the full program for PIC16F84. Feel free to modify it however you want

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
#include <htc.h>
__CONFIG(0x3FF1);
 
#ifndef _XTAL_FREQ
    #define _XTAL_FREQ 4000000
#endif
 
// HD44780 controller based LCD display drivers for PIC10/12/16
// Driver is a personal work I made, you can download the LCD driver from:
// [url]https://www.edaboard.com/blog/1817/[/url]
#include "HD44780.h"
#include "HD44780.c"
 
#define sA RA0
#define sB RA1
#define sL RA2
 
void main(void){
    // TRIS registers
    TRISA = 0x03; // RA0 and RA1 are inputs
    TRISB = 0x00;
 
    // assuming sensors are variables sA and sB, and lights switch is sL
    unsigned int People=0;  // counter for people inside the room
    char AllowNextCount=0;  // boolean indicating if allowing next count or not
    short int InOut;        // 1 = entering; -1 = exiting
    
    // Initializing LCD
    LCD_Initialize();
    
    // Set data on display the first time
    LCD_Clear();
    LCD_WriteString("Counter: ");
    LCD_WriteNumber(People);
    LCD_WriteString("\nLights:  ");
    LCD_WriteNumber(sL);
    
    while (1){
        if ((sA==0) && (sB==1)){
            // entering
            InOut = 1;
        }
        
        if ((sA==1) && (sB==0)){
            // exiting
            InOut = -1;
        }
        
        if ((sA==1) && (sB==1) && (AllowNextCount==1)){
            // only when both sensors are touched validate the people counter
            People += InOut;
            
            if (People > 0) sL = 1; // Turn/keep lights on as long as People greather than 0
            else sL = 0;            // otherwise, turn them off
            
            // count once then block counting until the same person has finished entering/exiting
            AllowNextCount=0;
            
            // Update data on display
            LCD_Clear();
            LCD_WriteString("Counter: ");
            LCD_WriteNumber(People);
            LCD_WriteString("\nLights:  ");
            LCD_WriteNumber(sL);
        }
        
        if ((sA==0) && (sB==0)){
            // it gets 0;0 only when someone has finished entering/exiting
            // or at turn on; so now allow to counting again
            AllowNextCount=1;
        }
    }
}



EDIT
I forgot the attachment, added it right now.
 

Attachments

  • Door.zip
    84.7 KB · Views: 117
Please explain me about these library code:
"include <htc.h>
__CONFIG(0x3FF1);

#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif

// HD44780 controller based LCD display drivers for PIC10/12/16
// Driver is a personal work I made, you can download the LCD driver from:
// https://www.edaboard.com/blog/1817/
#include "HD44780.h"
#include "HD44780.c"

#define sA RA0
#define sB RA1
#define sL RA2
"


what means by "htc.h"?

Why don't you use these code to initialize LCD? :>
"
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

"


Please explain me...I could not understand properly your code above before "while loop"
Please...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top