Electronic Shifter for Bicycle
by jbike in Circuits > Electronics
996 Views, 8 Favorites, 0 Comments
Electronic Shifter for Bicycle
The ability to change gears via pushbutton is a feature on high end road bikes. Shimano and Sram have such systems, but they cost over $1000. This project shows that you can DIY a conceptually similar system for less than $50. Of course, this will not be as precise a system, thus I have chosen to convert an older (1970's era) bike. The rear derailleur only has to contend with 6 rear cogs, not 12 like on today's high end road bikes. I use a common RC servo to move the modified derailleur. The servo is attached to the derailleur via a 3D printed bracket. The springs are removed from the derailleur to make it easier for the servo, but this does make the derailleur prone to moving out of gear if a pothole is encountered. Ideally, the servo would use a worm drive to lock the servo position when not powered.
A USB battery bank powers the servo, while a CR2032 coin cell powers the electronics (an ATtiny85). The ATtiny85 uses a deep sleep mode between shifts and when not in use. A pin change interrupt wakes it when a shift button is pressed. In sleep mode, only 0.2 uA is used from both the battery bank and the coin battery. MOSFETs turn on the USB battery bank when a shift is needed. There is a shift table in code for up shifts and down shifts, as the commanded servo position is not the same for the same gear between up and down shifting- shifts are slightly more than the absolute position to get a reliable shift.
This project was based on https://www.instructables.com/DIY-Electronic-Derailleur/ Major differences: 3D printed servo bracket, use of ATtiny85 microcontroller instead of Arduino Pro Mini, sleep mode allows use of USB battery bank (no on/off needed).
Supplies
ATtiny85 microcontroller, 8 pin DIP version (Amazon or Aliexpress)
8 pin DIP socket (Amazon)
CR2032 coin battery holder
CR2032 coin battery
USB Battery Bank
USB male connector (Amazon)
Perfboard for components
2 small perfboard mount pushbuttons
MG996R servo
25T metal servo arm
Servo extension cable
Derailleur (like Shimano Altus A10), needs springs removed
P-MOSFET A03401 surface mount
N-MOSFET A03400 surface mount
Red and Green surface mount LED
2 Schottky surface mount diodes
2 10K surface mount resistors
Wire as appropriate (wire for pushbuttons and circuit connections)
Plastic project box (empty tire patch box)
zip ties
soldering iron
solder
USBTinyISP programmer for Arduino
Programming socket for 8 pin DIP (the ATtiny microcontroller)
Arduino IDE (free programming app for Windows or macOS)
Fusion360 for the .f3d file (3D bracket design file)
Cura slicer
3D printer
Downloads
Gather Parts, and Build
This project requires some familiarity with the Arduino IDE app, and installing the proper libraries. The required libraries are listed at the top of the code sketch; download and install them. Also necessary to install the proper board in board manager (ATTinyCore). Under tools in Arduino IDE, set the Programmer to USBTinyISP. Under Tools:Board select ATTiny 25/45/85 (no Bootloader), then select ATtiny85, BOD disabled, 8 Mhz clock (internal), Programmer USBTinyISP(ATTiny Core) Slow. Plug the Programmer in to the USB port, and the programmer cable in to the programming socket board. An alternative is to use an Arduino UNO configured as a programmer, jumper wires, and a breadboard to program the ATtiny. To program, use the Sketch Tab, then "Upload using programmer".
Install components on the perfboard according to the circuit diagram arranged however you want. It should eventually be able to fit into your project box.
10/7/2024 updated code to eliminate button bounce and improve interrupt handling. Code executes to the end before allowing another button press interrupt to occur.