Counting With a Ping Sensor
Dmagee
Posts: 20
Hi, I'm trying use a Ping Sensor to count ten black bottles as they travel down a conveyor belt.
After ten bottles have been counted a entry gate opens and a bunch of other stuff happens.
The Ping Sensor is easy but the count ten and then continue with the rest of the program I'm having problems with.
I've been looking for some examples in the Parallax text that might help me but I haven't found one yet.
Any help would be appreciated.
Thanks, Dave.
After ten bottles have been counted a entry gate opens and a bunch of other stuff happens.
The Ping Sensor is easy but the count ten and then continue with the rest of the program I'm having problems with.
I've been looking for some examples in the Parallax text that might help me but I haven't found one yet.
Any help would be appreciated.
Thanks, Dave.
Comments
To help you get started, let's go over some general principles first:
2. Mount a backstop behind the bottles for the Ping))) to sense reflections from when there's no bottle in the way. This will prevent long recovery times, which may cause you to miss a bottle.
3. Establish a starting distance threshold for bottle vs. no-bottle.
4. Take samples as fast as you can. When the distance becomes less than the distance threshold, add one to your count and increase the distance threshold a little. This adds hysteresis to the detection and helps to prevent multiple counts.
5. When the sensed distance becomes greater than the distance threshold, decrease the distance threshold by the same amount you increased it before.
6. In a noisy bottling environment, be prepared for false data from the Ping))). You may need to filter the data returned by considering more than one or two samples.
7. Don't expect a sensor like the Ping))) to be able to count bottles quickly. A few bottles a second may be all that you can achieve. If they are moving too fast -- especially if they are round -- you could miss them entirely.
-Phil
Two things:
1. Your attempt at hysteresis is backwards and could lead to oscillation. Better would be:
2. You're gating your count with the LED pin. IOW, you keep incrementing as long as it remains high. What you should be doing is adding to the count only when the pin changes from low to high.
-Phil
Here is one way to do this problem.. We just did almost this same problem with the ping. What we did was use the ping and the basic stamp, actually on a boe-bot, to count a drill based coil winder. A large circle, about 1 foot in diameter was cut from card board. Then this was cut in half and taped to the side of the shaft coming out of the variable speed battery operated drill. Every time the drill would go around, the stamp on the boe-bot would count it and output this to both the LCD and the computer via the debug. The way it works is to have nothing in front of the ping, then when the half circle turns, it cuts the beam of the ping. The ping gets an echo, at a closer range. I used 8 inches, for when the circle is in the way, otherwise the ping goes as far out as it normally does. This has to be counted with a bit of tricks to insure that the counter works when you move the drill around a bit. This seems to work as long as the speed of the drill is not more than the rate the ping pings at. Seems to be good for well over a 100 RPMs. Any faster and the ping will 'skip' counts. It also beeps so you can hear it counting. It's kind of a ping insturment, wave your hand in front and you get a different tone for the measured range. It is limited by the 'word' max value.
I posted the code below. Its not clear to me how to put this in a panel by itself, so sorry for that. But this does work. We used this the past few days to wind some 1000 turn coils, and it worked pretty good.
note the logic with the indistanceflg... This counts once, and then waits until the range goes long again.
Maybe this code will help you. You can see the count results on both the PC and the LCD here.
Regards,
Walt,