Using Ultrasound to count people.

Hey guys,

I am new to arduino.and i think its awesome.I am building a man counter as my first project.I intent to use ultrasound to count people.

There are two doors parallel to each other.I intent to place two ultrasound sensors at the top of each door and count the people walking through it.

My questions are?

1.IS THERE ANY OTHER WAY TO COUNT PEOPLE OTHER THAT USING LASER TRIP WIRE?
2.CAN I MAKE IT RUN FOR 24/7?
3.PLEASE HELP ME OUT WITH THE CODING A LITTLE.JUST AN ALGORITHM IS NECESSARY FOR ME.I CAN FIGURE OUT THE REST.

PLEASE HELP ME OUT GUYS :disappointed_relieved:

  1. Yes. Can you ask each person to push a button?
    Do you need to know which direction they are going or are these one-way doors?

  2. Yes. The first problem is how are you going to power it? Then what are you doing with the data - you probably don't want to climb on top of the door to download the data each day. You may need to run a serial or USB cable to a computer or find a simple LCD display to show the numbers.

  3. You are the best one to work out the algorithm. You haven't even told us if you want to count how many people are inside the building or how many are outside.

You could use a light and a Light Dependent Resistor - being more diffuse it might actually make it easier to avoid counting arms or legs twice.

...R

Ferico:
1.IS THERE ANY OTHER WAY TO COUNT PEOPLE OTHER THAT USING LASER TRIP WIRE?

Install a subway style turnstile

Use a pressure sensitive floor mat

Use an infrared emitter/detector pair

Use a reflective infrared proximity sensor

Use a passive infrared motion sensor

Use a camera and image processing software

Use a mechanical feeler switch that people brush by

Use a gesture sensor (like the APDS-9960)

Use an RFID reader and make each person carry an RFID tag

Use vibration sensors in the floor

Use a very sensitive capacitive sensor

Use a sensitive metal detector to detect keys and coins in pockets, belt buckles, zippers, snaps, etc.

Use a trained monkey to push a button as each person passes

There are many ways to approach a problem. Each one has their strengths and weaknesses, some are more practical than others. The choice depends on your requirements, budget, installation restrictions, convenience to the people, appearance requirements, and expertise.

2.CAN I MAKE IT RUN FOR 24/7?

Of course!

3.PLEASE HELP ME OUT WITH THE CODING A LITTLE.JUST AN ALGORITHM IS NECESSARY FOR ME.I CAN FIGURE OUT THE REST.

Before worrying too much about an algorithm, make sure you have clearly and concisely specified your requirements. Do you want to just get a total count? Do you want to know when people are passing so you can characterize traffic patterns over time? Do you need to know direction? How tolerant do you need to be about people walking close together or even side-by-side? How accurate does it need to be? What kind of budget do you have? What installation and power restrictions do you have?

Once you've clearly figured out WHAT you want to do, you can then start figuring HOW you're going to do it. This includes sensor selection and starting to figure out an algorithm (which will depend heavily on the above requirements and also on the selected sensor.) I think it's way too early to start talking about algorithms at this point.

MorganS:

  1. Yes. Can you ask each person to push a button?
    Do you need to know which direction they are going or are these one-way doors?

  2. Yes. The first problem is how are you going to power it? Then what are you doing with the data - you probably don't want to climb on top of the door to download the data each day. You may need to run a serial or USB cable to a computer or find a simple LCD display to show the numbers.

  3. You are the best one to work out the algorithm. You haven't even told us if you want to count how many people are inside the building or how many are outside.

Ok.thanks :slight_smile:
1.No they cannot push a button or use any kind of mechanical switch.And yes they are one way doors. :slight_smile:
2.I plan on powering it using a 12v 7Ah. battery 1.75 Amp max.And use AC to charge the battery when by any chance power is out. :sunglasses:
3.Which board do you suggest.I don't think an uno will be enough to drive an LCD disply and use unsigned long.Wont it run out of SRAM and crash if ran for 24/7.And also it need to handle a lot of strings.So arduino DUE is the best choice i Guess :wink:
4.And for the Algorithm almost infinite No. of people are going to use this door :sweat_smile: to reach a particular place.I am currently using Laser diode and an LDR to read in the analog values and count if the analog values go down.
The hard part is many people slam the door misaligning the Laser and LDR alignment making the count inaccurate

Ferico:
The hard part is many people slam the door misaligning the Laser and LDR alignment making the count inaccurate

Can't you just use a non-directional light?

...R

Wont it run out of SRAM and crash if ran for 24/7.

No, SRAM is not consumed with correctly written code.

And for the Algorithm almost infinite No. of people are going to use this door

Don't be silly. If you have one person per second go through the door than that is only 31536000 per year.
A long type variable will hold a number up to 2,147,483,647, so that is 24 years of operation at one person per second, if you want more then use a long long variable type.

.I don't think an uno will be enough to drive an LCD disply and use unsigned long

You are wrong on that.

Grumpy_Mike:
No, SRAM is not consumed with correctly written code.

Don't be silly. If you have one person per second go through the door than that is only 31536000 per year.
A long type variable will hold a number up to 2,147,483,647, so that is 24 years of operation at one person per second, if you want more then use a long long variable type.

You are wrong on that.

Trust me on that bro.its for a very specific purpose.and almost infinite no of people are going to pass by.and every hour the no will be recorded by a person on hard copy,So just for mere safety i use unsigned long.That is 2^16 since 328p is a 16 bit micro controller right??
And don't tell me it wont run out of SRAM .Because it has many times.I am currently using laser trip wire to count people.

after running for a long time.The lcd(16x2) displays random characters.I think this is because it runs out of SRAM.After a reset everything runs fine.It has many strings to display to The LCD.I reduced it as much as possible.

You are asking for trouble disagreeing with the esteemed experts!

You are new to the device. When an expert says you are wrong, don't argue!!

Weedpharma

weedpharma:
You are asking for trouble disagreeing with the esteemed experts!

You are new to the device. When an expert says you are wrong, don't argue!!

Weedpharma

OK SORRY I DID NOT MEAN TO OFFEND ANYONE :cold_sweat:

sorry everyone

BUT it did run out of SRAM.The whole display just prints random character

#define LDR_1 200 //define sensitivity values of LDRs
#define LDR_2 200
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 6, 7);
unsigned int count=0;//variable for counter

void setup() 
{
  //Serial.begin(9600);
  lcd.begin(16,2);
  lcd.print("Count");
}

//begin loop
void loop  () 
{
  if((analogRead(A0)<LDR_1))
  {
    count++;
    if(analogRead(A5)<LDR_2)
    {
      count++;
    }
    delay(900);
  }
  else if(analogRead(A5)<LDR_2)
  {
    count++;
    if(analogRead(A0)<LDR_1)
    {
      count++;
    }
    delay(900);
  }
  lcd.setCursor(0,1);
  lcd.print(count);
  //ldr1();
  //ldr2();  
}

That is the sketch i am using.Is that ok.

Please do tell me then why i am getting random characters when it runs for few hours.I ll post a photo of it next time i see it here.But trust me random characters just appeared on the screen. :confused:

Why have you count++ in 4 places? is that for 4 people?

One reason you may be getting garbage is because you are not clearing the row of the LCD before you print the next value.

You have delay(900) which should mean a max count of 66 per minute. How could you possibly exceed the limits of an unsigned long. Which is 2**32, by the way.

And how many people can fit into the space where you are counting?

I'm not sure why you have delay(900) in two separate places either.

...R

Robin2:
Why have you count++ in 4 places? is that for 4 people?

One reason you may be getting garbage is because you are not clearing the row of the LCD before you print the next value.

You have delay(900) which should mean a max count of 66 per minute. How could you possibly exceed the limits of an unsigned long. Which is 2**32, by the way.

And how many people can fit into the space where you are counting?

I'm not sure why you have delay(900) in two separate places either.

...R

ok.
i use count in four place because i use two photo-resistors and two lasers that is if a two people go to 2 doors at same time.

i use the delay because if they stand in the path of laser for a long time they get counted as two or more depending on the time they stay there.

Ferico:
i use the delay because if they stand in the path of laser for a long time they get counted as two or more depending on the time they stay there.

Why not keep checking each time through the loop until they move? You then get rid of any delay.

Weedpharma

So just for mere safety i use unsigned long.That is 2^16 since 328p is a 16 bit micro controller right??

Wrong.

The size of a variable in C has nothing to do with the underlying processor architecture. In fact the 328p is an 8 bit processor, and int variables are 2 bytes, where as a long is 4 bytes, that means for an unsigned long you get a maximum number of 232, which is twice the number I gave for the signed long.
So are you expecting more than one person per second? Do you want it to run longer than 24 years?

And don't tell me it wont run out of SRAM .Because it has many times.I am currently using laser trip wire to count people.

I said correctly written code, there is no way it runs out of memory. The only way is that:-

  1. There is too much memory required in the initial program, in which case it will crash right away.
  2. You have a memory leak in the code, caused by allocating / deallocating memory, which can happen with the String library. (note String is not the same as string )

Please do tell me then why i am getting random characters when it runs for few hours.

No idea but what ever it is it is not the code, that code will run until hell freezes over without running out of SRAM. If it is crashing then it is something else. Maybe interference or power brownout or something else like loose connections. What ever it is it is not running out of memory.

Trust me on that bro.its for a very specific purpose.and almost infinite no of people are going to pass by

Well given your record of being right so far I do find that hard to believe. I worked on a building evacuation system once using RFID and one per second was about the maximum anyone can pass a single restrictive point. So you need to get more realistic about what your project is going to measure and how fast it is going to measure it.

Also counting people accurately passing a point is almost impossible, due to the many different ways people can move.

i use the delay because if they stand in the path of laser for a long time they get counted as two or more depending on the time they stay there.

Then you are writing the code incorrectly, you should count on edges, not levels. That is when an input changes not when the input is a certain level. Look at the State Change example in the IDE.

I know you are only young. I read one of those books of sayings over the weekend and one line struck a chord.

If you study hard for 16 hours a day then maybe by the age of 60 you will be as smart as you thought you were when you were 20.

Ferico:
i use the delay because if they stand in the path of laser for a long time they get counted as two or more depending on the time they stay there.

This is not the issue I was commenting on.

First I was making the point that if you are only counting once every 900 msecs it will take a long time to count to 232

Second, I was making the point that you have the same code [delay(900)] in 2 places which is poor programming practice.

And, now that you have explained, I will add

Third, (as others have said) this is a poor way to deal with the problem of multiple counts for the same person.

...R

Grumpy_Mike:
Wrong.

The size of a variable in C has nothing to do with the underlying processor architecture. In fact the 328p is an 8 bit processor, and int variables are 2 bytes, where as a long is 4 bytes, that means for an unsigned long you get a maximum number of 232, which is twice the number I gave for the signed long.
So are you expecting more than one person per second? Do you want it to run longer than 24 years?
I said correctly written code, there is no way it runs out of memory. The only way is that:-

  1. There is too much memory required in the initial program, in which case it will crash right away.
  2. You have a memory leak in the code, caused by allocating / deallocating memory, which can happen with the String library. (note String is not the same as string )
    No idea but what ever it is it is not the code, that code will run until hell freezes over without running out of SRAM. If it is crashing then it is something else. Maybe interference or power brownout or something else like loose connections. What ever it is it is not running out of memory.
    Well given your record of being right so far I do find that hard to believe. I worked on a building evacuation system once using RFID and one per second was about the maximum anyone can pass a single restrictive point. So you need to get more realistic about what your project is going to measure and how fast it is going to measure it.

Also counting people accurately passing a point is almost impossible, due to the many different ways people can move.
Then you are writing the code incorrectly, you should count on edges, not levels. That is when an input changes not when the input is a certain level. Look at the State Change example in the IDE.

I know you are only young. I read one of those books of sayings over the weekend and one line struck a chord.

Ok.Ok I get it Edge detection Right :open_mouth: Thank you very much Mike Sir :open_mouth:
Yes,Still a noob to arduino.Just got it last week :blush:
Thank you sir.FYI I just checked out your website Grumpy_Mike.I did not know you were at the cutting edge.

and about the long int so its 416 RIGHT.Oh.. its same as 232.
Still can't figure out why the display goes crazy.I will post a picture here the next time i see it.

Once again thank you very much for helping out guys.I ll keep my progress updated here

You might like to go back to that previous post and prune the repeat quotes out....

Ferico:
Trust me on that bro

As a Rule of Thumb, when people tell me to trust them, I don't.

I bet it's been a loooooooong while since anyone called Mike "bro"..... (If ever?)