# EBike Power Meter

145

2

I recently converted a mountain bike to an electric bike. The conversion went relatively smoothly, so upon completing the project, I hopped on and set out for a shakedown cruise. I kept my eye on the battery charge indicator, not knowing how far to expect the bike to run on battery power. About the time that the power meter showed 80% with me feeling pretty good, because I had gone a long ways, I ground to a halt with a dead battery. An unhappy call to the manufacturer resulted in words like “Oh, the battery indicator really isn’t good for much – the technology just isn’t there yet”. I needed better than that.

I wanted to know which gear gave me the best efficiency, how much was the headwind costing in battery capacity, what power level delivers the most miles, does it really help to pedal, if so, how much? In short, I wanted to know if my battery would get me home. Kinda crucial, doncha think?

This project is a result of my long pedal-powered ride home. Basically this small module sits between the battery and the e-bike power supply input to monitor battery current and voltage. Additionally, a wheel speed sensor provides speed information. With this set of sensor data, the following values are calculated and displayed:

• Instantaneous efficiency – measured in kilometers per AmpHour of battery consumption
• Average efficiency – since this trip started, km/AH
• Total number of AmpHours used since last charge
• Battery current
• Battery Voltage

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Important Data

The instantaneous efficiency addresses all of my questions about how to minimize my battery consumption. I can see the effect of pedaling harder, adding more e-power, changing gears or battling a headwind. The average efficiency for the current trip (since power-on) can help me gauge the approximate power it will take to return home.

The total number of AmpHours used since last charge figure is crucial to getting home. I know my battery is (supposed to be) 10 AH, so all I have to do is mentally subtract the displayed figure from 10 to know my remaining capacity. (I did not do this in software to show AH remaining so that the system will work with any size battery and I don’t really believe my battery is 10 AH.)

The battery current consumption is interesting as it can show how hard the motor is working. Sometimes a short steep climb or sandy stretch can quickly diminish the battery. You will discover that sometimes it is better to get off and push your bike up a steep grade than to reach for that tempting throttle lever.

The battery voltage is a backup indicator of battery state. My 14 cell battery will be almost completely depleted when the voltage reaches 44 Volts. Below 42 Volts, I risk damage to the cells.

Also shown is a picture of my display mounted under the standard Bafang C961 display that comes with the BBSHD motor system. Note that the C961 is happily reassuring me that I have a full battery while, in fact, the battery has been depleted by 41% (4.1 AH from a 10 AH battery).

## Step 2: Block Diagram and Schematic

A block diagram of the system shows that the eBike Power Meter can be used with any battery / eBike power system. The addition of a standard bicycle speed sensor is required.

A more detailed block diagram illustrates the key circuit blocks that comprise the eBike Power Meter. The 2x16 character 1602 LCD has a PCF8574 I2C interface board attached.

The circuit is very straightforward. Most resistors and capacitors are 0805 for ease of handling and soldering. The DC-DC buck converter must be chosen to withstand the 60 Volt battery output. The output of 6.5 Volts is chosen to exceed the dropout voltage of the onboard 5 Volt regulator on the Arduino Pro Micro. The LMV321 has rail to rail output. The gain of the current sensor circuit (16.7) is chosen such that 30 Amps through the .01 Ohm current sense resistor will output 5 Volts. The current sense resistor should be rated for a maximum of 9 Watts at 30 Amps, however, thinking I would not use that much power (1.5 kilowatts), I chose a 2 Watt resistor which is rated for about 14 Amps (750 Watt motor power).

## Step 3: PCB

The pcb layout was done to minimize the size of the project. The DC-DC switching supply is on the topside of the board. The analog current amplifier is on the bottom. After assembly, the completed board will plug into the Arduino Pro Micro with five (RAW, VCC, GND, A2, A3) solid leads clipped from through hole resistors. The magnetic wheel sensor is connected directly to the Arduino pin "7" (labeled thus) and ground. Solder a short pigtail and 2 pin connector to connect to the speed sensor. Add another pigtail to a 4 pin connector for the LCD.

The LCD and I2C interface board are mounted in the plastic enclosure and attached to the handlebar (I used hot melt glue).

The board is available from OshPark.com - actually you get 3 boards for less than \$4 including shipping. These guys are the greatest! https://oshpark.com/shared_projects/bYrMoHIu

Brief sidenotes - I used DipTrace for schematic capture and layout. Several years ago I tried all of the freeware schematic capture / PCB layout packages available and settled on DipTrace. Last year I did a similar survey and concluded that, for me, DipTrace was, hands down, the winner.

Secondly, the mounting orientation of the wheel sensor is important. The axis of the sensor must be perpendicular to the path of the magnet as it passes by the sensor, otherwise you will get a double pulse. An alternative is to mount the sensor so that the end points towards the magnet.

Lastly, being a mechanical switch, the sensor rings for over 100 uS.

## Step 4: Software

The project uses an Arduino Pro Micro with an ATmega32U4 processor. This microcontroller has a few more resources than the more common Arduino ATmega328P processor. The Arduino IDE (Integrated Development System) must be installed. Set the IDE for TOOLS | BOARD | LEONARDO. If you are unfamiliar with the Arduino environment, please don't let that discourage you. The engineers at Arduino and the worldwide family of contributors have created a truly easy-to-use microcontroller development system. A vast amount of pre-tested code is available to speed any project. This project uses several libraries written by contributors; EEPROM access, I2C communications and LCD control and printing.

You probably will have to edit the code to change, for example, the wheel diameter. Jump in!

The code is relatively straightforward, but not simple. It will probably take awhile to understand my approach. The wheel sensor is interrupt driven. The wheel sensor debouncer uses another interrupt from a timer. A third periodic interrupt forms the basis for a task scheduler.

Bench testing is easy. I used a 24 Volt power supply and a signal generator to simulate the speed sensor.

The code includes a critical low battery warning (blinking display), descriptive comments and generous debugging reports.

## Step 5: Wrapping It All Up

The pad labeled "MTR" goes to the positive connection to the motor control circuitry. The pad labeled "BAT" goes to the positive side of the battery. Return leads are common and on the opposite side of the PWB.

After everything has been tested, enclose the assembly in shrinkwrap and install between the battery and your motor controller.

Note that the USB connector on the Arduino Pro Micro remains accessible. That connector is quite fragile, consequently I reinforced it with a generous application of hot melt glue.

If you decide to build it, get in touch for latest software.

As a final comment it is unfortunate that the communication protocol between the Bafang motor controller and the the display console is not available because the controller "knows" all of the data that this hardware circuit collects. Given the protocol, the project would be much simpler and cleaner.

## Step 6: Sources

DipTrace Files - you will have to download and install the freeware version of DipTrace then import the schematic and layout from the .asc files. The Gerber files are included in a separate folder - https://diptrace.com/download/download-diptrace/#D...

Arduino - Download and install the appropriate version of the IDE - https://www.arduino.cc/en/main/software

Enclosure, "DIY Plastic Electronics Project Box Enclosure Case 3.34"L x 1.96"W x 0.83"H" - https://www.aliexpress.com/item/32816551130.html?s...

I2C interface - https://www.aliexpress.com/item/32404454240.html?s...

Arduino Pro Micro - https://www.aliexpress.com/item/32785518952.html?s...