We were recently given an assignment in class which we have no idea how to do. We are attempting to build a machine which sorts different types of marbles. Where we are struggling is finding a way to use a sonar to detect when all the marbles have been sorted. We will create a hopper which lines all the marbles along a track, waiting to be let into the sorter. A servo will control the flow of the marbles, moving a gate up and down to allow one marble through at a time. We must use a sensor for something and our only idea is to have a sonar detect when the line of marbles has been depleted. However, we have no idea how to use sonars as were never taught and I can't find good examples online. I want to create an if statement that basically says "if the sonar reads that there are no marbles, set the servo to the closed position." I have no idea what to put in the if statement, whether it be echoPin or duration or what.