A ping sensor measures distance. It doesn't care whether that distance is to a dog, a tree, a brick wall, or a human.

The first thing that you need to do is to be able to get distances from the sensor. There are plenty of examples around for doing that.

Then, you have to decide what that distance means. Do you want to increment the counter each time the distance it measures is less than some value? Do you want to increment the counter only once when the distance is less than some value, ignoring readings until a reading above that threshold happens?

A ping sensor measures distance. It doesn't care whether that distance is to a dog, a tree, a brick wall, or a human.

The first thing that you need to do is to be able to get distances from the sensor. There are plenty of examples around for doing that.

Then, you have to decide what that distance means. Do you want to increment the counter each time the distance it measures is less than some value? Do you want to increment the counter only once when the distance is less than some value, ignoring readings until a reading above that threshold happens?

What will you do with that counter?

I thought if the sensor a smaller distance than normal measurement he than 1 "point" to the total number of does.

We want to use it for if there eg. 400 clots in the trash is thrown there than something happened!