Phidgets Lesson 3: Object Detection

This lesson will help you choose and install a sensor for detecting objects. There are plenty of sensors that can do object detection, each offering different pros and cons, so you need to decide which one will fit your project best.

When choosing a sensor, you need to ask yourself how you’ll be using it. You’ll want to consider whether you need a sensor that measures the distance of an object - infrared (has a small distance range and doesn't function in sunlight) and ultrasonic (can have difficulty with odd shapes and densities and can't be installed outdoors) can both do this. Maybe you need to differentiate between objects - an RFID sensor (senses only tagged objects) or camera (requires more intensive algorithms) is what you’re looking for. Are you looking to detect objects passing a certain location? You can use capacitive sensors (although these have a limited range), contact switches (which require direct contact), or a photoelectric tripwire. If you’re detecting metallic objects, then go for an inductive sensor.

Phidgets sensors for object detection(clockwise from top-left: RFID, sharp distance sensor connected to an interface kit 8/8/8, inductive proximity sensor, ultrasonic sonar sensor and photoelectric tripwire sensor)

Now that you’ve chosen your sensor, you can start programming. Object detection works well with event driven programming, which is demonstrated in many of the Phidgets examples. Download the Phidgets examples in the programming language you prefer (see lesson 2 for instructions on running examples).

In the SensorChangeHandler, you can verify the sensor and run checks on the value. For most sensors, this will be setting a threshold, which you will need to calibrate by using the control panel or running the interface kit example program while the sensor detects objects. You may have varying triggers if you want different responses based on an input, like the distance or the RFID tag.

The response is up to you. In my code, I chose to print a message and turn an indicator light on. Your program could do anything, like play a sound from the computer, trigger a relay to turn on a lamp, unlock a bolt, or run a motor to open a door.

In C, this looks something like this:

int CCONV SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int Value)
    printf("Digital Input: %d > State: %d\n", Index, State);
    if (Index == OBJECT_DETECTOR)
        if (Value > 500) // The threshold value
            printf("Object %d detected\n", objectCount);
            CPhidgetInterfaceKit_setOutputState(IFK, INDICATOR_LIGHT, 1);
            CPhidgetInterfaceKit_setOutputState(IFK, INDICATOR_LIGHT, 0);
    return 0

In an RFID application, the TagHandlers work much like the SensorChangeHandlers. You can respond to specific RFID tags while ignoring others, then implement your response within those functions.

There are a lot of ways to detect objects, each offering their own advantages and disadvantages. Setting up a response is easily done within the sensor change handler or tag handler. It's easy to make these changes to the Phidgets examples and then grow your system to respond in complex and interesting ways to the objects you detect. Good luck.

LikedLike this to see more

Spread the word

Flag this post

Thanks for helping to keep our community civil!

Notify staff privately
It's Spam
This post is an advertisement, or vandalism. It is not useful or relevant to the current topic.

You flagged this as spam. Undo flag.Flag Post