I've posted the final code and schematic diagram we referred
int count = 100;
int previous = 0;
int sensorValue = 6;
int voltage;
void setup()
{
Serial.begin(115200);
pinMode(sensorValue,INPUT_PULLUP);
}
void loop()
{
delay(2000);
voltage= digitalRead(sensorValue);
if ( voltage == LOW)
{
Serial.println(voltage);
}
else
{
Serial.print("Car hai");
Serial.println(voltage);
if (previous != LOW)
{
Serial.println("Same car");
}
else
{
count--;
Serial.print("count is ");
Serial.println(count);
}
}
previous =voltage;
}
