# How to count the number of objects in a bottle?

I am working on a pet project using arduino where I need to keep track on number of objects in a bottle.It requires counting the number of objects(size of a regular pill and approximately of the same weight). My approach to this was asking the user to drop one object into the bottle and weigh it, then ask the user to drop the remaining objects into the bottle. So I can find the number of objects using the formula (total weight)/(weight of single pill).Whenever the weight of the objects in the bottle changes the formula is used and number of objects still in the bottle are found out, as you can see this is not very user friendly so I was looking if anyone can help me out with a better solution.

EDIT:If not by using weight is there any way to count the number of objects by using IR sensors etc., cause I have seen the load cells to measure small cells are quite expensive.

• I think it's a fine idea. Nov 20, 2015 at 11:08
• Sounds like you've already solved it. Though I'd suggest weighing 10 or 20 and dividing by that number to get a more accurate figure. Nov 20, 2015 at 11:29
• Would you please describe a few more parameters of your problem? For example, how accurate must it be? A few % error is very different from 99.99999% accurate. What ranges of weight of objects, and how uniform are they? Approximately the minimum and maximum number of objects? Have you a large time/effort, technology, skill, money budget? At one end the problem might be estimating the number of peanut M&M's in a bag (no one could mind if they get too many :-) vs dispensing expensive and dangerous drugs. Nov 20, 2015 at 13:46
• This approach is commonly used manufacturing to count product: press "count" on the scale, the scale will tare (zero), "+5" (or some appropriate value) will show up on the display, the user will load five objects, the scale works out an average weight for the object and calculates count based on that value. Much faster than counting product. You now no longer need to "keep track" of the number of objects in the bottle - you can just work it out. Nov 20, 2015 at 18:20
• If not by using weight is there any way to count the number of objects by using IR sensors etc., cause I have seen the load cells to measure small weights are quite expensive.
– Arun
Nov 21, 2015 at 5:11

A regular pill weighs less than 1g. The main challenge with your approach is to weigh this exactly. As the weighing range of affordable precision scales is quite limited, it's even more challenging to weigh the pills together with the bottle.
Nick's suggestion may help to calculate the exact weight of one object - but you still have the problem to accurately weigh differences of +-1 object.

I'd say you should either lower your requirements (use heavier objects or allow a tolerance on counting) - or buy a ready-to-use counting precision scale.

You could allow the user to drop more than one at a time. Simply measure the hole time and store the weight differences.

All differences a an integer multiple of the weight of a 'pill' so after a few stored value you should be able to calculate the weight of the GDC (greatest common divisor) of all weight differences which should be after a few values be 1.

Than you have the weight of 1 'pill'

Example:

• weight of empty bottle: 100g
• weight after 1st filling: 163g (unknown number of pills) => known differences: 63
• weight after 2nd filling: 211g (unknown number of pills) => known differences: 63, 111, 48 GDC( 63, 111, 48) = 3

3g was the number I was searching for. You night wait a 3rd and 4th filling to ensure that you do not have a multiple of the real weight.