Arduino Code

regenerative_bike_brake_prot_2_5
The following is a prototype program for a device used on a bicycle with a generator for a brake.  Essentially this is a regenerative brake for a bicycle which charges a USB battery (one of the new mobile charger batteries).  Thus, when you’re braking, you can charge this mobile battery up full which can charge an iPhone (or anything that charges USB, it’s capacity is that of about two full iPhone charges when at full charge).

mobile_usb_battery_pack

Because we want to record data about the device’sperformance in real-time, we added an “SD shield”.  This device is another Arduino-looking thing which can write and read from an SD card.

Our device records three analog inputs (the first two are voltages, while the third is a reed switch) and adds a relative time-stamp to a file written to an SD card. Our Arduino has an SD shield. The file will be post-processed during data analysis to find the generator power, bike deceleration, and total bike brake time and distance. This code should keep growing but be finished by March 2014.

sd_shield_for_arduino

I will display images of the code, for color coding reasons, it’s easier to read, and the code itself as a text download:

bike_brake_3_20_2014.rtf

The Code has been updated,  and, as a tool for myself, here’s what could be improved:

1.  Have the filename change based on files present on the SD card already.  – We have to remove the file from the card after each time turning on and using the program.  The program should check what’s on the card, starting with say ‘datalog000’ and counts up until the file name doesn’t exist.

2.  Have two brake lights, red; with each one corresponding to a measurement taken.  Currently, there is only LED Brake Light #1, which is supposed to turn on when the voltage reading is above some small value.  (Once the brake is engaged and starts to spin, a voltage appears.  After testing, we can determine an appropriate threshold voltage to indicate braking.) [editor’s note, it’s not quite working] Brake Light #2 [not currently hooked up] should turn on when a current is detected above some predetermined threshold.      – That way, each brake light LED serves two purposes;  first, to indicate that the brake is engaged, and second, to have an independent indicator for voltage and current in the circuit, which may help to define the system’s behavior or to help troubleshoot.

READ the posts about the designs:
Prototype 2.5
Prototype 3.0