Translate

Automated People Counting & fan Controlling System

For our 3rd semester digital electronics module we chose this project.

The purpose of the project was to implement a system which can count the number of occupants in a closed area and control the speed of the fan according to the temperature. The implementation was carried out by three subsystems such as one system for occupant counting, one for temperature measurement and other to control the speed of fans. It was found out that this can be done using  basically IR sensors (Transmitters and Receivers), a temperature sensor and a micro controller. But this implementation was carried out under certain assumptions. Under those assumptions this system works in a reasonably precise manner and serves the purpose and can be used in real world applications which adheres  those assumptions. But this system can be further developed so that it can be used in any situation.

The micro controller we used was 16F877A. The temperature sensor was LM35DZ.   

Here I am not going to explain how the circuits were built. My contribution to the project was mainly programming the micro controller. I preferred PIC C. 

Since we had to do several tasks we had to decide how are we going to use the microcontroller to achieve the expected results. 

Basic algorithm we had in mind was,


Occupants counting algorithm 
  Emitters (Emitter1 and Emitter 2) emit IR signals, which are received by Receiver1 and Receiver 2 respectively. 
  At the time when there is no interrupt the receiver will receive the IR signal.
  When an interrupt is taken place that will be notified by the receiver.
  If the Receiver 1 notices an interruption first and then the Receiver 2 it indicates an entrance to the closed area.
  If the Receiver 2 notices an interruption first and then the Receiver 1 it indicates an exit from the closed area.
  The time delay (T) between the detection of an interrupt by Receiver 1 and Receiver 2(or Receiver 2 and Receiver 1) will determine the time taken to travel between two sensors.
  There is a ceiling value (T1) and a floor value (T2) for this time delay.
  For the accuracy movement is taken as an exit or an entrance only if T1 < T < T2.
  The increment or decrement of the counter is done according to the movement.

It was decided to use the B0 interrupt pin of 16F877A for people counting task.
But the problem was we had two IR beams but one interupt pin. So the solution was, connecting an XOR gate to the inputs from IR sensor circuit and connecting the gate's output to PIN B0, PIN B1 and PIN B2.
By this method we could successfully detect when a person enters or leaves. 

To get the analog input from temperature sensor, PIN A0 was used.

To control the fan(AC), we used phase controlling. 

Below is the source code. Hope to explain the project further.

#include "p1.h"
#include "flex_lcd.c"
/////////////*FUNCTION DECLARATIONS*///////////////
void init_pic();
void setTimer();
int checkTimer();
void rayCrossed_isr();
void clock_isr();
int32 convertToCelsius();
int convertToASCII(int16 number);
void lcd_display(int16 number, int x, int y);
void initialDisplay();
int16 read_temperature();
void lcd_display_temperature();
void phaseControl();
///////////////////////////////////////////////////
/////////////////*GLOBAL VARIABLES*/////////////////////////////////////////////////
int16 noOfPeople = 3; // Number of people inside the room
int int_count; // Number of interrupts left before a second has elapsed
int unitsPosition, tensPosition, hundredsPosition;
int1 rayOne = 0; // to record when first beam get crossed
int1 rayTwo = 0; // to record when second beam get crossed
int1 pin_changed = 1;
int1 number_changed = 1;
int16 mseconds =0;
int16 counter_for_temp=0 ;
int16 temperature=27;
int16 t; // The A/D conversion of the analog input
// signal results in a corresponding 10-bit digital number.
// this variable is to store that
////////////////////////////////////////////////////////////////////////////////////
void main()
{
init_pic();
initialDisplay();
/* only if the number of people changes the value shown in lcd is changed.
And temperature is updated when counter_for_temp overflows.*/
while(1)
{
phaseControl();
if(number_changed)
{
lcd_display(noOfPeople,14,1);
number_changed = 0;
}
if(counter_for_temp == 65535)
{
lcd_display_temperature();
counter_for_temp=0;
}
counter_for_temp++;
}
}
/* when timer0 counter overflows(0-255) an interrup occurs. int count which is initially
* set to INTS_PER_mS, is decremented by 1 inside the isr.
* When int_count reaches 0, no of miliseconds is incremented by 1
*/
#int_RTCC
void clock_isr() {
if(--int_count==0)
{
++mseconds;
int_count=INTS_PER_mS;
}
}
//Whenever a beam get crossed this isr is invoked.
#int_EXT
void rayCrossed_isr()
{
if(INPUT(PIN_B2))
{
rayTwo = 1;
if(checkTimer() == 2 && rayOne == 1)
{
rayOne = 0;
}
if(rayOne == 1)
{
if(checkTimer() == 1)
{
noOfPeople++ ;
number_changed = 1;
}
rayOne = 0;
rayTwo = 0;
}
setTimer();
}
else if(INPUT(PIN_B1))
{
rayOne = 1;
if(checkTimer() == 2 && rayTwo == 1)
{
rayTwo = 0;
}
if(rayTwo == 1)
{
if(checkTimer() == 1 && noOfPeople>0)
{
noOfPeople-- ;
number_changed = 1;
}
rayOne = 0;
rayTwo = 0;
}
setTimer();
}
}
void setTimer()
{
int_count=INTS_PER_mS;
set_timer0(0);
mseconds=0;
}
/* When both rayOne =1 and rayTwo = 1, this is called */
int checkTimer()
{
if((mseconds <= MAX_CROSSING_TIME) && (mseconds >= MIN_CROSSING_TIME))
{
return 1;
}
else if(mseconds > MAX_CROSSING_TIME)
{
return 2;
}
else
{
return 0;
}
}
int32 convertToCelsius()
{
return (t*150)/307;
}
void lcd_display_temperature()
{
temperature =read_temperature();
lcd_display(temperature,13,2);
}
int convertToASCII(int16 number)
{
return (number+48);
}
void lcd_display(int16 number, int x, int y)
{
int unitsPosition, tensPosition, hundredsPosition;
unitsPosition =number % 10;
tensPosition = ((number - (number % 10))%100)/10;
hundredsPosition = ((number - (number%100))%1000)/100;
lcd_gotoxy(x,y);
lcd_putc(convertToASCII(hundredsPosition));
lcd_putc(convertToASCII(tensPosition));
lcd_putc(convertToASCII(unitsPosition));
}
int16 read_temperature()
{
delay_us(12); //a small delay is required after setting the channel
t = read_adc();
return convertToCelsius();
}
void initialDisplay()
{
delay_ms(25);
lcd_init();
lcd_gotoxy(1,1);
lcd_putc("SYSTEM STARTED..");
lcd_gotoxy(1,2);
lcd_putc("================");
delay_ms(500);
lcd_gotoxy(1,1);
lcd_putc("\fNumberInside:");
lcd_display(noOfPeople,14,1);
lcd_gotoxy(1,2);
lcd_putc("Temperature: C");
}
void init_pic()
{
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_32);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RTCC);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
EXT_INT_EDGE(L_TO_H);
OUTPUT_B(0);
OUTPUT_C(0);
SET_TRIS_B(0b01000111); //pins B0, B1, B2 and B6 are set to give inputs. B0 is the external interuupt pin
//B0, B1 & B2 are used for people counting. B6 for zero crossing detection in fan controlling
SET_TRIS_C(0b00000000);
SET_TRIS_D(0b00000000); //D port except D0 pin, is used for lcd panel
set_adc_channel(0); //the next read_adc call will read channel 0
}
/*
the fan is controlled using phase control method.
Fan is on only if the number of people >0
*/
void phaseControl()
{
switch(noOfPeople)
{
case 0: OUTPUT_HIGH(PIN_B7);
break;
default:
if(INPUT(PIN_B6) && pin_changed == 1)
{
if(0<=temperature && temperature<20)
{
OUTPUT_HIGH(PIN_B7);
}
else if(temperature>=20&& temperature<23)
{
delay_us(6000);
OUTPUT_LOW(PIN_B7);
delay_us(500);
OUTPUT_HIGH(PIN_B7);
}
else if(temperature>=23 && temperature<25)
{
delay_us(5000);
OUTPUT_LOW(PIN_B7);
delay_us(500);
OUTPUT_HIGH(PIN_B7);
}
else if(temperature>=25 && temperature<27)
{
delay_us(4500);
OUTPUT_LOW(PIN_B7);
delay_us(500);
OUTPUT_HIGH(PIN_B7);
}
else if(temperature>=27 && temperature<30)
{
delay_us(4000);
OUTPUT_LOW(PIN_B7);
delay_us(500);
OUTPUT_HIGH(PIN_B7);
}
else if(temperature>=30)
{
OUTPUT_LOW(PIN_B7);
}
pin_changed = 0;
}
if(!INPUT(PIN_B6))
{
pin_changed = 1;
}
}
}
view raw 1.c hosted with ❤ by GitHub

1 comment:

  1. Hdpe geomembrane sheet are essential components in various engineering and construction applications, primarily used for lining and containment. Known for their durability and resistance to chemical damage, these sheets provide an effective barrier against liquids and gases. Understanding the price of geomembrane sheets is crucial for budgeting projects, as costs can vary based on thickness, size, and specific requirements. Additionally, the interplay between geotextiles and geomembranes enhances overall performance in soil stabilization, erosion control, and environmental protection. This guide will explore the significance, pricing factors, and the synergy between these vital materials in modern infrastructure projects.

    ReplyDelete