Introduction: Electric Bicycle (EBike) Dashboard and Battery Monitor

Picture of Electric Bicycle (EBike) Dashboard and Battery Monitor

This project is an Arduino circuit that monitors battery voltage and current with an ACS 712 module. The measurements are communicated over Bluetooth with an HC-05 module to an Android device. Basically you rewire the negative connection between your controller and battery to go through the ACS712 module.

The Android app displays the battery status as well as current speed and distance traveled from the Android GPS

The Android can be mounted to the bike in a weatherproof bag. The Arduino circuit is permanently mounted in a weatherproof box on the bike near the battery.

The Android and Arduino code is available on github. ( https://github.com/edj2001/BikeDashArduino and

https://github.com/edj2001/BikeDashAndroid . You'll also need the libraries https://github.com/edj2001/AndroidBluetoothLibrar... and https://github.com/edj2001/libraries).

There are commercial versions of similar products available if this is more than you might be able to handle. You can easily find them by googling "bluetooth 36v watt meter". If you look at some of the pictures, you'll see an Arduino Pro Mini, a DC-DC power supply, and an HC-05 (or -06) module on the back.

If you ever wonder how much battery you have left, or how much further you can go on battery, or if you need to pedal or reduce throttle to get where you're going, this is what you need.

Another potential advantage is that you may decide to remove the bicycle computer from your handlebars, freeing up some space, although now your phone will be mounted on your bike instead.

As always, this information is provided as-is with no warranty of any kind, express or implied. You are responsible for anything that you do with this information. I will not be responsible or liable in any way for any damages whatsoever. See the disclaimers section in the Terms of Service.

Step 1: Instructable Updates

PeterB476 showed me that I had neglected to include a step to initialize the Arduino EPROM, so I have added that to the instructable.

I have also added a newer version of the app to a later step. It hasn't been thoroughly tested but you can give it a try.

Step 2: Install Android App

There is no point proceeding with the rest of this project if the android app doesn't work on your device. The releases from github have the android apk attached. The apk file is also attached here. Make sure that at least the GPS portion of the app works, and you can try to connect to a bluetooth device.

If you want to build the app yourself, I suggest you start with a "release" point because it was probably working at some point, whereas the latest "master" branch may have updates that have not been tested.

Copy the apk file to your device. You will have to allow "Unknown Sources" in the Security settings on your device since the apk did not come from Google Play. Then simply tap the apk file on your device to install it.

Obviously the app requires bluetooth permissions to communicate with the Arduino, and the GPS permissions to determine your speed and distance traveled.

Press the "remote" button to try to connect to a bluetooth device. Press "reset" to reset the distance traveled to 0. Hold the battery Ah used field to reset it after you charge your battery. The Ah used value will be saved if you turn the battery off and on without charging it.

Step 3: Collect Parts

Picture of Collect Parts

Note these parts are for a 36V battery. If you have a 48V battery you will need to change the 10K resistor to 11K or 12 K, and you will need a different DC-DC converter.

1 Weatherproof enclosure. I used a 4x4x2 inch PVC electrical box.

1 piece of Your favourite Stripboard or Protoboard

1 Arduino Pro Mini, 5V 16 MHZ. You could also easily build a bareboard arduino since you don't need a voltage regulator or usb interface. All you need is the ATMEGA328P, a 16MHZ crystal and a few capacitors. You could also use an Arduino Nano if you have room in your enclosure. The Nano is larger than the first two choices, but has the built in USB interface if you don't have a serial converter.

1 ACS712 module to match the current range of your battery. I used a 20A module for my 8A battery.

1 HC-05 bluetooth module. I like the ZS-040 variety, the 6 pin kind with the pushbutton. It will be labelled ZS-040 on the back.

1 50V to 5V DC-DC power supply if your bike has a 36V battery, which will be about 42V fully charged. If you have a 48V battery, it will be 56 or 57V fully charged, so you may need a different power supply. Please let us know what you use if you find something for 60V. Some people say that most usb wall warts work on 48VDC (and higher), but I haven't tried it.

1/4W Resistors: 1 x 2K, 1 x 10K, 2 x 1K (increase the 10K if your battery is more than 36V).

In-line fuse holder and 2A fuse.

straight and right angle Header Strips

5.08 mm terminal blocks, 2 x 2

16AWG stranded wire for interconnecting the modules.

22AWG solid wire for the arduino circuit

Terminal Block Strip for the battery and bike connections

Soldering iron

solder

A way to mount your android device to your bike.

To program the Arduino and HC-05 module you will also need a 3.3V usb to ttl serial converter (or at least an isp programmer) and the Arduino ide from https://www.arduino.cc/en/Main/Software. This project was done with version 1.6.13, different versions may or may not work without modification.

Step 4: Initialize Arduino EPROM

I neglected to include this step in the original instructable. The area of the EPROM that is used by the sketch needs to be initialized for the sketch to work properly. The sketch could be written to do it automatically, but at this point it doesn't.

If you're not working with the arduino source code, you can download the hex file attached to this step to your arduino to initialize the EPROM.

If you are working with the arduino source code, there are two lines in the setup() section that look like this:

//initialize the EEPROM the first time the program runs. 
//updateEPROM();

If you uncomment the second line so that it looks like this:

//initialize the EEPROM the first time the program runs. 
updateEPROM();

Download that sketch to the arduino and let it run. The EPROM will be initialized. Then recomment the line for the next step.

The EPROM is used to remember how much of the battery has been used so that you can ride your bike, stop and turn off the battery, and when you turn it back on it will start from where you left off.

Step 5: Configure Arduino

Download the Arduino code (hex file attached) to the Pro Mini using either the Arduino IDE or avrdude by itself. Normally you would use the usb to serial converter for this, but you could use an isp programmer as well.

Again, if you want to compile it yourself, start with a "release". The latest "master" branch may have untested changes.

If you changed the 10K resistor to something higher, you will also need to change the battery voltage divider constant in the sketch. Change the 11.0 in the line "double VBmultiplier = 11.0;" to match whatever you installed.

Step 6: Configure HC-05 Module

Picture of Configure HC-05 Module

You need to configure the baud rate on the HC-05 module. It's also nice to give it a name that you can easily recognize later (like "BIKE").

You use the usb to ttl serial converter module for this as well. If you don't have a serial converter you could write a sketch for an arduino to configure it, or I guess if you have 2 HC-05 modules you could hook them together and use one to program the other (maybe).

There is an excellent write-up on this module at http://www.martyncurrey.com/arduino-with-hc-05-bluetooth-module-at-mode/

You need to configure the baud rate to 4800 to match the Arduino sketch, and change the name to "BIKE" or something that you will recognize.

Once the module is configured, you can pair it with your android device in your bluetooth settings.

Step 7: Assemble Circuit

I have attached a scan of my hand-drawn wiring diagram for reference, if somebody is ambitious enough to redraw it nicely, please let me know :)

Make the following connections:

(+) Bike Battery to one side of fuse and bike controller.

Other side of fuse to DC converter (+)IN terminal and 10K resistor for battery voltage input on Arduino.

(-) Bike Battery to (-)IN on converter and one ACS712 power terminal.

At this point make sure that you have 5V from your DC converter when you turn on your battery if you haven't already.

Turn the battery back off and complete the connections:

(+)OUT from converter Arduino 5V, HC05 VCC, ACS712 VCC.

(-)OUT from converter to Arduino GND, HC05 GND, ACS712 GND, Arduino pin A2.

HC05 TXD to Arduino pin 7

HC05 RXD from bluetooth resistor divider.

Arduino pin 8 to bluetooth resistor divider.

ACS712 OUT to Arduino pin A3

Battery Voltage Divider to Arduino pin A1

(-) from Bike Controller to second power terminal on ACS712.

The extra reset button is not really required, it might just be convenient when wanting to download to the arduino after it is installed on your bike. You might be able to reach the reset button on the arduino, or you can reset it from the serial interface if your pro mini supports it.

Double check your connections.

Step 8: Preliminary Verification

At this point you can turn on the circuit and verify that you're getting readings in the android app.

You should be able to connect the bluetooth to the bike and see battery voltage and hopefully close to zero battery current. If you can spin up the bike and see the current reading change, then everything is working.

The app assumes positive current is draining the battery, so if the reading shows a negative current when you spin up the bike just swap the two current wires on the ACS712 module.

If you don't see any readings in the app, you can look at the lights on the bluetooth module to make sure it's connected and transmitting data. You can install a bluetooth terminal app on your device to see the data that is being sent from the circuit. You should see about 10 lines a second of current readings, and one line a second of battery voltage and amount of battery used. If you don't see anything, recheck the configuration of the HC05 module and the connections between the arduino, the resistor divider, and the HC05 TXD terminal.

Finally, run the bike long enough to have a non-zero value displayed in the battery used display. Then long press on that number until the toast appears that usage has been reset. The number should return to zero. If it doesn't after trying a few times, recheck the connections from the HC05 RXD terminal to the Arduino.

Step 9: Final Assembly

Picture of Final Assembly

Install all the mounting hardware and mount the arduino circuit to your bike. Mount your android device in a bag or other holder and you're all set to go!

The pictures show the battery stabs on my bike, and the bag for my android device.

You can see the little board for the battery voltage divider connections and the ACS712 mounted so that I could reach the terminal block screws after mounting everything. The HC-05 bluetooth module is back in the right corner.

The white terminal strip has all the battery and bike controller connections to the circuit.

If I had to do it again I would definitely combine the Battery voltage divider and the ACS712 on the same piece of daughterboard. I might also try to mount the bluetooth module on a daughterboard underneath the arduino.

Step 10: Future Steps

The Android App could use a lot of work. I'd like to add some colour changes based on ranges for the measurements. I'd also like to add indication that a measurement is not updating in the app. You could also add some graphical gauges. Even a nice icon would be a big improvement.

The best feature would be an "estimate to empty" that would tell you the distance you could travel on your remaining battery, and whether that is more than the distance to your destination. Since I normally ride either to work or to home, my thought is to have GPS "waypoints" stored in the app that have the remaining distance to home, and how much battery is used on average at that waypoint. You could probably also do something with a data connection, but I don't normally have one.

I'd like to move away from the bluetooth library in this app to a more developed one that has auto reconnect for example.

If you build this, you may consider adding a hardware low pass filter on the measured current and measuring it separately to use for the total charge used calculation. At low loads, less than 4A or so, the measurement varies widely, +/-1A. I'm not sure if it's just a measurement problem or the current changes that much as the wheel rotates. In any case, a separate measurement of average current over a second or two might help with accuracy. You could just sample the current faster and do it in software, but I don't know how fast you'd have to sample. I guess putting an oscilloscope on the signal might help figure out how fast to sample it.

You could add things like a pitot tube to measure wind speed (there's already an instructable for that).

You could add closed loop throttle control from the arduino.

If you've always wanted a USB power source on your bike, you can easily run a cable from the 5V DC converter for the arduino up to wherever you need the USB power connection.

Step 11: Questions and Comments

If you have general questions about any of the items here, you're best to just google it instead of asking questions here. None of the items are critical, you can almost certainly substitute something else and get the job done.

Don't ask me to send you the code, it's all on github. Get it from there. You don't even need a github account.

Please don't ask me how to do something in Android Studio or on Arduino. I probably don't know. Again, just google it.

Really don't ask me about any Apple products, I haven't a clue.

If the app doesn't work on your device, I'm sorry. But I probably don't know how to fix it so that it does. It works on my phone, that's all I need.

Although suggestions for improvements are welcome, I will probably never implement them, I have other things to move on to. I'll probably never even implement my own suggestions. Your best bet is to fork the code on github and add things yourself. If you do, please do let people know here so they can use your code instead of mine.

If you've already built a better version yourself, please post a reference to it here so others will know about it. I will not be offended. I will be happy to take your version and start using it.

Step 12: App Update for Testing

This is an updated version of the app.

The numbers are much bigger. There's a new icon. There is no "connect" button anymore. Use the "connect - secure" option from the top right corner menu.

This version should also work back to Android version 2.3 gingerbread. It works on my lg P500 Optimus One.

Comments

magallanr1 (author)2017-11-12

I've made my connections but I still only have one connection on the terminal screws of the ACS712. It is from the -bike battery. Should my other connection be from the +bike battery? I only have the +/- battery connections coming from my controller.

edca2001 (author)magallanr12017-11-14

The other terminal of the ACS712 should go to your bike controller, where the -battery would connect. In other words, the ACS712 goes in the connection between the -battery and the bike controller.

You can imagine cutting the existing wire between your -battery and bike controller and putting the ACS712 in the cut. Hopefully you have a screw terminal or something available and don't actually have to cut the wire.

magallanr1 (author)2017-11-11

Hello I am trying this with an Arduino Nano. You have connections for HC05 TXD to Arduino pin 7 (AIn) and Arduino pin 8 (CLK) to bluetooth resistor divider.

Do you know how these would correspond on the Nano? I have the 2 datasheets and am not seeing a correlation.

edca2001 made it! (author)magallanr12017-11-12

I'm not sure where you're seeing the AIn and CLK descriptions. The numbers in my description refer to the arduino "pin" numbers, not the physical pin numbers like an integrated circuit. So pin 7 on the pro mini like shown in the attached picture would be "D7" on the nano shown in the attached picture. (Likewise 8 would correspond to D8.) Don't try to count the pins like an integrated circuit, just go by the pin labels on the arduino module.

magallanr1 (author)2017-11-11

Never mind, I found it.

magallanr1 (author)2017-11-05

Hello, I am implementing this project and have a question as to the "bike controller" connections. In the schematic the battery + terminal is bridged to the + bike controller. Additionally the from Bike Controller to second power terminal on ACS712. What are the + and - of the bike controller? I am using a kit and have taken it apart and am having some trouble indentifying these connections.

edca2001 (author)magallanr12017-11-06

I assume when you start you have your battery (+) and (-) hooked up to your bike controller. The fuse for this project connects to the battery (+) along with the existing bike controller. This is labelled "TO BIKE" in the sketch. The (-) battery gets disconnected from the bike controller. Then the (-) battery goes to one side of the ACS712. The other terminal of the ACS712 goes to the bike controller terminal that had the (-) battery connection. This is labelled "TO BIKE" in the sketch as well.

Maybe post a picture of your setup if this doesn't make sense.

magallanr1 (author)edca20012017-11-07

This is what i'm using. The only connection from this is the one to the right. It is the battery connection (+,-). The other connections are for the motor, trottle, brake. The steps mention the bike controller so I am assuming I have to bridge these connections to something other than the battery. My question is does someone know to what? I think its to the connections to the motor but i'm not sure. Any help is greatly appreciated!

edca2001 (author)magallanr12017-11-07

The only connections for this project are to the two battery wires. You do not need to connect to anything on your bike controller.

magallanr1 (author)edca20012017-11-07

I see, thank you for the response.

IgorM54 (author)2017-10-25

HI, I do this really nice project and I have managed to have a reading from the current sensor (is not connected to the battery yet) but I have no reading from GPS? App has been tested on Moto G 5 Android 7, Moto G 2 Android 5.1 and Samsung A3 Android 6.0.1 and it works without crashes. The project is still on breadboard :). Does anyone have an idea where the problem is? Thank you in advance. Regards.

edca2001 (author)IgorM542017-10-25

Those dashes mean the GPS has not established a location yet. Does it help if you go outside or change location?

You could download a gps tester app and make sure the gps on your android device works in the location that you're testing.

The speed from the gps relies only on the android device, not on the arduino circuit, so you can test them separately.

IgorM54 (author)edca20012017-10-26

HI, thank you for your response. I've managed to have all reading on Moto G 1st gen (Android 5.1) and everything seems fine, but the problem still exists on Moto G5 (Android 7). I've tested my GPS and everything is ok, it works on other apps like Google Maps etc.

IgorM54 (author)IgorM542017-10-26

Update: Now it works GPS. For everyone who has the same problem, this could be a solution. Go in apps on your phone and find the app Bike dash then Permission select Location (must be on) and it works. :) Thanks.

edca2001 (author)IgorM542017-10-26

Thanks for the tip IgorM54.

PeterB476 (author)2017-10-10
Hello, I'm currently setting up your watt meter and I've encountered one problem. As soon as I got my phone connected to hc-05, app crashes. Happens on both my cellphones Moto G 2gen. and Huawei p9 lite. BT terminal shows that data is being transferred. I was wondering if I should do anything else except installing "Bike Dash" app and granting it GPS and BT rights? I will be grateful for any suggestions.
edca2001 (author)PeterB4762017-10-10

That should be all you need to do, is grant the rights that you mentioned.

I assume that if you don't connect the bluetooth that the app runs fine, and shows speed, time, and distance travelled?

What android version are your phones? Mine is a Moto G 1st generation with 5.1 lollipop. Your 2gen must be at least that. What version is the Huawei? It's possible that there is something in newer Android versions that I am not aware of that is causing a crash.

I have two thoughts. First, Is there any way for you to get the logcat from one of the phones when the app crashes? There should be a message in there that might help.

Secondly, I have made a few changes to the app that I haven't posted yet because I haven't been able to test them. If I send you a new apk, would you be willing to test it? Most of the changes were to make it work on android versions back to 2.3 gingerbread, but we might get lucky.

PeterB476 (author)edca20012017-10-10

Hello, thank you for a fast response. I should have specify this at the beginning : p9lite runs 7.0 nougat and Moto G v2: runs 6.0. As for logcat : it seems useless without root permission so I'll root my phone and hopefully I'll get some answers. Interesting thing is that the crash seems coused not by a BT connection itself but because of the data transfer- when I accidentally mixed Rx and TX wires on my hc-05 and no data was transferred (BT terminal showed none) , your app managed to establish connection and kept working ( without displaying any data of course). I will be very happy to test your app, problem is that I can do it only in the evenings (it's UTC+01:00 here). My Arduino is still on the breadboard but I'll get all the connections done on my bike by the weekend. And - pardon my English, it's not my first language :)

edca2001 (author)PeterB4762017-10-11

I have posted an updated version of the app in step 10. Please try it if you can and message me with the results. Thanks.

edca2001 (author)PeterB4762017-10-10

I will post the newer apk tomorrow night (in about 24 hours). Since the first version isn't working anyway, there won't be any harm in trying the new version.

DIY Hacks and How Tos (author)2017-04-22

Cool. Nice well written tutorial.

About This Instructable

4,872views

48favorites

License:

More by edca2001:Lowest Cost Bus Pass CalculatorElectric Bicycle (EBike) Dashboard and Battery Monitor
Add instructable to: