Bicycle Distance Sensor

Introduction

A student recently came to us with a project that would make use of Dr Ian Walker’s bicycle overtaking sensor, so I agreed to make him one. Since Dr Walker published his original article, the code has had to change a bit, so I thought this would be a good opportunity to post the updated code and include a complete bill of materials.

Bill of Materials

Code for Arduino

You’ll need a USB cable to program the Arduino. I have made some modifications to Dr Walker’s original code. They address four points:

  1. The RTC (real-time-clock) used in the latest revision of the Datalogging Arduino Shield has changed. This addresses the changes needed.
  2. There is a new library available for the Maxbotix distance sensors which is a far more elegant than the old alternatives. 
  3. I’ve decided to use the internal pull-up resistor on the button input, rather than an external pull-down. It saves on the wiring!
  4. I’ve added a serial output for checking the unit is working correctly.

The revised code is available here. Remember that the first time you use the RTC, you need to program it – instructions can be found here

Building the Unit

It should be pretty obvious how this all goes together from the photographs, code and wiring diagrams, but a few hints:

  • The handlebar button fits in the printed enclosure, and the cable can be secured with a cable tie to stop it pulling on the button connections. A tiny dab of super-glue holds the button in place.
  • The Arduino and shield can be secured using the base plate that comes with all Genuino’s using the self-tapping screws, and the base plate secured in the enclosure using the sticky fixers. 
  • I secured the Maxbotix sensor to the enclosure by screwing two standoffs to it, and gluing the standoffs to the inside of the enclosure. 
  • I thought it easier to connect the power button using crimp connectors. This allowed me to easily fit the button to the enclosure. The battery holders are held down with sticky fixers. 
The Fritzing file for this diagram is available here
The unit, showing the inside of the enclosure and the handlebar mounted control unit.
The unit, showing the inside of the enclosure and the handlebar mounted control unit (bottom right).

Conclusions

I’ll update this section in due course when we have the results of the research conducted with this sensor!