Building a Smart Relay for My Truck
I’ve been thinking about how to build a smart relay between the starting battery and accessory battery of my truck to connect the batteries automaticallyΒ when either the alternator is charging the battery or their is sufficient sunshine to charge both batteries on the truck.π
Over the summer, I added a two way switch to the truck that has three positions π – in position 1 it connects the batteries when the engine is on, in position 2 it connects the batteries even when the engine is off to enable solar charging and position 0 the batteries remain disconnected regardless of engine status to help starting in cold weather should the accessory battery be low.π
A smart switch would either connect the batteries when the alternator or solar panel is feeding in ample power to charge the batteries. When the engine is off and the sun isn’t shining bright enough to charge both batteries, they would be disconnected to assure the camp load and accessories do not overdischarge the starting battery. β I wouldn’t want the starting battery to get too low, but I do want it to be charging when the sun is shining and the load is small.
I was thinking I could make a smart switch using an Arduino Nano microprocessor, some voltage dividers (which are a set of resistors wired up in a specific way to divide voltage), and a transistor or small relay.π Here is how I would imagine this would work. The Arduino Nano has five analog pins and about fifteen digital pins. They can be configured for either input or output. The analog pins can read a voltage between 0 and 5 volts DC. So how do you measure a car or solar panel that could in theory put out as much as 16 volts? A voltage divider.β
It turns out voltage can be divided by resistors in parallel. If you have a 10kΞ© and an 3.3kΞ© resistor in parallel, on a 16 volt source you will have a voltage of 12.03 volts and 3.97 volts on the other side of the resistors. While as around 12 volts will be wasted as heat, β because your only moving a small amperage through the circuit to provide a voltage reference for the Arduino, the waste in heat is an insignificant 0.01 watts.
Now two of the analog pins will have a voltage between 0 and 3.97 volts. The microprocessor reads the voltage from 0 to 5 volts, which corresponds to an 8 bit analog number from 0 to 255 in the analog read function. π An input voltage of roughly 4 volts would give an input value of 204. Because we have run this through the previously described voltage divider, we know an input value of 204 equals a voltage of 16 volts. Likewise a value of 161 on the analog input equals 12.6 volts, an analog input value of 173 equals 13.6 volts.
First off to avoid wasting battery power when the engine is off and the skies are cloudy, the Arduino should be put into a deep sleep for every 30 seconds.Β π€ After which the the Nano should read the pins and compare the input values to what had been read some 30 seconds before. Only after two consecutive readings (30 seconds apart) that should warrant opening or closing of the small relay that will drive the bigger relay that either connects or disconnects the batteries.π
Great. Now all I have to code this into software to be burned into the brain of the Arduino, and then solder together the transistors and resistors.π₯Β While I have now figured out how this would work on paper, the next step is to physically build the device and write the code. As this device could lead to the possibility of being stranded with a dead battery in the wilderness, it is important that I fully test and understand the ramifications of the device I’m building.π€