si618
Posts: 7
Joined: Tue Jul 09, 2013 4:09 am

Sensor for bike lap timer

Tue Jul 09, 2013 5:14 am

Greetings,

Seeking advice on a suitable sensor to interface with a raspberry pi for use as a lap timer for a bike pump track. Ideally the sensor should detect when the tyre breaks the beam, but rider detection is ok so long as it's reasonably consistent.

Google has turned up this PIR, but I'm an electronics novice so am unsure. Any thoughts or better alternatives? The low current spot model (AMN43121) looks the most appropriate. I'm assuming I can use the 3.3V, GND and a GPIO pin on the RPi expansion header to power and interface with the sensor.

My plan is to house the RPi in an IP66 enclosure with a PV panel and batteries, and mount it in a PV friendly location about 2-3 metres from where the sensor will be placed in a smaller IP66 enclosure in the middle of the track, facing outwards. The sensor will be around 30cm off the ground, mounted on a pole with a spring at the bottom should it should be able to take a hit. Wires will travel under ground via existing drainage, in their own conduit for water protection. The RPi will also be acting as a WiFi access point, running a web server to transmit the lap times to anyone near by via a web app and REST API.

Questions:
  • Would I need to drop the 3.3V down to 3V for the PIR, or is .3V negligible?
  • Will a 2-3 metre gap between the RPi and PIR cause an issue?
  • Does it matter which GPIO pin is used? The PIR output current is listed at 100 micro amps at .5V less the input voltage (assuming I RTFM correctly:)
  • What's the simplest way of interfacing with the PIR output signal?
Thanks for any help, I'm a software developer by trade, so just need to get the hardware side sorted and should be able to figure out the rest.

cheers, si

si618
Posts: 7
Joined: Tue Jul 09, 2013 4:09 am

Re: Sensor for bike lap timer

Tue Jul 09, 2013 7:03 am

Of course just after posting I found a nice tutorial on Adafruit :)

The only issue I can see is that PIR sensor as a 120º spread, whereas I'm probably looking for something more narrow, but that could be reduced by enclosing in a tube or similar.

PiGraham
Posts: 3939
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Sensor for bike lap timer

Tue Jul 09, 2013 7:16 am

I don't think PIR is the right sensing technology for this. If you want accurate timing you should use a through-beam sensor that triggers on the wheel. The PIR will only register the rider, and not very precisely. Check what the response time is.

Sensors for automatic gates may work for you, but may miss a narrow wheel rim.

You may need to use a laser to get precise sensing. There are various light detectors available and it could be as simple as shining a laser into a tube with a photodiode at the end.

Ambient light and shadows could be an issue. Some optical sensors modulate the beam and detect the modulation rather than the level. If you drive the laser under Pi control and sense the photodiode level (via an ADC) with the Pi you could detect the change due to the laser on and ignore background variations.

PiGraham
Posts: 3939
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Sensor for bike lap timer

Tue Jul 09, 2013 7:17 am

Is this for only one bike? If several riders are lapping at the same time things get interesting.

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Sensor for bike lap timer

Tue Jul 09, 2013 7:20 am

I'm not sure an IR motion detector will react to a cyclist speeding past. You'll need to test that out.

Other possibilities (among many I'm sure) are a pressure sensor on the track or interrupting a light beam.

si618
Posts: 7
Joined: Tue Jul 09, 2013 4:09 am

Re: Sensor for bike lap timer

Tue Jul 09, 2013 11:21 am

PiGraham wrote:I don't think PIR is the right sensing technology for this. If you want accurate timing you should use a through-beam sensor that triggers on the wheel. The PIR will only register the rider, and not very precisely. Check what the response time is.
Ahh, good point, I dug through the specs and the slight motion detection type responds to a movement speed of 0.3 to 1.0 m/s. A bike at speed is going be faster than that, so that rules out the PIR.
You may need to use a laser to get precise sensing. There are various light detectors available and it could be as simple as shining a laser into a tube with a photodiode at the end.
I'm not after a really high degree of accuracy, anything within say .01 of a second would be plenty. The thing I'm not keen on with a laser is that the pump track is for kids as well as adults, so I wouldn't want to risk eye damage from a curious child. A friend mentioned that a focused LED of sufficient power might make for a replacement laser?

I'm also wondering about an ultrasonic range finder? The specs say it takes a reading every 50ms which might be enough.
Is this for only one bike? If several riders are lapping at the same time things get interesting.
At this stage yes, only one bike on the track. For multiple bikes the best bet is probably to attach an RFID tag (or similar) to each bike and have a reader keeping tabs, but I wanted to keep it as simple as possible for the first iteration.

si618
Posts: 7
Joined: Tue Jul 09, 2013 4:09 am

Re: Sensor for bike lap timer

Tue Jul 09, 2013 11:35 am

joan wrote:I'm not sure an IR motion detector will react to a cyclist speeding past. You'll need to test that out.

Other possibilities (among many I'm sure) are a pressure sensor on the track or interrupting a light beam.
I did consider a pressure sensor, but a pump track is made up of rollers (like a sine wave), and once you get up to a decent speed, it's possible to jump parts of the track, so you couldn't rely on a single position.

It looks like the light beam with a sensor detecting a break is the way to go, so I'll investigate that further. The light beam may also run into problems with jumping, just needs testing.

What about an IR LED in the middle of the track, pointing at an IR sensor on the outside, which is looking for a break in the beam?

Thanks for the input Joan and Graham, appreciated!

PiGraham
Posts: 3939
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Sensor for bike lap timer

Tue Jul 09, 2013 12:03 pm

The IR gate trigger I linked might do the job. It will certainly work of you are content to trigger on the rider.
It uses LED IR light source.

It has a relay output, which will slow the response a bit, but you could probably pick up the relay drive signal to bypass that.

It's cheap and modulated and has IR filters and lenses built-in.

I tried one as a trigger to my DSLR and it worked over >5m in a sunny garden.

si618
Posts: 7
Joined: Tue Jul 09, 2013 4:09 am

Re: Sensor for bike lap timer

Mon Jul 22, 2013 3:22 am

Hello again,

I ended up buying an active infra-red sensor similar to PiGraham's suggestion, and although the manual translation from Chinese to English was more humorous than helpful, it appears to be working well.

When I measure the voltage on the comms line which linked the two sensors (called master and slave) it was reading 4.54 volts, and when the sensor was triggered it dropped slightly down to 4.53. I stuck a few resistors (100k->200k->300k) in series on another cable coming out of the master comms and it read ~2.7 volts with 0.01 drop when triggered, which should be well within the GPIO 3.3v comfort zone.

Before I start experimenting to see if this is good enough for the GPIO to trigger a falling event, is there anything I should watch out for? I already broke one RPi when the small piece of the plastic holding the SD card in place broke (butterfingers!), so I might hook it up to that Pi first and make sure no smoke escapes :)

If it matters, at the moment the sensor and pi are powered separately, with the sensor running off an unregulated 12v supply (which puts out ~18v without any load and ~16v when I read it on the master sensor) although both will be running off the same 5v battery when the 5v to 12v converter arrives.

Final thing I'm not sure about is I'm assuming the comms line to the GPIO will need a ground, so is it safe to use the ground from the 12v source? That's the one I was using to read the voltage on the multimeter, so I'm assuming it is, but not sure.

Master (T0) >> resistors >> GPIO port
Master (-) >> to GPIO ground

cheers, si

timpea
Posts: 1
Joined: Sat Aug 24, 2013 8:04 pm

Re: Sensor for bike lap timer

Sat Aug 24, 2013 8:08 pm

Hi Si,

Did you get any further with this? Would love to do something very similar.

Cheers,
Tim

si618
Posts: 7
Joined: Tue Jul 09, 2013 4:09 am

Re: Sensor for bike lap timer

Sun Aug 25, 2013 10:55 am

Hi Tim,

Yes, hardware for the prototype is working well, I ended up subverting an LED on the master IR sensor to act as the GPIO trigger event. Here's a photo of the set up, the PV panel is hidden under the rpi and batteries, and it's hooked up via ethernet instead wifi as my adapter died and still waiting on a new one to arrive:

Now I'm just trying to get the software written and tested. All the code is open source and can be found along with the hardware used here.

I'm teaching myself python and experimenting with some newish technologies like websockets, so the code is pretty unstable with lots of refactoring going on, but give it another month or two and it should be usable. Trying to keep the design as simple as possible, but also allowing for alternative set ups like multiple track sections (split times), and different start and finish areas in the future.

kmpoppe
Posts: 1
Joined: Tue Jan 07, 2014 6:55 am

Re: Sensor for bike lap timer

Tue Jan 07, 2014 7:00 am

Hi Si,

i am very interested in your solution as i am planning on using a photo resistor led to detect a power-meter led flash. I am a bit lost since i don't quite know how to get in Information of the resistor into the PiB (GPIO i assume would be great) and have an IRQ triggered or whatever to detect the time the led flash was detected.

Could you Elaborate your photo with some schematics as to what you connected where and how you set up the Pi to do what you expect (or is this in the Python code?)

Thanks!

Regards

Kai

si618
Posts: 7
Joined: Tue Jul 09, 2013 4:09 am

Re: Sensor for bike lap timer

Wed Jan 08, 2014 12:04 am

Hey Kai,

Sorry, I don't have any schematics available, but the two things I needed to get GPIO working were using a common ground between the PI and the LED sensor, and ensuring the resistance between the LED and the GPIO was within an acceptable range. Initially I had too much resistance and didn't share +0V, and it wasn't triggering.

I've been too busy riding our bike track and riding in general to finish off the code (waiting for winter:), but you can find the GPIO code here. It only logs the sensor event, rather than triggering an action, but enough to show that it works.

Hope that helps, si.

Return to “Automation, sensing and robotics”