Final Project Update 3/19/19

The automatic 21 speed bike transmission has been completed with all planned features, except one, fully implemented and integrated. The system we created in summary reads the speed of the bike rear wheel and shifts to the appropriate gear for that speed. There are 7 gears to shift from with a minimum speed of 0.0 km/h and a maximum speed setting of 40 km/h. Note that the wheel is being demonstrated and tested without load and free spinning so the upper ranges of wheel speed are more obtainable.

The peripherals used were two PWM controlled servos, one reed switch attached to GPIO, and one laser distance sensor communicating through I2C. The servos each controlled the up shift lever and down shift lever independently to allow us to mechanically interface with the bike transmission. The reed switch was attached to the rear wheel spokes and frame to read the speed via a GPIO interrupt that stopped a timer counter when the switch was activated by the spinning magnet on the wheel. The laser distance sensor checked pedal rotation by sensing the pedal arms passing in front of it to ensure correct gear engagement and user input via pedaling.

Some design challenges we faced were mechanically mounting the devices to the bike, designing for proper bike transmission action, and real time constraints. We used compression locking hardware to mount the servos, reed sensor, and laser sensor with a metal frame constructed to hold the servos next to the shift levers and hold the microcontroller board. The hardware was made sturdy to resist the forces acting on the bike during use. The transmission of the bike requires pedaling to engage the next gear after a gear shift occurred. The laser sensor was employed to sense this while the program flow was carefully designed to accommodate edge cases such as starting from stop, quick speed changes, and gear slippage. The shifting levers overlap in arc so the program had to control the servos without collisions. The real time aspect of our project made calculating timings and ranges fairly challenging as the rate our servos turned at, the speed of the sensors, and overall program performance impacted system integrity. We did our best in software to control program flow with our grand loop to maximize responsiveness as well as tune our settings for the hardware finely. The display proved too problematic and time consuming to include so we scrapped the idea of including a LCD display in our system.

The program is structured as a grand loop that uses flags to initiate actions or block other actions from occurring. Our code utilizes all four timers all with interrupts enabled. GPIO also has an interrupt which in combination with the timers posed a risk to proper system flow. We realized early on that executing our actions in the interrupts caused poor run time and responsiveness as well as undefined behavior at times. We opted to only change flags or data variables in the interrupts to minimize their performance impact and the main grand loop contained blocks of code that activated or deactivated in response to the flags. All of the code is contained in our single main file and we imported only the MCPWM library in addition to the default LPC 4088 library.

Mathematically our program takes in the rotational period of the rear wheel in milliseconds and converts that to a speed reading given the physical dimensions of the wheel. The speed is them used to select the correct corresponding gear which is compared with the current gear setting. Logic then occurs to compare the current and optimal gear to determine shift actions to take. When a shift occurs, the program has a cool-down before the next shift to accommodate for hardware and mechanical limitations. Pedaling is required for shifts so the program also checks for pedaling between shifts and at start from stop cases.

Responsibilities shifted from the originally planned jobs for our three group members. Ultimately Chris Chan implemented the mechanical and electrical integration of the components onto the bike, the reed switch GPIO interface, the PWM servo drivers, and part of the program design. Zachary Battles worked on the overall running program with Chris, implemented the UART output interface, and did the trial testing and math behind the timings. Jacob Zamora along with Zachary implemented the I2C laser sensor drivers. The lab overall took about 200 combined hours. A demonstration video will be also be included.

Update 3/15/19

We have implemented the reed switch and attached it onto the bike. We have also implemented the distance sensor into the code and are working on attaching it to the bicycle. The Servos have been attached to the frame of the bicycle as well and we are working on correctly shifting the gears. Due to time constraints and complexity we have decided to output our data into CoolTerm using UART instead of the LCD device if we have time at the end. Our main focus is properly reading speeds, pedal position and shifting the gears properly.

Update 3/10/19

We have correctly configured the reed switch to GPIO and are able to read the speed of the bike wheel. We are currently working on outputting the data to the LCD through I2C and controlling the servos with PWM. The servos have arrived and the laser distance sensor for the pedals is currently being implemented. The physics behind calculating the speed is being fine tuned and debouncing for the reed switch is also being implemented. The speedometer component of the project should be complete by the end of next week with the servos as a later goal due to mechanical complexity of the implementation method.

Update 3/1/19

We have gotten all of our parts for our project. This project seems like we were over ambitious and won’t be implementing the actual automatic shifter, so we are taking the servos out of the project. However, we will be implementing an LCD display of current speed the bike is traveling based on the rotation of the back wheel. For all of our current devices we have set up the basic foundation code and will work on implementation this following week.

Project Proposal

21 Speed Bike Automatic Transmission Control

153B Final Project Proposal

Chris Chan, Zachary Battles, and Jacob Zamora


We plan to create an automatic control system for the gear shifters on a 21 speed bicycle. The device would interface with a standard bike with varying speed gears by controlling the shifter cables that run from the bike’s chain derailleur while reading the speed of the wheels and position of the pedals. The goal would be to create a real time control system that would use the data gathered from the speed and pedal position in order to select the right gear ratio for the current speed. There will be a servo attached to the control end of the shifter cable at the handle bars and a tachometer reading the speed of the rear wheel attached to the main frame of the bike. There will also be a distance sensor reading the position of the pedals to guarantee engagement of the current gear before indexing the next gear in rapid gear change situations such as starting and stopping on a bike. The microcontroller and power source for our peripherals will be stored in the storage basket attached to the handle bars of the bicycle. The system will also prompt the user with three LED notifications for upshifting, downshifting, and user pedal to engage chain.


  • Servo with positional encoding
  • Tachometer
  • Distance Sensor
  • LEDs x 3
  • Accelerometer (Optional)

Software Design

We plan to implement our system with grand loop and finite state machine. The software will continually check at constant intervals, the speed of the bike, the current gear setting, and pedal position. The program will determine if the current speed is either above or below the programmed gear setting and will either initiate a downshift or upshift to get to an appropriate setting. When either shifting case occurs the servo will index the gear number up or down while the user is notified with a LED notification of which type of shift is occurring and to pedal to engage the chain with the new gear. The challenges that will accompany this project will be interfacing with the peripherals, getting the correct speed to gear number ratios and timing of the whole system.


  1. The primary goal of this project is to provide accurate and fast shifting automatically by implementing the servo, tachometer, and distance sensor to work as feedback based control system.
  2. The secondary goal of this project will be to provide a simple LED user interface to keep the rider of the bike informed on the actions and state of the bike during use.
  3. The optional goal of this project will be to include an accelerometer as a sensor in the system in order to improve responsiveness and predict successive shifts for rapid changes in speed. This would utilize an interrupt that would override the state machine in stopping and starting cases.

Group Responsibilities

  • Chris will be in charge of the finite state machine/grand loop, and tachometer implementation.
  • Zachary will oversee the implementation of the LCD display with the micro controller.
  • Jacob will manage the interface between the distance sensor with the microcontroller.