I am trying to measure the velocity of an object moving in front of two sensors. The distance between the sensors is very small, 43mm, and I am using the micros () function to measure to falling edge from one sensor to another.
Currently, I am using an Ultrasonic sensor HC-SR04 for my object detection.
I am having issues that at higher velocities. My object passes by the sensor before a falling edge is detected.
I am looking for another approach. I am thinking that maybe a beam of light approach may have better results but wanted to post here before I redesigned the project.
Wrong choice for sensors for your project. Ultrasonic measurements are pulsed sound emitters and listen for an echo. You CANNOT use two together at the same time because each will hear the other's sound pulse or the other's echo. In addition, since the devices are pulsed, the odds of either device seeing your object are rather slim.
Follow the other advice for possible sensor.
Here is image of my system: I will look into a doppler sensor. The object (a ball) is at rest in front of Starting Point. I am trying to approximate the initial velocity with the two sensors.
Thank you. Can you recommend an appropriate light gate to use? Am I correct to assume that the light gate will be an HIGH/LOW measurement and not a 'analog' of distance?
The emitter can be just a simple steady on IR emitter LED or an IR LED that emits a modulated signal. The modulated signal makes it possible for the detector to distinguish the emitter signal from ambient light.
The detector can be a simple IR phototransistor or a purpose built detector tuned to the modulated frequency of the emitter.
See this Vishay page for information on emitters and detectors used in IR reflective and light gate presence sensor applications.
To get further into your problem, look at the code your are using. Each HC-SR04 requires a pulse to initiate the ultrasonic pulse. Then your code used a pulseln() function to measure the time in microseconds until an echo is received. The pulseln() function BLOCKS your code execution until an echo is received or a time-out occurs. Study your code and find where that is done.
A second HC-SR04 cannot begin to make a pulse until the first device has received an echo or timed out.
I think your idea is not bad, it is just your sensor type that is wrong. I would make an array of IR emitter-receptor. Then reading the sensor you could fit very accurately the position of the ball.
If the ball is metallic may be you could use an array of hall sensors.
Thanks for the tip. I didn’t realize pulseln() was blocking so I had all sensors going at all times.
I re-ordered the code so only one sensor was going at a time and got positive results. At speeds of less than 4fps, the sensors work. Above that- I blow by them.
I agree with the thread that these sensors I selected are not the best approach.
I going to try a “break the beam of light” approach next. I can’t find a good example for using an IR transmitter/receiver pair like a switch (just break the beam or not break the beam). Most examples and libraries seem to be more focused on transmitting/ receiving data. If anyone knows of one- can you please send a link?
I am planning on using:
MELIFE 5 Sets Digital 38khz Ir Receiver Ir Transmitter Sensor Module Kit for EK8477. https://a.co/d/1bA5RO6
You can use the tone() function to modulate the emitter at the required 38KHz. If the emitter requires more than about 20mA, a transistor should be used to drive it.
If the IR receiver is made for light gate use (not IR remote control) it will show one state (high or low) with the light on it and the other state with the light off. Without a data sheet for the receiver, I can't tell whether it is suitable for light gate or what the active level is. Easy enough to find out once you have them, though.
I use a length of 1/2" PVC pipe with a single photo-interrupter type sensor (opposed emitter and detector on opposite sides of the tube) to measure the speed of a fixed-size ball and it works pretty well. Since the ball is a fixed size, the speed can be inferred directly from how long the sensor is blocked.
The fastest I am expecting is 15 fps, so the falling edge to the falling edge would be 9.4 milliseconds.
I looked that TOF libraries and I was concerned with the delay() in the code. In order to catch the object I need to be really careful about my cycle time on the entire program. In the program that your wrote with one sensor, do you know what your cycle time was?
I was continuously sampling every 50mSec - looking at the datasheet range timing I doubt if it can be much shorter than 50mSec and therefore too slow for your object moving at 15fps
I would think a light gate as suggested by @groundFungus would be worth looking at
possibly using an optical sensor such as the OPL550A
First I have to agree with everyone else who suggest you are using the wrong sensor for the application.
I would suggest either a photo transistor be it IR or similar. What you are looking at is a basic chronograph to measure velocity. A Google of Arduino Chronograph should provide some good suggestions. Velocity will always equal Distance / Time. That is what your code will always reflect. There are plenty of designs out there using doppler effect including accurate ballistic chronographs but I doubt you really need that as a solution for 15 FPS. Most simple solutions will involve your object breaking a light beam so a light source (Emitter) and receiver (detector) configuration. Much like a simple garage door safety works.
I have gotten good results using a LASER Emitter and LASER Detector. Even in average ambient light conditions. Not in bright daylight.
Another emitter and sensor is using IR and I suggest a modulated IR so ambient light is not a problem like used in a TV remote. A Google of "Modulated IR sensor and transmitter" or similar should get you plenty of results including off the shelf inexpensive modules.
You are sending to the screen so often you are filling the serial buffer and making the Arduino wait until there is room in the buffer for more message text.
Change the baud rate to the maximum you can do for the type of Arduino you are using.