How to count

How to count (objects)
Thomas Vrakking

Wat was counted

The scope of the assignment was to count metal objects falling through a metal shute. The bottom part of the shute can be edited.

Vision-based systems

First of all, they could be detected using vision, either by implementing a PixyCam connected to a microcontroller or by using a more professional industrial camera such as a Cognex vision system connected to a computer. While this option offers a lot of flexibility and can be highly reliable, it is relatively difficult and time-consuming to set up, especially when other more straightforward options are available.

Inductive sensors

An inductive sensor could have been an excellent option for detecting metal objects. However, the detection range is limited — up to 15 mm for standard sensors, and up to 40 mm for special long-range types. Unfortunately, these ranges are too short for the required chute dimensions.

Capacitive sensors

Capacitive sensors detect changes in capacitance and can pick up both metallic and non-metallic objects, such as plastics, liquids, powders, and even wood. Their detection range is slightly larger than inductive sensors (up to about 60 mm), depending on the target material and sensor size. Although they are more versatile, they are also more sensitive to environmental factors like dust, humidity, and temperature fluctuations, which can cause false positives or unstable readings in factory environments.

Hall-effect sensors

A Hall-effect sensor measures magnetic fields, making it a poor fit for detecting regular metal parts inside a metal chute. Unless the parts are magnetized, this solution would not be practical.

Load cell sensors

Load cell sensors measure weight and could theoretically detect parts falling onto a plate connected to the load cell. However, this option is generally unsuitable for factory environments due to vibrations and mechanical noise, which can lead to false positives and unreliable counting.

Mechanical button

Another possible solution involves a simple mechanism where objects fall onto a plate attached to a button or limit switch. When the object lands, it presses the button, and when it slides off, the button is released. The challenge here lies in selecting a button with a precisely tuned spring force to reliably detect each object without being triggered by vibrations or minor impacts.

LDR (Light Dependent Resistor)

An LDR sensor can detect changes in light intensity. However, in a metal-on-metal chute, light reflections would likely be too similar in intensity, making it difficult for the LDR to reliably detect individual objects.

Break-beam sensors

Several types of break-beam sensors exist:

  • Ultrasonic sensors: These require a bit more detection time and may not be fast enough to reliably count quickly falling objects.
  • Infrared sensors: These require precise alignment between emitter and receiver, which can be difficult in a fast-moving industrial environment.
  • Photoelectric sensors: These do not have the disadvantages of the other two and are therefore a very good option. They can reliably detect objects passing through a light beam.

Chosen solution: Photoelectric sensor

The solution we ultimately selected is a photoelectric sensor. This option offers several practical advantages in a factory environment:

  • Fast response time, capable of reliably detecting fast-moving, falling objects.
  • Easy installation and alignment, especially when combined with a reflector to enlarge the detection area and improve reliability.
  • Insensitive to environmental factors such as vibration, dust, and lighting variations, which could cause issues for capacitive or load cell-based systems.
  • Simple to program and integrate with a microcontroller or industrial PLC, typically offering straightforward digital output signals (e.g., PNP/NPN) when the light beam is interrupted.
  • Cost-effective and widely available in different models and detection ranges to match the required chute size.
  • Simple to implement into an existing system, there are minimal changes needed.

These characteristics made the photoelectric sensor the most reliable, scalable, and low-maintenance option for our counting application.

Code

The code used for the photoelectric sensor is made in C++ for arduino, the code is as follows:
#define SENSOR_PIN 3 // Sensor connected to digital pin 3

int count = 0;

void setup() {

Serial.begin(115200);  



pinMode(SENSOR_PIN, INPUT);  // Use internal pull-up to avoid floating  

}

void loop() {

static unsigned long lastDetectionTime = 0;  



static bool wasDetected = false;  



 // Read the sensor multiple times for stability  



bool stableLow = true;  



for (int i = 0; i < 5; i++) {  



    if (digitalRead(SENSOR_PIN) != LOW) {  



        stableLow = false;  



        // Serial.println("False");  



        break;  



    }  



    delay(2);  // Small delay between reads (2ms × 5 = 10ms check window)  



}  



 if (stableLow && !wasDetected) {  



    if (millis() - lastDetectionTime > 75) {  // Debounce window  



        count++;  



        // Serial.print("Count: ");  



        Serial.println(count);  



        delay(1000);  



         if (count == 300) count = 0;  



         lastDetectionTime = millis();  



        wasDetected = true;  



    }  



} else if (digitalRead(SENSOR_PIN) == HIGH) {  



    wasDetected = false;  



}  

}

This code is made to count 300 objects. The propper delays are put in place to prevent double detections. Also, multiple detections of one object are needed to count te prevent detection when no object is falling through the shute.

Conclusion

In industrial applications where objects fall through a chute, photoelectric sensors offer an excellent balance between cost, reliability, ease of installation, detection speed, and programmability.

While vision systems provide more flexibility and the ability to perform object recognition, their complexity and high setup cost make them less suitable for simple counting tasks. Mechanical, inductive, capacitive, and load cell-based solutions each have specific drawbacks in terms of detection range, sensitivity to environmental factors, or mechanical wear.

By selecting a photoelectric sensor, we achieved:

  • Stable detection at the required distance
  • Fast and accurate counting of falling parts
  • Easy integration into our existing control system
  • Minimal susceptibility to factory noise and conditions

This makes the photoelectric sensor the most practical and scalable solution for our needs.