Smart Battery Guard

Monitor your vehicle's battery and get Home Assistant notifications when its power is getting low.

Smart Battery Guard
Photo by Thomas Kelley / Unsplash
Skill Cost Time
2 / 5 ~7 Euro ~20min

Picture this: your motorcycle has been sitting idle in your garage for a bit, and suddenly, your friends invite you for a ride on a beautiful day. Excited, you gear up, only to discover your battery is dead. Disappointing, isn't it? But fret not! In this guide, we'll walk you through building a Smart Battery Guard using a Wemos D1 mini, a 1M2 Ω resistor, and a DC Power Shield, allowing you to monitor your vehicle's battery and get Home Assistant to notify you when its power is getting low.

Bill of materials

  1. Wemos LOLIN D1 Mini or D1 Mini Pro (with external antenna)
  2. Wemos DC Power Shield
  3. 1M2 Ω or 1M5 Ω resistor
  4. Waterproof Black DIY Housing (69 x 42 x 23mm (L x W x H))

Solution - Hardware

Incorporating a Wemos DC Power Shield eliminates the requirement for a separate power source, allowing the battery to power the D1 Mini directly. This shield is designed to accept input voltages ranging from 7 to 24 volts, making it an ideal match for our project requirements.

Safe and accurate measurements are vital for a 12V battery that can reach nearly 15V during charging. The Wemos D1 Mini features a voltage divider circuit employing 220kΩ and 100kΩ resistors. While the onboard ESP8266 A0 port reads up to 1V, the voltage divider allows for readings up to 3.2V, effectively converting the higher voltage to a safe 1V range.

Voltage Divider calculations for 3.2V and 15V

To bring down the 15V to the D1 Mini's safe reading range, we add a 1M2 Ω resistor in series with the battery's positive terminal. This setup reduces the 15V to approximately 0.99V, allowing the D1 Mini to precisely measure the battery's voltage without risking damage to its internal components.

Wemos DC Power Shield with extra resistor

Alternatively, a 1M5 Ω resistor can reduce the input to about 0.82V. Although this slightly reduces precision, it also guarantees a safe measurement.

Desoldering the DC barrel connector from the shield enables us to shrink the entire setup, making it compact enough to fit inside a small, waterproof enclosure.

Wemos LOLIN D1 Mini Pro

If your car or motorcycle isn't near the WiFi network, opting for a D1 Mini Pro is a great solution. It provides the option to attach an external antenna, extending the range. Remember to re-solder the 0 Ω resistor on the PCB to switch from the onboard antenna to the external connector (in red below).

Ensure to activate Sleep mode by connecting the solder pads at the back of the D1 Mini (refer to the image below). If you face challenges while flashing the firmware after connecting the pads, temporarily remove the solder to resolve the issue.

Solution - Software

Our Arduino code reads the battery voltage through the voltage divider and publishes it to an MQTT server at a configurable interval. The incorporation of MQTT Discovery ensures hassle-free integration with Home Assistant.

Battery Voltage on Home Assistant dashboard
Battery Guard Device within Home Assistant

Downloads

Result

Once linked to the battery, the module will publish voltage data and enter deep sleep mode to conserve power for the specified interval. The Keep Awake switch prevents sleep mode, allowing over-the-air updates and calibration by connecting a voltmeter to the battery and saving the reading directly onto the module.

Here are some images showcasing the D1 Mini Pro version with an external antenna and the standard D1 Mini in a custom-designed 3D printed case.

Conclusion

With your Smart Battery Guard up and running, you're no longer in the dark about your vehicle's battery status. Embrace the power of IoT and automation to stay connected with your car or motorcycle, ensuring they're always ready to hit the road when you are. This project enhances your vehicle's health and serves as a testament to what DIY electronics and programming can achieve. So, gear up, get your hands dirty, and embark on this exciting journey of building your Smart Battery Guard! Safe travels! 🚗🏍️