Counting Person entering a room

Hello

My project :

  1. I want to add to counter when a person is entering.
  2. Deduct when leaving.
  3. Will detect temperature in room via LM35.
  4. According to person entering the room, will adjust the temperature reading.
    e.g : 6 person in rooms. = 3 degree rise in temperature.
    0.5 degree rise in temperature for each person. ( JUST TO PRINT IT ON SCREEN)
    e.g 2 : Actual Temp reading = 34 C . but if 6 person are in room then temp will be shown as 37 C .
    5 ) with the FAKE TEMP reading i would control the speed of fan.

Print all the data on LCD. ( Person Count and FakeTemp Reading)
ONLY THEORY
To achieve the person count . Initially i was using a 2 LDR .
LDR 1 , LDR2 are mounted closely to each other. and a laser beam has to be thrown onto it.

If LDR1 is cut and then shortly LDR2 is cut. Then person+=1 .
If LDR2 is cut and then shortly LDR1 is cut. then person-=1.


But due to ignorance. I tied LDR to digital pins, Thinking that when person will cut the pin will go low and vice versa.


Now, I want to use HALL EFFECT SENSOR and attach magnets to the door ( DOOR with PUSH when entering and PULL WHEN LEAVING)
hence i want to know how can i use HALL EFFECT sensor as a switch on digital pin without interrupt.

I did use half effect sensor on a running engine to measure RPM but that was using interrupt .

I have designed my PCB and fabricated it and don't want to spend time creating another one as i mistakenly used hardware interrupt pins as I/O for LCD.

EDIT : I am using standalone ATMEGA328( not 328p) with internal 8MHz oscillator, programmed via ArduinoToBreadboard example and tinkering.

Here is the code , eagle schematic and PCB .

#include<LiquidCrystal.h>
LiquidCrystal lcd(0,1,2,3,4,5);
int ldr1=9;
int ldr2=10;
int tempsens=A0;
int fan=11;
int PWMOutput=0;
int person=0;
int temp=0;
int count=0;
float count1;
int temp1;
void setup()
{
  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0,0);
  pinMode(ldr1,INPUT);
  pinMode(ldr2,INPUT);
  pinMode(tempsens,INPUT);
  pinMode(fan,OUTPUT);
}

void loop()
{

  
   temp = (5.0 * analogRead(tempsens) * 100.0) / 1024;  
 if(temp>0){
fan1(); 
count=person;
count1=count*0.5;
temp1=temp+count1;
 lcd.setCursor(0,1);
lcd.print("Temp:");
lcd.print(temp1);
lcd.write(0b11011111);
lcd.print("C");
}
  
   if(digitalRead(ldr1)==HIGH&&digitalRead(ldr2)==LOW)
     {
     delay(100);
     if(digitalRead(ldr1)==LOW&&digitalRead(ldr2)==HIGH)
     {person+=1;
     }
     }
       
     
    if(digitalRead(ldr2)==HIGH&&digitalRead(ldr1)==LOW)
     {
     delay(100);
     if(digitalRead(ldr2)==LOW&&digitalRead(ldr1)==HIGH)
     {person-=1;
     }
     }
    

if(ldr1==LOW&&ldr2==LOW);
{
print1();
}

void print1()
{
  lcd.setCursor(0,0);
       lcd.print("Person:");
       lcd.print(person);
 
}

void fan1()
{
    if(temp<=32)
 PWMOutput=0;
					if(temp>32&&temp<=37)
					PWMOutput=100;
					if(temp>37&&temp<=40)
					PWMOutput=130;
					if(temp>40&&temp<=45)
					PWMOutput=160;
					if(temp>45&&temp<=50)
				PWMOutput=190;
					if(temp>50&&temp<=55)
					PWMOutput=220;
					if(temp>55&&temp<=60)
					PWMOutput=240;
						if(temp>=60)
					PWMOutput=255;
        analogWrite(fan, PWMOutput);   
}

ammar123:
I have designed my PCB and fabricated it and don't want to spend time creating another one as i mistakenly used hardware interrupt pins as I/O for LCD.

Just as well and not a "mistake", as interrupts are virtually useless for this sort of application.

LDRs will work just fine as sensors, you just have to use the correct pull-up value (the internal pull-ups will likely work quite OK) and they must be mounted inside a long (4 cm) black tunnel.

The logic is a little more complex. If LDR1 is broken, then LDR2, then LDR1 is illuminated again, then LDR2 is illuminated, only then is the count incremented. All other patterns do not count. Correspondingly if LDR2 is broken first and LDR1 re-illuminated last, then the count is decremented.

a comment about temperature. the room temperature does not rise. the heat gain rises.

if you think of HVAC as adding heat to an area of cool (or vice versa)
you can monitor the rate of leakage of heat by the BTU's added over time as plotted against the surrounding temperature.

a room on a hill will have a different leakage than a corner office or a office surrounded by 4 other rooms on the sides on also on top and bottom.

also the amount of devices such as copiers computers and such, will also add heat.

what happens when a person enters a room, they are a new source of heat so the air conditioner could increase BTU output or the heater could reduce BTU output by a similar amount.

very interesting project. we did something similar in a college movie theater. the initial plan was to just start the cooling before people entered and then catch the rise from a mass of people. one of the problems was that 30 people would enter one door as a mass.

CO2 and VOC levels rose early enough and fast enough that they became the first level of sensing.

Hypothetically , One PERSON is entering or one person is leaving.
and yes heat signature or heat gain is rising. Hence i want adjust the fan speed accordingly.
This project is not going to be implemented into working rooms etc. to adjust temperature . Its a Summer project competition. So i need some guidance.

Paul__B:

ammar123:
I have designed my PCB and fabricated it and don't want to spend time creating another one as i mistakenly used hardware interrupt pins as I/O for LCD.

Just as well and not a "mistake", as interrupts are virtually useless for this sort of application.

LDRs will work just fine as sensors, you just have to use the correct pull-up value (the internal pull-ups will likely work quite OK) and they must be mounted inside a long (4 cm) black tunnel.

The logic is a little more complex. If LDR1 is broken, then LDR2, then LDR1 is illuminated again, then LDR2 is illuminated, only then is the count incremented. All other patterns do not count. Correspondingly if LDR2 is broken first and LDR1 re-illuminated last, then the count is decremented.

Thank you for that little idea to increase counter. But i want to know how i can use LDR on digital PIN . ( as LDR would not give 1 or 0 output , which i realized later on.)

You can say i want to use LDR as a switch.
Please have look at schematics and please advice further.

ammar123:
i want to know how i can use LDR on digital PIN . ( as LDR would not give 1 or 0 output , which i realized later on.)

An LDR acts as a variable resistor. You can connect one in series with a fixed resistor to act as a voltage divider, and connect the junction between them to a digital pin. The characteristics of the LDR together with the value of the fixed resistor would determine what light level caused the digital input to switch states, and you could adjust it by altering the value of the fixed resistor. This is quite a crude approach though - you would have much better control over the threshold if you connected the voltage divider to an analog input. If you choose the LDR characteristics correctly, you can even use the internal pull-up resistor as the other half of the voltage divider, simplifying the external circuit.

im assuming the LDR'S are photo resistors, you may be able to use transistors
apply a known voltage to each of the photo resistors and attach the photo resistor to the base of a transistor so when the laser is not on the sensor the full current passes though it but when the laser is on it the current is limited, use that to activate and deactivate the transistor and you can apply whatever voltage is high for your particular microcontroller at the collector and it will either pass or not pass through the emitter.
so it would be a pnp transistor so when the base goes low the collector and emitter will pass current

just an idea.. kinda new to this myself

keys-t:
im assuming the LDR'S are photo resistors, you may be able to use transistors
apply a known voltage to each of the photo resistors and attach the photo resistor to the base of a transistor so when the laser is not on the sensor the full current passes though it but when the laser is on it the current is limited, use that to activate and deactivate the transistor and you can apply whatever voltage is high for your particular microcontroller at the collector and it will either pass or not pass through the emitter.
so it would be a pnp transistor so when the base goes low the collector and emitter will pass current

just an idea.. kinda new to this myself

Can anybody elaborate on this method?. How can i achieve this ? . The concept of using Transistor as a switch will work. But only if when in OFF stage it should not get over 2V, or else the pin will get HIGH.

ammar123:
Thank you for that little idea to increase counter. But I want to know how i can use LDR on digital PIN . ( as LDR would not give 1 or 0 output , which I realised later on.)

There is no problem and absolutely no need to use analog inputs or analog input functions - you only ever want a zero or one input.

You just do as I described; you connect the LDR between the input pin and ground. You enable the internal pull-up function in the Arduino. When the LDR resistance is significantly lower than 10k (when illuminated), it will read LOW, if it is significantly higher, it will read HIGH.

I just (last night) checked the resistance of the little 5 mm LDRs I recently received with illumination by a 1 mW red laser (albeit at short range) and it was well under 1k.

The only concern in this regard is that applying voltages around the transition point of the input range will result in increased current consumption in the chip however since the "analog" pins also have full digital functionality, we must infer that this is not any sort of reliability concern, merely extra current consumption.

If you did feel the need to "condition" the inputs from the LDRs, you would not use transistors, but Schmitt inverters such as the 74HC14 with 10k pull-up resistors.

Actual accurate room human occupancy is not an easy task, otherwise you would see a lot of methods in use.

You might want to add a filter cap on the output of the 7805. Your schematic is drawn a bit "funky". Don't have traces going through the parts and don't have parts inside other parts. Makes it difficult to read. I also think you missed the ground connection on the HD44780. Where is the trace off the right edge going to? What voltage is your AC coming in as? I'm assuming this is low-voltage AC, right?

Also, I don't see an external crystal, so I assume you are changing the fuse bits to use the internal oscillator? Not sure if that's automatic. I've always used an external crystal myself.

You're also missing a pullup resistor on the reset line. Without that, the chip will be stuck in reset mode. Also, how are you going to program the chip? Recommend you put in ICSP interface or at least breakout the RX/TX and reset pins so you can use a FTDI USB to serial interface to program an already boot-loaded chip. Question... have you actually tried this circuit out on a breadboard to prove it works? I'm guessing no, because there are a lot of things wrong with it. Breadboard it first before you design your PCB. Will help you figure out some mistakes.

I designed the PCB , It is working for sure.
and as far as programming for ATmega328 is i used ArduinoToBreadboard example. Tweaked the avrdude.conf to change the signature. and wrote the program using arduino as ISP . then upload the sketch Upload using programmer and yes i mentioned its running 8Mhz Internal oscillator.
THE PCB is PERFECTLY WORKING.

This was my first take at designing Eagle Sch and look closely for right edge line. It goes to +12V from cap ( for Fan) .

That's great that it works. I guess either you've set the RSTDISBL bit to disable reset on PC6 or you're just lucky with PC6 floating. I guess one way you could test that is to touch a wire between PC6 and GND for a few seconds and see if it resets. Since this pin isn't connected to anything, you have a floating pin. If you have not set the RSTDISBL bit, your chip could periodically reset itself. Heck, it might be doing that right now without you even realizing it depending on how your sketch works.

To increment and decrement a counter based on the number of people who entered or left will need a two sensor gate.

If sensor one is triggered first then sensor two, a person has entered.
if sensor two is triggered first then sensor one, a person has left.

You will have issues if two people are rude and try to enter and leave at the same time.

HazardsMind:
To increment and decrement a counter based on the number of people who entered or left will need a two sensor gate.

If sensor one is triggered first then sensor two, a person has entered.
if sensor two is triggered first then sensor one, a person has left.

You will have issues if two people are rude and try to enter and leave at the same time.

Thats what i am trying to do . with 2 LDR's and Laser beam to excite them.
But the problem is. I want to use LDR on digital pins i.e LDR as a switch.

are you still looking for a solution to this? useing the photo resistors on digital pins?
i suggested that you use transistors, keep in mind that transitors are current driven but this schematic may help you i left out all the values because im sure you want to figure it out yourself.

i mixed up the collectro and emitter, correction below

ammar123:
But the problem is. I want to use LDR on digital pins i.e LDR as a switch.

Yep, just connect each LDR between a pin and ground, enable the internal pullup (read instructions for this as necessary) and - away you go!

Couldn't get easier!

The trick is in mounting the LDR in a black tunnel (tubing).