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.