Introduction: DIY: Monitor Your Car Battery: Code & Setup
Having the ability to monitor your car battery can prevent some unpleasant surprises. I will show you how I assembled the hardware, loaded the software and installed the monitor in my car. I will be using the ESP8266 Board called Wemos D1 Mini.
New to ESP8266? Watch my Introduction to ESP8266 video first.
Step 1: Watch the Video
The video has step by step instructions that will guide you through the process. Feel free to add your questions in the comment section of the YouTube video if you need any futher assistance.
Step 2: Order the Components
Buy on Amazon.com
- Wemos D1 Mini - https://amzn.to/308Sxoy
- Power Shield - https://amzn.to/3gbfqxq
- Assorted Resistors - https://amzn.to/2PagR34
Buy on AliExpress:
- Wemos d1 mini - https://s.click.aliexpress.com/e/_AEZGUP
- Power Shield - https://s.click.aliexpress.com/e/_AlE2SF
- Assorted Resistors - hhttps://s.click.aliexpress.com/e/_AAfyJV
Buy on Amazon.ca
- Wemos D1 Mini - https://amzn.to/3cpOxDe
- Power Shield - https://amzn.to/2XuoIxD
- Assorted Resistors - https://amzn.to/2AtfU1P
Step 3: Hardware
You will need a wemos d1 mini, a power shield and some resistors. First, I started by removing the power plug and installed the smaller connector to make the hardware more compact.
The D1 mini can measure external voltage up to 3.3v by using a voltage divider using R1=220KΩ & R2=100KΩ . This the voltage within the 0-1 Volt that the ADC can tolerate. To increase the 3.3v to 16v needed for the car battery, we need to increase R1 to 1.44MΩ. To do that we can add another 1.22MΩ in series to get the total 1.44MΩ. I did this by soldering a 1MΩ resistor to a 220KΩ resistor as shown here.
I attached a long wire to the power input terminals to be able to connect them to the car battery.
Step 4: Software
I then connected the D1 mini to my laptop and load the software. Make sure you select the sensor.bin version for the Analog input functionality. I then resumed with a typical Tasmota configuration.
Step 5: Car
At the car, I opened the hood and located the fuse box. I found the fuse box to be a safe and secure place to install my device.
I first wrapped the device in heat resistant tape to cover any exported pin to withstand the engine heat. Since the entire car chase is ground, I found the nearest screw and connected my ground to it. Next, I located the nearest connection to the battery positive rail and connected my positive power input to it.
Step 6: Calibrate
I then proceeded with calibrating the range of the analog input. I did this by connecting a multimeter to the battery and read the current voltage (in my case it was 12.73 volts). I then did some trial and error until my reading was 1273 as the analog reading. The last step was closing the fuse box and the car hood.
Step 7: Home Assistant
Back in Home Assistant, I opened the configuration file and added a new MQTT sensor - the code is attached above.
After I saved, I restarted home assistant for it to take effect. When it came back online, I added the new sensor to the dashboard.
Attachments
Step 8: Done
The integration is now complete. You can now use this sensor to trigger alerts!
If you found this useful, please consider subscribing to my YouTube channel - It helps me a lot.
If you are interested in supporting my work, you can check my Patreon page.
Much of the information contained is based on personal knowledge and experience. It is the responsibility of the viewer to independently verify all information.

Participated in the
First Time Author Contest
19 Comments
11 months ago
against all odds and against my ignorance of this stuff lol, I managed to get it working but I am having such a hard time connecting to the device through Wi-Fi so I can pull up the management tasoma page. Is there anyway I could use esp32 instead of the d1mini?
Reply 11 months ago
Having a hard time connecting to the device under the hood of the car. Whenever I put the device ip address to connect to it , the page just times out. Did you have this issue as well? How did you solve it?
11 months ago
Thanks for sharing ! For those who want to use this project with Domoticz. On Tasmota you can create a rule that publishes information directly to an idx with the following commands:
In Tasmota console :
Rule ON Tele-ANALOG#Range do backlog Var3 %value%; Mult3 0.01 endon ON Tele-ANALOG#Range do publish domoticz/in {"idx":YourIDXNumber,"nvalue":0,"svalue":"%Var3%"} endon
Then activate your rule : Rule1 1
To change refresh rate of your idx : TelePeriod 900 (in second)
2 years ago
Hello, and thank you so much for sharing this project. Parts are on order and I will build the same to monitor the battery voltage on my back up generator. As I’ve been caught out a few times as the battery has dropped voltage and in the time of need the generator failed to crank.
I have installed a solar battery charger but not sure it’s effective, so want to use this to check state of charge using home assistant.
I have a couple of questions relating to the project. In relation to the resistors.
In your yt video you only solder a 1M Ohm and 220K Ohm resistor in series. But the voltage drop calculator shows you need 1440 + 100 ohms. Were these in your final circuit or just as the video portrays? Thanks
Reply 2 years ago
The Wemos d1 mini already has a built-in voltage divider. I simply extended the range of it. If you are using something other than the Wemos d1 mini, I recomment you check the shcmatic first.
Reply 2 years ago
Great… thanks.. I figured that. Anyway built my monitor and hooked it up to the generator battery. Works like a charm, thank you. I left the Jack power connector in place mainly as I wasn’t able to remove despite how hot I got the connector tabs! Actually used this to my advantage as I hooked the Wemos to a 12v power supply and used that source for the calibration steps. A little easier at the bench that in situ at the battery. Had a few uses connecting to HA.. it eventually appeared despite several restarts. Did you install mosquito mqtt on your HA? That and tasmota add on appeared once the Wemos was detected. My next step is to add an automation so that the generator starts and if the battery voltage drops below a certain threshold. My next learning curve… thanks again…. Very inspiring, simply project and great for a beginner like me.
Reply 2 years ago
Awesome. I am glad it worked out!
2 years ago on Step 7
Hey man, its a great project. Can tou tell me maybe some more information. First, you dont say the way you build wifi network, on what network is Wemos Esp connected? Are you have some wifi router in car? And second, what is running homebridge server, are you have maybe Raspberry Pi in car? I expected some picture of diagram what with what is connected, how, and etc. That part is only unclear, other is perfect explained. Thank tou in advance. My e-mail is spurgin.stefan@gmail.com
Reply 2 years ago
Hello. Thanks. I am using my home wifi and I am running home assitant at home. Only the device is installed in the car, everything else is at home - over wifi. If you are parked far from home, then this setup might not work for you.
Question 2 years ago
Is there a circuit diagram for this? Particularly the link between battery voltage and A0 pin? Trying to figure out whether I need to build the voltage divider circuit with 1440 ohms / 100 ohms. You seem to only add a 1 M Ohm + 220 K Ohm in series making 1.22 M Ohms. What about the other 220 K Ohm and the other 100 Ohm on the other side of the voltage divider?
2 years ago
love what you have done here, i am setting up a few different esp's to work with home assistant, and have dose what you did above and everything is working perfect, exsept it sents the voltage out on boot up of esp over mqtt but dosent send it ever again on when i restart the esp, do you know why it might do this
Reply 2 years ago
Hello gordonfleming4040, thank you. TelePeriod maybe? The default TelePeriod is set to 900 seconds ( 15 minutes). Did you check if mqtt msgs sent every 15 mins? or you never get any mqtt msgs out?
2 years ago
Hi, this is not the right way to check the condition of a battery, especially heavy duty batteries. Because the no load voltage of the battery is totally different from the on load battery voltage. You may check the voltage of a weak battery that doesn't start the car, even that will show good till you push the car start button. Only when you push the start button, the voltage will drop to low, because the battery is not able supply the required current.
So the right way to check a battery is, connect a reasonable load instantaneously and measure the battery voltage at that instant.
Reply 2 years ago
Hi Ragothaman, thanks for your comment. Just to clairfy, I am not trying to check the CONDITION of the battery. That is a completely different test that is much more complicated, as you mentioned.
I am simply checking the volt which is is a ROUGH estimate of the battery charge. I omitted and made some assumptions to make this as-simple-as-possible while getting a "good enough" read of the battery charge. For example, I didn't take into consideration the chemical composition, the ESP load, the battery size, the resistors' tolerance, the battery temperature or even the accuracy of the multimeter - just to name a few.
Hope that helps.
Reply 2 years ago
Do you think the vehicles headlights would be enough? How high of a load would you need for an accurate reading?
3 years ago
Hi,
interesting project.
I would like to monitor a boat battery 12V during winter and charge occasionally.
What is the consumption?
Do you use deep sleep mode?
Is that possible to reduce the consumption for my purposes?
Regards
Joerg
3 years ago
This is awesome! Thank you for sharing... I have the parts already on order.
One little question: Is it possible to monitor more than one battery voltage with a single unit? I have a vehicle with 3 12 volt batteries that are used with a winch, that once the vehicle is turned off, they all disconnect from one another. I'd love to be able to monitor each battery independently, without having to build 3 units, and have 3 separate wifi connections..
Reply 3 years ago
Thanks! Unfortunately, no - because the ESP8266 has one ADC port only. You can try ESP32 which has more but Tasmota for the chip is still in beta. You might want to give that a try or wait a bit for the public release.
https://github.com/arendst/Tasmota/tree/firmware/f...
3 years ago
Thanks for sharing : )