Ultrasonic sensors to set Buzzer off for missing Capsules

I have a Clear PVC that is moving constantly in a linear left to right direction which contains Capsules.
Like medicine in blisters that contain 10 tablets.

I’m trying to make a simple device using Ultrasonic sensor to connect to a board that triggers a buzzer
when there is a capsule missing.

So basically, the surface where the top of the capsule is level with the clear PVC which will make it the same distance to the sensor BUT when a capsule is missing, the sensor will read a different distance say 1cm longer and trigger the buzzer off.

It doesn’t have to be an Ultrasonic sensor but any sensor with suggestions would be much appreciated
for what I’m trying to create.

Thanks again


Hi @Christian261850
Welcome to the forum.

Maybe this will work for you. :slight_smile:

It has a tolerance of +/- 3% so you want it close to what you are measuring to increase precision.

What is the difference in height between the pit and the plate of the blister?
Will that tolerance be sufficient?

Good to have you with us.
Pix :heavy_heart_exclamation:


Thanks so much for reading my post.

The reason I chose the Ultrasonic is because it uses Sound instead of a beam.
The Clear PVC is clear and I’m thinking the laser will shoot through to the bottom where the Ultrasonic
will read the clear PVC.

Sorry, I’m new to electronics prob making no sense here.

Anyways, yes. Is this what you’re referring to: It is 9mm

1 Like

Ah good thinking!
I should have read more carefully and addressed that part of your question. My bad. :man_facepalming:

I was thinking that you could detect the presence of a capsule, since if one is absent the laser would detect no change.
However it’s not certain how the laser will react to the plastic and so it’s maybe not a sound plan.

Looks like ultrasonic will work but getting the right one is important.
Below is a link to my best guess.

Concerning depth this Pico has the sensitivity to deal with a rise over run of 0.09 but it is a little tight. That means it’s important the pico itself doesn’t move too much when measuring. :slight_smile:

Usually, ultrasonics have a property called Effectual Angle. This is important to you since you want to focus on a very particular spot. i,e, you want a small effectual angle. I’m not sure what the effectual angle on the pico is but maybe a core team member can help me? :pray:
If it’s within 10degrees I think we’re in with a winner.

I think RADAR would also work for you, but I have never personally used a radar module. Maybes someone else with more experience might weigh in.


This is what the friendly gentlemen originally suggested from Core-E but later realising what I wanted to achieve maybe wouldn’t work. However, he hasn’t seen the photos above to know exactly what I wanted I guess.

I’m thinking what I want is so simple, but it doesn’t look that way.

Just wanted this Ultrasonic sensor to read the same distance continuously but when it picks up a different distance (9mm longer) reading to set off a Buzzer each time.

Worried about the programming as well as I have no clue but will it be doable?

1 Like

I’m confident we can find a solution that requires very simple code. I bet we could find an open source example and modify it only slightly for a good result. :slight_smile:

I think there must be a simple solution out there. :muscle:
I’m not sure what it is, but I’m just one guy. There are lots of other people on this forum who might have a idea :slight_smile:

1 Like

Much appreciate your time.

1 Like

Hi Christian
I think you would have to do your sensing before the top goes on or most sensor types would see the top and it would not matter if the capsule were present or not.

Regarding acoustic sensing I think the transmitted beam width might be a bit wide to detect the narrow recess where the capsule fits. For this I think you would need a narrow beam like a laser spot or similar and synchronise so the detector beam transmits when the capsule is directly below. If you try to use a continuous transmission it might coincide with the sides of the capsule and “see” the bottom of the hollow and thus false triggering. The conveyor does not seem particularly fast so something is probably doable.

Another way might be to use a beam which would pass through the clear plastic and be blocked with the presence of a capsule. But once again this would have to be synchronised with the conveyor position.
Cheers Bob

1 Like

Hi Bob.
I was a little worried about how the a laser would defract on the plastic. Do you have any experience or intuition about if a laser would cleanly pass through plastic? I think your solution is a winner :smile:

Hi All

That would depend on the Refractive Index and the thickness of the plastic. The RI of perspex is terrible, just drill a hole in a block and view it from different angles. Water is quite bad as evidenced with a stick into a pond at an angle and see how it appears to “bend” at the surface, and the magnification of a drop of water os a printed page. Glass and lens plastics are quite high.

It is unfortunately (but mostly fortunate) a fact of life (and physics) otherwise we would not have spectacles and camera and telescope lenses etc.

Unless you can find someone with a lot of experience in this field I think I am correct in saying if you can keep the thickness right down you will have a better chance of getting a decent through beam. It is the area that is at an angle that is the worry. The perpendicular component will pass straight through with no refraction.
Cheers Bob.
A bit of trivia:
O’Brien Glass make cracks in a windscreen disappear by forcing a substance into the crack that has the same RI as the glass, so the cracks become invisible.
One early (during my working live anyway) method of joining optical fibres without welding was to have a jelly like substance between the fibre ends with the RI the same as the fibre. Worked quite well with minimum loss.


Hello Bob. Thank you for the information.

It seems to me that it’s getting a bit too complicated and over my head.
Your knowledge has helped me to understand a lot though.

Thanks again


Hey Christian Pix and Bob,

Just throwing in my 2c

Physical detection for a problem like this is possible. Weight, Radio, Cleverly Mounted Microswitch, Microwave Radar, Ultrasonic, Radio, IR Reflection, ToF, and a few other tricks “should” work (with varying success I’d argue depending on the configuration and type of sensor).

Although in my opinion, this is a perfect example of a problem that can be solved by image recognition. It may seem intimidating at first, although getting a model trained against a relatively simple environment and problem like this shouldn’t be too difficult compared to other less generic use-cases.

I’d personally start looking into OpenCV and maybe Amazon Web Services Rekognition (intentional typo, it’s a title)

Just need to have an API that you can listen to the output of a trained model from, and trigger your buzzer or any other behaviour required on hardware.

1 Like

Hi All
A point worth remembering is that you have 6 capsules across the conveyor. This means 6 sensors and 6 processing systems as they will be all simultaneous.

What about a gantry with 6 sensitive microswitches mounted so the operating arm (which could be fitted with a roller) runs along the surface and stays operated when the hole is occupied with a capsule but releases when a capsule is missing. They could be wired in parallel or series so that any one of them operated would sound your alarm or do something else like stop the conveyor. Probably don’t need a processor at all.

Microswitches come on various values of operating force. Some are very sensitive as you will need so the operating mechanism does not push a capsule out of its little nest. Reputable suppliers should publish this information so I wouldn’t go looking at the cheap Chinese shops which you are lucky to get a reliable picture.
Cheers Bob

1 Like

I agree, a gantry of fine microswitches is likely the best soln here, apply Occum’s Razor.

Depending on their sensitivity one trick I’ve used before is to set up some hairs of (relatively thick) magnet wire to act as fingers dragging off the surface rather than using the face of the microswitch. Some also have built in rollers for these kinds of purposes on their face.

Yep, although with a camera mounted above, you may be able to get all six in one shot if you go with the image recognition route.