Proximity Sensor Project issue involving speed of a moving object on a flat plane.

Hi,

I was wondering if you folks would be able to point me in the right direction regarding making a proximity sensor project?

I currently have a setup of an Arduino nano, an I2C OLED screen, and a pair of IR LEDs and PhotoTransistors. I have the LED, PhotoTransistor pairs spaced apart about 6 inches, though I would like to go to 12 inches, and I call this a “gate” or “trip wire”. I have a second set of LED/PhotoTransistor pair setup in the same way as a second “gate/trip wire”.

The distance between the two gates/trip-wires are a foot apart.

I have these going to analog inputs on the Arduino Nano.

So, the idea is that I have a ball that passes through the “gate 1”, which tells the Arduino to start counting milliseconds. When the ball then passes “gate 2”, it stops counting milliseconds and gets the duration of time between when it passed the first gate and second gate. Because I know the distance between gates is a foot apart, I can derive a speed in feet per second or miles per hour. I can determine it passes through a gate when the analog input of the date drops 5 bits or more in value from where the ADC started at boot.

So the problem I am having is that if the ball moves faster than 6 or so miles per hour, the Arduino Nano’s analog pin doesn’t seem to drop, so it never appears to be detected as passing through the gate. I am not sure if it’s the “speed” of the LED phototransistor pair not electrically reacting fast enough, or if the Arduino Nano isn’t fast enough. I did try a SAMD21 Arduino, but that didn’t seem to change anything.

Do you folks have anything you could recommend, chips, breakout boards, etc, that would improve my ability to capture the speed of a moving ball on a flat plane?

Hi, is it possible to use an interrupt pin instead of analog pin? Have you tried that?

I was afraid to try that. Currently, at the distance the IR LED and Transistor are located, when nothing obstructs it, it only reads 1V. So, if I put it on an interrupt, whether an object passes by it or not, it will still read “low”. So, I’d have nothing to interrupt.

Also, I’ve had the bits drop to only 5 or less than it previously was when something passes, so if I amplified the 1V signal to say, 4V, it might only go down to 3.9V when something passes through it. On an interrupt on that scenario, it would always read “high” and the interrupt would never trigger. However, this might not be true, if my Fluke isn’t fast enough to see the voltage drop to 0 or something and I’m only “seeing” it drop a couple millivolts because of the speed of my Fluke (and of the Arduino’s serial output)

Analog reads are slow. For a fast photogate, it is best to use a photodiode and suitable analog circuity to create logic level voltages from the signal, so the transition can be detected by a digital pin. You will also need to exclude extraneous light, perhaps by using a tube and lens to limit the photodiode field of view.

Using an IR laser diode instead of an LED will also help.

Here is a decent approach for accurate measurements (PDF article):

arduino_photogate.pdf (2.32 MB)

As an update, I tried using rpiloverbd’s suggestion and used interrupts. I had to use a rail-to-rail op-amp to do it, but now it appears to work much better. I then moved it over to an ESP8266 at 80MHz because I wanted to use a larger I2C display to show what the microcontroller is seeing, so I had to drop my voltages from 5V down to 3.3V and set the op-amp accordingly. Still works pretty well, but if the ball exceeds 17 or so MPH the second gate seems to not trip. This might be acceptable, but will do some field tests to be sure.

I dropped back to an Arduino Uno and realized that in my interrupt functions that by using and if/then statement, that lagged it enough on the interrupt that I was not getting speeds over 17 MPH. So now, even on my Uno, I can get speeds up to 24 MPH, and haven’t beaten the interrupts, even once, after making this change.