How to detect a car/count cars entering into a garage using Arduino Uno?

Hello everyone,

I am trying to count number of cars entering into a garage. I wish to use a PIR sensor by Panasonic. Its an analog sensor.
I tried to write a code and ended up with this.

CODE
int pirPin = 9; //digital 9
int counter = 0;
int state;
int lastState = HIGH;

void setup()
{
Serial.begin(9600);
pinMode(pirPin, INPUT);
}
void loop()
{
int state = digitalRead(pirPin);
if ( state != lastState)
{
//was motion detected
counter=counter+1;
Serial.println(counter);
}
laststate = state;
delay(0);
}

Does this work?

Please advise.

Thanks !!

omkardokur:
Does this work?

I don't know. What happened when you ran it?

As you will no doubt discover, PIR sensors are useless for counting moving objects. They are way too erratic and sensitive.

For automobiles, magnetic pickups are reliable and are commercially available under various names like "driveway sensors", "loop vehicle detector" etc. But you can make your own, they are just large coils of wire with a small signal amplifier.

Edit: here is an interesting vehicle detector circuit that uses a 555 oscillator to drive a large coil. As the car moves over the coil, it changes the resonant frequency of the circuit, and the resulting increase or decrease in amplitude of the oscillations in the LC circuit is detected by the LM393. An Arduino could take place of both the 555 and the LM393. http://forum.allaboutcircuits.com/showthread.php?t=61662&page=2

Yeah jremington , what you said is correct. I am also trying them. Meanwhile i am interested to experiment with Ultrasonic sensor.

I have a question here and i will be really happy if anyone of you can answer my question. Its much related to the energy associated with the sound energy.
Here I go:
We all know that Ultrasonic sensor is based on sound waves. Trigger generates the sound wave and Echo Pin receives the echo. And we use pulseIn() to calculate the distance of the object. I am pretty comfortable with this.
But what I want is more than the distance. Sound waves are associated with energy. They too have some energy in the medium. When sound waves hit an object and reflect back, a part of energy may be absorbed by the object. Further , human beings absorb more than any other objects.
I am trying to figure out way to calculate this energy.
Also sound wave is associated with PItch. If a wave has a high pitch then its energy is higher than the low pitch. Further high pitch has higher frequency than the low pitch.

Is there any way we can calculate energy reflected back? Is there anyway we can calculate frequency of the reflected wave(We know that frequency of transmitted wave is 40Khz) so that we can relate this frequency to the energy associated with the wave.

Hope everyone participates actively in this discussion !!

In sound waves, power and energy density is related to the pressure amplitude, not the frequency or pitch. Sound power - Wikipedia

Is there anyway i can calculate the received amplitude???

I just want to differentiate the difference between waves reflected from car/human beings.
Suggest me how i can differentiate ????

Hi omkardokur,

I would go on using a IR beam counting system, installed at the entrance of the garage/parking lot. Each car entering the garage will interrupt the IR beam. They are cheap and you can already find libraries on that.
However if you still want to calculate the energy of the soundwave, you should look for sound E=I/C (sound intensity/sound speed), measured in Pascals.

Great..

Please provide me some links or suggest me few IR Sensors.

Thanks
Omkar

You could order one of these http://www.aliexpress.com/item/Single-Beam-Photoelectric-Infrared-Barrier-Detector-IR-Sensor-Alarm-system-door-access-switch-with-factory-supply/1684360382.html
from aliexpress. really cheap. they have a dry contact output that you could use as an input for your arduino.
If your application is intended for outdoor, there might be some bad positives triggered by environmental changes.

How can i achieve this with RFID reader and tags.. If any one did this... Please guide me !!