We began this project with the goal of making biking safer. Bikers face many dangers on the road. For example, unless there is a bike lane, bikers must share roads with vehicles that are much bigger and often driven by distracted drivers increasing the risk of deadly collisions. Bikers must also adhere to the rules of the road, including speed limits, to make sure they are safe and do not cause any traffic disruptions. Our project is built around these safety concerns. We want bikes to be more visible, preventing collisions. And by providing feedback to riders, they can maintain a safe speed.
We used an Adafruit HUZZAH32 to control our system and code in C++ through the Arduino interface. The first piece of our system is LED headlights that turn on when it is dark outside. We attached a photoresistor to an analog read pin to detect changes in outside light. When the light is below a certain brightness a pair of LEDs illuminates.
We display the speed of the bike on a backlit LCD display. The LCD update code and the light detection code are in the main loop and run continuously. To help with displaying information on the LCD, we used the Arduino LiquidCrystal library.
Image: Soldering the LED headlights together.
To detect the speed of the bike, our board is connected to a reed switch which is mounted on the front wheel’s tire fork. The switch’s trigger is mounted to the wheel and closes the circuit when the tire makes a full rotation, then it triggers an interrupt.
We began to configure the reed switch by following amandaghassaei’s steps in her Instructables guide (see resources). Her project uses an Arduino Uno, so we could not use her code directly, but we set up code to figure out when the reed switch was opened or closed.
Image: Adafruit HUZZAH32
To calculate the MPH, we started with amandaghassaei’s strategy which uses a timer to check if the tire has made a complete rotation 1,000 times every second and then calculates speed using the time it took. Constantly using a timer interrupt limits our ability to add more peripherals which also use interrupts. Instead, our speedometer figures out how long it takes the wheel to make one rotation by saving the current time when the interrupt fires and then subtracts it from the time of the last called interrupt. Then it divides the distance of the circumference of the bike tire by the travel time.
Other than the LCD, which only displays the current speed, the bike speedometer does not have a user interface! After the device is powered up, it does everything on its own.
Image: Our system not mounted on a bike.
We had difficulty creating an effective way of figuring out when the bike has stopped moving. Our speedometer only does speed calculations when the reed switch is triggered, so if the bike stops, the speedometer is stuck at the last calculated speed, waiting for the next interrupt to update the speed. We solved the problem by forcing the speed to zero if there has not been an interrupt after a certain amount of time.
We also had issues with the LCD. We originally displayed the speed on the bottom line of the display. Every time on startup, it would display 27.68 and then after a few seconds reset to 0. We thought the number was the MPH from the last time the board was on, but it was consistently 27. Also, the code sets the saved MPH to 0 on startup. Our first attempt at fixing the bug was to clear the board after initializing it and at the beginning of each loop. But this made the display hard to read. We decided that working with both lines of the display was causing the issues, so we moved all of the information to the first line. We are not sure why, but this gave us more control over what we were displaying, and we could set the displayed MPH to 0 on startup.
On the hardware side, the reed switch was difficult to rig onto the bike. The switch and the trigger need to be very close to each other in order to get a reading. On the bike we used for the prototype, the tire and the fork are farther than this minimum distance, so the speedometer could not make readings. We used foam and a lot of electrical tape to give the trigger a platform and put it in the range of the switch (see image).
We bought a 3.7V battery pack to power the board. But the display we use needs 5V so the system would not power up. To solve the problem, we power the speedometer with a 5V USB battery pack.
Created with images by Adafruit • Andrew Gook - "Beware of these Streets" • Luke van Zyl - "untitled image" • Luís Sousa - "COUNTERFEITING" • Robert Ruggiero - "Biking in the Snow"