Introduction: 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 2 new versions of the app to a later step. They haven't been thoroughly tested but you can give them 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
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
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
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
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
These are updated versions 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.
The "app-settings-debug.apk" version has a settings menu to allow to set the capacity of your battery so that the percentage remaining calculation is correct. It has not been completely tested.