Soon after I got my Ancheer 26-inch folding electric bicycle, I built a data logger that directly measures battery voltage and current, and calculates wattage. It also records calculated energy consumption in terms of ampere-hours and watt-hours. It records this data on a microSD card every second. The datafile can be opened in a spreadsheet application like Excel to analyze and graph the data.
After taking some nice rides on local bike paths and some farther away thanks to the folding feature, I started to develop an Arduino-based logger to record the main electrical parameters. I prototyped the hardware using Dupont jumpers to connect the components temporarily housed in a dollar store kitchen container. This worked well on several rides so the next step was to build it on a stripboard and put it in a real project enclosure. The project has gone through several evolutionary improvements and is now well developed.
The project is based on an ESP32 dev kit, specifically the TTGO T8 V1.7 with onboard LiPo charger and microSD card socket. Other ESP32 boards could be used but few are available with the integrated microSD socket. Stand-alone sockets are available that can easily be connected to the ESP32.
E-bike battery current is measured with an ACS712 Hall-effect sensor rated at 20 amperes. Battery voltage is measured with one of the built-in analog to digital converters provided in the ESP32 and scaled with a simple voltage divider. Measured and calculated values are displayed on an LCD1602 backlit display and simultaneously logged to the SD card. At the end of your ride, you remove the card and plug it into a PC to read the comma-separated value (CVS) data. Future development will do the logging on a smartphone allowing the data to be combined with GPS tracking and video recording.
The data is timestamped with two numbers. One number is simply the time in seconds since the start of the log. The other number is the year, month, date, hour, minute, and second obtained from a network time protocol (NTP) source provided Wi-Fi is available when you turn the device on.
A key component is the dc-dc switch-mode converter that supplies 5 V from the e-bike battery. It is difficult to find one that will accept an input voltage of greater than the 42 volts of the open-circuit 36-V battery. I used one rated at 10-Amps that is overkill for the 300 mA needed by the ESP32 but provides plenty of power for a cell phone charger port. There are now sealed modules made for automotive applications that are small and less expensive.
The code and schematic for the project are on GitHub at https://github.com/W4KRL/EBikeLogger.
Here are some important details:
The software is written in the Arduino dialect of C++. You may install the latest version of the Arduino IDE from https://www.arduino.cc/en/Main/Software. Select the correct version for your computer. Do not use the Web version.
Install the ESP32 core with the instructions at https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/
Add these libraries using the Arduino IDE:
- LiquidCrystal_I2C by Frank de Branbander https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
- ezTime by Rop Gonggrijp – https://github.com/ropg/ezTime
Add your WiFi SSID and password at the places indicated (approximately lines 40 and 41). Add your timezone using the Olson format at line 42. Use this reference https://gist.github.com/ykessler/3349954
Save the file and upload it to the ESP32.
- TTGO T8 V1.7 WiFi Bluetooth module with ESP32 with 16MB flash – See Aliexpress.com, http://tindie.com. You can use any ESP32 devkit with the addition of an SD card reader module.
- 50V (or higher) to 5V Buck (Step-down) converter 1Amp or higher. Search Aliexpress for “Supply power converter DC DC Module 50V to 5V”. The ones made for automobiles should work well.
- LCD 1602 display with I2C interface
- ACS712-20A – 20-amp version
- 120 k-ohm resistor
- 39 k-ohm resistor
- 10 k-ohm resistor
- Deans Connector male
- Deans connector female
- USB Type-A connector. I used a socket taken from a dollar store phone charger.
- Single Pole, Double Throw (SPDT) switch
- Connectors and terminals as needed. Use #18 AWG wire or larger for the power circuit.
- Perf-board prototype board
- Project enclosure
- Micro SD card 1GB