here it is: `#include <Wire.h> #include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,1); #define trig 6 #define echo 7
int t_puls = 0, distance = 0, No_people = 0;
int initial_distance = 400;
const int sound_speed = 57; // you can change it depend on the weather
don't understand the need for the while loop in your code since loop() is repeatedly called
there's a test for distance <= initials_distance but then there's a test for distance != initial_distance that is likely to always be true
since each iteration of loop() measures the distance to the nearest object, why not have a test if the distance is < some threshold and increment the count on each transition from the distance being less than the threshold by keeping track of the previous distance
look this over
const byte trig = 6;
const byte echo = 7;
const int Threshold = 60; // cm
boolean inRange = false;
int count;
void loop ()
{
// generate pulse
digitalWrite (trig, HIGH);
delayMicroseconds (10);
digitalWrite (trig, LOW);
// compute distance from pulse echo
long duration = pulseIn (echo, HIGH);
int distance = duration * 0.034 / 2;
// check for something within range
if (distance < Threshold) {
if (! inRange) {
count++;
Serial.println (count);
}
inRange = true;
}
else
inRange = false;
}
void setup () {
Serial.begin (9600);
pinMode (trig, OUTPUT);
pinMode (echo, INPUT);
}