Hi, I have a speed measurement project with the HC-SR04 Ultrasonic Sensor. I there a code that the sensor stops after an object passes and made the measurements and will wait for the next object to pass by?
You have not provided much detail, but it sounds as though you need to detect when an object becomes detected rather than when it is detected
See the StateChangeDetection example in the IDE
What I want is: the sensor start reading when an object (Soccer ball)passes the sensor and stops when the ball has passed. I need one reading to export to my excel sheet.
Thanks
I could use a infra red sensor that will trigger a relay to activate the HC-SR04, instead of a push button?
More detail of what your project please. What part does the pushbutton play in the project ?
Are you trying to count the number of objects seen, how long they are in view or something else ?
Under what circumstances do you think that you need to turn the sensor on and off ?
for the speed and distance (Position) when a soccer ball crosses the goal line. that data will be collected in a excel sheet. The problem is that the sensor must strop pinging,. I need only the data when the ball crosses and after that goes back to zero.
Hi,
Can you draw a diagram showing where you would position the Ultrasonic unit and the goal line?
Is the Ultrasonic looking along the line across the face of the goal?
Thanks.. Tom...
The StateChangeDetection principle will work OK for what you want. When the ball is not in range of the sensor you will get a large (no ball detected) distance reading which you ignore.
Once the ball is detected then ignore all subsequent distance values until the ball is no longer in vision and the readings return to normal (no ball detected) values
No need for a pushbutton or to turn the sensor on and off
However, if you are intending to use the HC-SR04 sensor in a full size soccer goal I anticipate that you will not get accurate readings over long distances
the posts are 3m apart (indoors) can you help with the code? If the distance is more than 3meters it returns 0. Thanks
The sensor will do the ping and listen for the echo each time your code asks it to do it.
You would learn more if you wrote the code
Have you got a sketch that reads the distance and prints it if the ball is in range ? Don't worry at this stage that the ball is detected multiple times as it crosses between the posts
That's going to be very hard with a cheap ultrasonic rangefinder. The beam width is quite wide so the rangefinder will have no way of detecting if the ball is outside the goal or inside the goal. And it can't take samples much faster than 40 per second. A soccer ball moves about 67cm per sample!
The ultrasonics also can't tell the difference between a ball and a goalie, if this is in a game and not just for practice on an unguarded goal.
Hi,
Have you written any code to make sure you can communicate with the UltraSonic?
I suggest you use the NewPing library and try some of the examples that show you how to work with the sensor.
Tom...
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.