Which sensor to use for locating static position

I'm working on a machine that picks up medicinal pills and dispense them on schedule.
The pills will be picked up by some kind of CNC moving mechanism-like suction arm.
The problem is I don't know which type of sensors to use to locate the pills position to pick up from the tray.
Is there any sensors that can do this? And how should I use it/them?
Thank you all very much. All replies are appreciated.

Colour perhaps?

There are a number of devices that sort M+M's and so on based on colour. As long as the pill colour can be seen against on the tray.

I think I saw some on Instructables, or maybe it was YouTube.

But with color sensor will you be able to locate their exact locations? Maybe a combination of color and ultrasonic? Sorry I'm still really new to this :))

Ok here is a reply that works! When we have loose chips(ICs) to place on printed circuit boards, we order the chips in what is called "waffle trays". These trays have a pattern of depressions that can hold only one chip. The pick and place machine knows where to find each of the pockets. So, it can pick up the chip on one pocket after the other. If a pocket does not have a chip, the machine determines this and moves to the next pocket.

If you put the pills in a similar tray, that problem is solved.

Paul

The Pixy (CMUcam5) can identify and locate variously colored blobs, and it works with Arduino.

Pixy looks nice :slight_smile: although not worth the $$$ to me personally as a hobbyist.

Also, it might be possible to use a simple light / dark sensor like used in line following robots, rather than colour.

although not worth the $$$ to me personally as a hobbyist.

It is not your project.