Counter using IR sensor

Hello.
I need to make the arduino to calculate the number of cars passing by IR sensor, so I used IR reciever with 38KHz to make a signial to analog pin of arduino. The problem is that the arduino continue counting without any passing cars.
I programmed it as the following:

If (sensIR > threshold)

Number of cars++;

where threshold = 1000

I just want to know the problem is because of the wrong cods, or because of the singinal coming for IR reciver circuit.

Hi,
Welcome to the Forum

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html
then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

We need to see how you have connected the IR circuit to the Arduino.
What model Arduino are you using?

Thanks.. Tom... :slight_smile:

Oh, Sorry for that.

okay, I use Arduino uno in my project.

first the code is

int threshold;  
int sens2;
int street2=0;

void setup()
{
Serial.begin(9600);
}

void loop()
{

sens2 = analogRead(A0);
threshold=1000;
if (sens2>threshold)
{
 street2++; 
 delay(1500);

and I attached the circuit diagram of the IR receiver, but notice that I removed the LED and made the input of the analog get from the point in which I removed LED.

Hi,

We need your complete code.
Do you have a DMM to measure voltages in your circuit.

Tom.. :slight_smile:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int threshold;  
int sens2;
int street2=0;
void setup()
{
Serial.begin(9600);
lcd.begin(20,4);
lcd.setCursor(5,1);
lcd.print("Hello!");
delay(2000);
lcd.clear();

}

void loop()
{

sens2 = analogRead(A0);
threshold=1020;
if (sens2>threshold)
{
 street2++; 
 delay(1500);
 Serial.println(sens2);
}

lcd.setCursor(0,0);
lcd.print("street2 = ");
lcd.print(street2);

I just tried to reduce it. this is the whole code that I uploaded to the arduino, and yes, I have. The voltage across the input of the analog go high (3-5 volt) whenever, I pass something through the IR ray. So I get confused how the arduino continues counting without any cutting the ray.

You need to look at the state change detection example. You do NOT want to increment the counter as quickly as possible while a car IS blocking the sensor. You want to count when the sensor BECOMES blocked.