1
Suppose to be after the count is the output from Arduino. Please help. Newbie here huhu
Here is the code
#define trigPin 6
#define echoPin 5
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
int countgrab=0;
void loop() {
int duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 300) {
countgrab++;
if (distance <= -300){
countgrab++;
}
}
Serial.println(countgrab);
delay(200);
}