Object counter « counting box »


I have as project at work to create a « counting box ».
People in my team are counting daily small pieces (5 cm x 2 cm x 1 cm), in plastic, 1 by 1. For them to make their life easier (and increase our accuracy), i would like to create a small box where they could throw the pieces inside, and it would count them.

On this box, i would like 5 electonic parts :

  • a PIR motion sensor (as the parts a really small, i don’t want to have a laser only taking in consideration 1 direction but more a surface)
  • a display (big and simple), where it would be possible to count from 0 to 100 (no lore info is needed, therefore a lcd screen is not mandatory
  • a button « reset » (to put back to counter to 0)
  • a button + (to manually increase the counter of 1)
  • a button - (to manually decrease the counter of 1)
    I bought a Arduino nano, i think totally enough to perform the job.

I found a lot of videos taking about it in internet, but none of them are fulfilling my requirements. Like this one : Arduino counter using infrared sensor (sharp IR) - YouTube

Would anybody have information to help me ?
Thank you

Please Google pir sensor and study how they work.



Thank you for the answer.
I just figured out that pir sensors can only detect « warm » bodies. So i don’t think it will detect my plastic bags. Is that right ?

If that’s the case, which kind of sensor do you think i should use to detect those plastic bags ?

Again, i would like to cover a surface more than a single line. So to have a detector capable to check in 2 dimensions, and not only 1.

Or maybe there are some « tricks » that could do the job as well.

Thank you for your support

IR emitter and IR detector or Ultrasonic Sensor will do the job.

Ultrasonic Sensor will do the job.

Might be too slow, and miss some items.

I'd go with....

IR emitter and IR detector

... though.

Get one of these to test with; they come in different distances. You can test without an Arduino: just apply 5V and see if its onboard led blinks as the item drops past.

When it gets to coding, you'll need to go the state change detect route, else it will likely give multiple counts while the item's in front of the beam for a while as it passes..

Plastic piece? Plastic bag? What exactly do you have? Bags don't throw well, and you mention you're throwing them.

I was thinking of a bounce plate. Like used in seed counters. But it depends on what your plastic pieces really are, so do post some images!


Sorry for the long time without replying.
Attached 2 pictures to show which kind of items to count we are talking about.
They are plastic bags with jewellery items inside, in silver or gold. Therefore the accuracy needs to be perfect, as it's high value items (and not just screws or anything). The size of the bag can be 4x6 cm (like the small one o nthe picture), or 8x12 (like the big picture).

Would this "Pololu Carrier with Sharp GP2Y0D815Z0F Digital Distance Sensor 15cm" you propose detect those bags? If yes, as i'm leaving in Germany, do you know if i can get it somewhere in europe where i don't need to wait 1 month to receive it ? Or a similar component maybe ?
And if no, any other idea of cheap but reliable component i could use ?

Other question : for the display and the buttons, would you have references you rely on i could buy ? I don't want to buy anything, and then it breaks after 2 hours...

Thank you for the help again,

That seriously ups the ante.

IR: the bags may be transparent (probably are) to IR. So your bags may not be seen (all transparent passing in front of the sensor), or counted double (object & label as separate items) or triple (the necklace: two signals when the necklace passes, and a third for the label). You will have to try that out.

Speed: check the data sheet of the sensors for how quick they can react, and make sure your bags don't fall past the sensor too fast. And make sure that your bags fall in front of the sensor in the first place, in an orientation that allows them to be seen reliably.

You will anyway have to make sure there's enough time between the items, to be able to count properly. So the actual handling is going to be a major factor. Is it people throwing the bags one by one in the counting machine? Or do you want them to dump a box full of items in some hopper that then does the separation into single items and counting?

The people will throw each bag one by one (not a full bag), so that’s already a good point.

I understand that the IR might count double or triple the item, which need to be send in a way that the sensor recognize them.
But what about if i install 2 or multiple IR (to make a kind of grid). With the code making sure when 1 IR detects the item, it deactivate all other IR for a few milliseconds before they are all activated again ?

I wouldn't disable the sensors, just ignore the input from the others. If you know you're not going to get more than say one bag per second, you can safely ignore all other triggers for half a second before counting again.

The main thing is going to be the physical layout of the whole thing. You have to cover it in a sensor grid that's fine enough to not let the smallest bag pass undetected. That's why I'm still thinking you may be better off with a bounce plate - I think at least you should have a look at the option. A piezo disk or two and rigid plate is what's needed.

You’re right, ignoring the signal for a couple of milliseconds would make more sense :slight_smile:

If i understand it correctly, the bounce plate would count a item from the moment it touches it. Right ?
If i have in my box 50 or 60 pieces already, and i continue to launch some inside, would it still count it accuratly ?

I’ve ordered yesterday some push buttons, IR sensors and 7-sensors components with 3 digits (as we’ll never count more than 999 pieces at once, but more than 99 yes).
Do you know where i can find which resistors i need to use ? And how to place them ?
I don’t want to make any mistake and break the components from the 1st use.

For the arduino code, i’ll check around if i find easy code. Otherwise, do you know where i could find some help ?

Thank you very much again for your help, and your quick responses always

A bounce plate would be mounted at the top of the box, so the item is falling first against that plate, then slides into the box.

Which resistors (if any, and capacitors for that matter) to use depends on the exact components you have.

For code, lots of examples out there for all kinds of components, do a Google search of your part number with "Arduino library" and good chance you'll find some. There's definitely code out there for all kinds of 7-segment displays and other kids of displays, for break beam sensors, for push buttons, bounce plates (aka "knock sensor", see also this recent post & thread), etc.

Thanks for the description from the bounce plate. It changes the way i was seeing this counting box, but why not :wink:

I checked the link, and the video from the guy : basically i want to do the same principle, not with nerf but with jewelry :slight_smile:

I’ll have a deeper look, and see how it inspires me.
I’ll buy already now a piezo vibration sensor like in the link, that i can try both option (IR or this one).

Now i need to receive it, and make some tests.
I guess i’ll still need some help in a few days :slight_smile:


I've tried to make some small schema of the 2 possibilities for this counting box :

Schema 1 : with IR sensors

Schema 2 : with Bounce Plate

To make sure we are on the same level of understanding, and also that we go to the right direction, do you confirm that these schema are correct ?

If yes, we'll have our physical prototypes :slight_smile:
Then I'll need to figure out the electrical schema, and then the Arduino code. Still some steps to go.


Or, combine the two into a chute with an IR sensor. Mount the IR as low to the sliding surface as practicable. As the package slides it breaks the IR beam.



And add a capacitive sensor to the chute.

The IR sensors pictured are proximity sensors ,not break beam sensors. They work basically with opposite principles: break beam reacts to the absence of a beam because it's blocked by an object that's in the way; the proximity sensor reacts to the presence of IR light as it's reflected by an object in front of the sensor.

With those bags I think the first will work better: if the beam is reflected away, the proximity sensor will still not see it. Experimentation is needed, for sure.

Thanks for all these replies.

Now i have 3 questions for you :

  • what is the maximum distance that a ir proximity sensor can detect ?

  • can i mount both ir sensors together to build a break beam sensor (like the picture from dougp) ?

  • what is the added value to have a capacitor ?


  • can i mount both ir sensors together to build a break beam sensor (like the picture from dougp) ?

That exact configuration probably will not work. You need to know whether the sensors are modulated. If they are, each sensor is looking for its own light beam and others will be out of sync. You could try a corner cube reflector and a single sensor to make a retro-reflective sensor but I believe you'd have more success - and less fuss - using something made for the purpose. You might have to do some level translation but the sensor will be reliable.

Don't forget, you have to come up with a way to mount whatever you decide on. Commercial offerings are amenable to a wide variety of mounting options.

Some additional reading material.


  • what is the maximum distance that a ir proximity sensor can detect ?

Depending on the actual sensor up to a few meters. The one pictured, 10-20 cm or so, but it depends highly on the object, the incident angle and the level of ambient IR.

  • can i mount both ir sensors together to build a break beam sensor (like the picture from dougp) ?

A proximity sensor looks for the presence of an IR signal, a break beam sensor for the absence. If you would place two proximity sensors opposite one another they would not give any signal: when there's no object presence they see the transmitted IR of the opposite emitter, when there's an object they see the reflected IR of their own.

If you want to go the break beam route, get a break beam sensor.

  • what is the added value to have a capacitor ?

Depends on where (both from an electrical and physical standpoint) exactly in your circuit you plan to add one, what value, and maybe even what type of capacitor it is.