Detecting cars with sensors for garage counter

Customer:

I wrote this code myself and everything works as it should without using a boolean. I’m wondering if it can work this way - is something missing that might cause an error later?

Here’s the code:

int led = 13;
int inPin = 11;

void setup() {
  Serial.begin(9600);
  pinMode(inPin, INPUT);
  pinMode(led, OUTPUT);
}

void loop() {
  if (digitalRead(inPin) == LOW){
    digitalWrite(led, LOW);
  }
  else if (digitalRead(inPin) == HIGH){
    digitalWrite(led, HIGH);
    Serial.println(" Ocitavam objekt" );
    delay(1000);
  }
}

I looked at some tutorials online but they overcomplicated the code. What sensor can I use to detect any object? The HC-SR501 motion sensor detects radiation, but I want to detect metal - for example, a car passing by. I’d like to build a car counter for a garage entrance.

Original message (Croatian)

napisao sam ovaj kod sam i sve mi radi kako treba i bez boolena pa me zanima jel to moze tako (mozda nesto fali pa ce s vremenom doc do neke greške)

Evo Koda

int led = 13;

int inPin = 11;

void setup() {

Serial.begin(9600);

pinMode( inPin, INPUT);

pinMode( led, OUTPUT);

}

void loop() {

if (digitalRead(inPin) == LOW){

digitalWrite(led, LOW);

}

else if (digitalRead(inPin) == HIGH){

digitalWrite(led, HIGH);

Serial.println(" Ocitavam objekt" );

delay (1000);

}

}

gledao sam neke tutoriale na netu pa su dosta iskomplicirali s kodom.

S kojim senzorom mogu ocitati bilo koji objekt jer (SENZOR POKRETA HC-SR501 očitava zračenje).

Kako bih mogao npr očitat neki metal NPR AUTOMOBIL koji prolazi?

Želio bih napravit brojač ulaza automobila u garažu

Originally submitted via the contact form on soldered.com on 30 September 2017. Migrated to the forum for community visibility.

Soldered Support:

Your code will work exactly as written and won’t produce errors.

For detecting a car, you have several options:

You can measure distance with an ultrasonic module and detect when the distance decreases: HC-SR04 ultrazvučni senzor: Arduino kompatibilni modul za mjerenje udaljenosti – Soldered Electronics

Or you can use a laser and a light sensor: point a laser at a light sensor, and when the light disappears, detect that something has passed.

Or something else entirely. There are many possibilities!

Original message (Croatian)

Ne znam o kojem se senzoru ovdje radi, ali ovo će raditi stvarno kako ste napisali uvijek i neće se događati greška.

Što se tiče senzora koji bi očitao automobil, možete mjeriti udaljenost s ultrazvučnim modulom i kada se udaljenost smanji detektirati to kao automobil: HC-SR04 ultrazvučni senzor: Arduino kompatibilni modul za mjerenje udaljenosti – Soldered Electronics

ili
možete koristiti laser Soldered: Open-Source Electronics, Boards, Sensors & Modules – Soldered Electronics
i nekakav senzor svjetlosti Soldered: Open-Source Electronics, Boards, Sensors & Modules – Soldered Electronics
u kojega uperite laser te kada nestane svjetlosti, to detektirate da je netko prošao

ili nešto treće.. :slight_smile:

Čestitamo na prvoj spaljenoj ledici :slight_smile: bit će ih još puno! :slight_smile: