Skip to main content
emobility.academy
B.Tech / BECharging & energyIntermediate About 5 weeksKit only

Remaining Range Estimator from SOC and Recent Consumption

Build a remaining-range estimator that combines the cell's state of charge with recent energy consumption to predict how far the vehicle can still go. Speed is emulated with the potentiometer and the estimate is shown live on the 16×2 LCD.

Uses: ADC · GPIO

The problem

Riders trust an EV less when the range figure jumps about or runs out sooner than shown. Range depends on how much usable energy is left and on how much energy each kilometre is costing right now, which changes with speed, load and driving style. A good estimator balances a responsive reading against a stable one.

Objectives

  • Estimate state of charge and remaining usable energy of the kit cell
  • Estimate discharge power from measured cell voltage and the known load resistances
  • Compute recent consumption in Wh/km using emulated speed and a moving-average filter
  • Display remaining range and compare several filter choices for stability and accuracy

What you need

From the EV Embedded Development Kit

  • Second STM32F103C8T6 as the Smart BMS unit
  • STM32F103C8T6 microcontroller unit (main controller)
  • 1S battery with connector and T-sense input
  • Load section: three switchable resistive loads with LEDs
  • Charge/discharge control relay
  • Analog potentiometer input
  • 16×2 LCD
  • Serial UART interface

Software

  • STM32CubeIDE with HAL drivers
  • Embedded C
  • Python with pandas and matplotlib

Extra parts

None. Everything this project needs is on the kit.

This project uses the kit's lithium cell. Respect polarity, never short the terminals, and don't leave the cell charging unattended.

Key concepts

Usable energy
The energy the cell can still deliver before reaching its cut-off voltage, roughly remaining capacity multiplied by average voltage. It is less than the label capacity suggests at higher load.
Current from known resistance
With no current sensor on the kit, discharge current is estimated as cell voltage divided by the total switched-in load resistance, measured beforehand. Resistor tolerance, wiring and relay contact resistance set the error.
Wh/km
Energy used per kilometre. Range is remaining energy divided by Wh/km, so the consumption estimate drives how the range reading behaves.
Exponentially weighted moving average
A filter that gives recent samples more weight than older ones with one tuning factor, cheap to compute on a microcontroller.

Step-by-step guide

  1. 1

    Scope the estimator and scaling

    Write down how the kit maps to a vehicle. The cell is tiny, so define a scaling factor that turns kit energy into vehicle energy, for example by treating the cell as one of many in a pack, and keep it in one constant. Emulated speed from the potentiometer gives distance. Decide what the display shows: remaining range in km, SOC per cent and recent Wh/km. Review cell safety: check polarity, never short the terminals and never leave a charge unattended.

    Checkpoint: A short design note lists the scaling factor, the speed range and the display format.

  2. 2

    Measure the load resistances

    With the cell disconnected, measure each of the three load resistors with a multimeter, including the path through the relay if possible, and record the values. Calculate the combined resistance for each load combination. These values replace a current sensor, so note their tolerance and the expected error in current: a 5 per cent resistor gives roughly 5 per cent error in current and power.

    Checkpoint: A table of measured resistances and combined values for all seven non-zero load combinations.

  3. 3

    Board setup

    Enable the DIP switches for the battery, loads, relay, potentiometer, LCD and UART blocks. On the BMS unit configure the ADC with DMA for cell voltage and temperature at 10 Hz, GPIOs for the three loads and the relay, and a UART to the main controller as shown on the kit schematic. On the main controller configure ADC for the potentiometer, the LCD in 4-bit mode and a UART for logging. Set both controllers to 72 MHz.

    Checkpoint: Cell voltage, load state and potentiometer value appear together on the UART log.

  4. 4

    Calibrate voltage and estimate power

    Calibrate the cell voltage reading against a multimeter at two points. Compute current as voltage over load resistance and power as voltage squared over resistance for the active load combination. Use integer microvolts and microamps, or Q-format, because the controller has no FPU. Integrate power over time into milliwatt-hours. Check the integrator by switching on a fixed load for a measured time and comparing the result with a hand calculation of V²/R × t using the average voltage.

    Checkpoint: With one load on, computed current agrees with a multimeter in series within the expected tolerance.

  5. 5

    SOC and remaining energy

    Build an OCV-to-SOC table by recording resting voltage at several points during a slow discharge, or use the cell datasheet curve. At start-up, take SOC from resting voltage; during use, track it by subtracting estimated charge. Remaining energy is remaining charge times an average voltage for the remaining SOC range, multiplied by the vehicle scaling factor. Correct SOC to the resting-voltage value whenever the cell has rested long enough with no load, so errors from estimated current do not accumulate.

    Checkpoint: Remaining energy at full charge is close to capacity times nominal voltage, scaled, and falls steadily under load.

  6. 6

    Emulated speed and distance

    Map the potentiometer to 0–60 km/h and integrate speed to get distance. Link load to speed so the setup behaves like a vehicle: for example, low speed switches in one load, medium speed two and high speed three. Make the mapping a table so it can be changed. State in the report that speed is emulated. Add a small dead zone near zero on the potentiometer so the vehicle can be held stationary for the standstill tests.

    Checkpoint: Turning the potentiometer changes displayed speed, distance accumulates, and the load LEDs change at the set speed bands.

  7. 7

    Consumption filters and range

    Compute Wh/km over each 100 m of emulated distance. Implement three options: lifetime average, a fixed window of the last few kilometres and an EWMA with a tunable factor. Range equals remaining energy divided by filtered Wh/km, with a minimum consumption floor so the estimate does not explode when stopped. Freeze consumption updates below a low-speed threshold. Clamp the displayed range to a sensible maximum so the reading stays believable.

    Checkpoint: All three range estimates are logged together and none jumps to an unrealistic value at standstill.

  8. 8

    Display and logging

    Show range, SOC and Wh/km on the LCD, updating twice a second, and add a key or button to switch between filter options. Stream speed, power, energy, SOC, Wh/km and all range estimates over UART once a second. Write a Python script that reads the log and plots the estimates over a drive. Mark load changes and filter switches in the log so they can be lined up with changes in the range estimate when you analyse the plots.

    Checkpoint: A logged drive plots cleanly with all estimates visible.

  9. 9

    Drive-cycle tests and evaluation

    Define three repeatable speed profiles, for example steady, stop-and-go and steady then fast, and drive each to the cut-off voltage. After each run, compute the true distance achieved and compare it with the range predicted at 80, 50 and 20 per cent SOC. Score each filter on prediction error and on how much the reading jumped. Recharge to the same starting voltage before each run so results are comparable.

    Checkpoint: A table gives prediction error and maximum jump for each filter and each profile.

  10. 10

    Report

    Document the scaling, the current estimation method and its error, the SOC method, the filters and the results. Recommend one filter with reasons and explain which error source dominates. Include photographs of the setup and plots of each run. Add a short section on what would change on a real vehicle: a measured pack current, real wheel speed, a larger pack with cell balancing and temperature effects on capacity, and how each would affect the estimator design you chose.

    Checkpoint: The report is complete with tables, plots and a stated recommendation.

Testing & validation

  • Estimated current against a series multimeter for each load combination
  • Range prediction error at several SOC points against distance actually achieved
  • Stability score: largest step change of the displayed range during each run
  • Behaviour at standstill and at low speed with the consumption floor

Expected results

A working range display driven by SOC and filtered consumption, with logged runs and a comparison of three filters showing which gives the best balance of accuracy and stability.

Take it further

  • Add grade correction from the BMP280 to separate terrain from driving style
  • Replace load-resistance current estimates with an INA219 add-on and quantify the improvement
  • Send range and SOC to the cluster as CAN frames
  • Predict range for a planned speed instead of recent history

Viva and review questions

How do you know the current without a sensor?

We measured the load resistances beforehand and compute current as cell voltage divided by the active resistance. Its error is set mainly by resistor tolerance and wiring resistance.

Why does range need a filter on consumption?

Instant consumption swings with every speed change, so range computed from it would jump. Filtering trades a little responsiveness for a stable, believable reading.

What happens when the vehicle stops?

Consumption updates are frozen below a speed threshold and a minimum Wh/km floor is applied, so the range does not shoot up or divide by zero.

Related EV projects

All 100 EV projects