Introduction: Battery Hero (aka Cutout Switch)
Last year I brought a thermoelectric cooler for camping. These aren't the best for cooling items down from room temperature but they will kept items cold if they come out of a fridge. The big issue is that the cooler will quite happily drain the battery overnight if left plugged in. There are a number of ways to solve this problem:
- Dual battery setup - Great idea for running all sorts of accessories but you need to mount a second battery and charging circuit that cuts off when the car isn't running. I am not intending on keeping the car for long so didn't want to invest to much in it.
- Use an outlet that is only on when the car is running - We found that you need to keep the cooler running for as long as possible to keep the temperature low. If the temperature rises too much the cooler will take significant time bringing it back down.
- Unplug the fridge when stopped - Same issues as above and has the risk that you may forget (I did...) and discharge the battery.
- Monitor the battery voltage and turn off cooler before the battery discharges too much. This option maximises the run time of the cooler, is relatively simple to build / install and is cheap.
This instructable will document the fourth option (nicknamed "the Battery Hero") and provide some additional information on things that I learnt whilst constructing the device. Step by step instructions are not given as everybodies implementation will be slightly different. All concepts and stages of the design will be outlined so it should be relatively easy to develop your own unit.
Supplies
The battery hero was built whilst the world was in lockdown due to COVID 18 and hence I had to make do with what I had at hand. There are a couple of changes I would suggest and these are described below.
- ATtiny 85
- L7805 voltage regulator
- 0.33uf ceramic capacitor, I only had an electrolytic but a ceramic should be used
- 0.1uf ceramic capacitor
- Momentary push switch
- WS2812 LED
- 47k resistor
- 15k resistor
- 1k resistor
- 2N2222 transistor
- IN4007 diode
- 102 Trim pot, this should be replaced with something with a smaller range so that changing the voltage doesn't take so many turns.
Step 1: Description
The auto switch measures the input voltage and switches the output on and off dependant on the cutout selected. The LED indicates green when the voltage exceeds the cutout and the relay output is activated. Initially the switch was toggling at the cutout level as the relay put enough of a load to exceed the cutout. The code accounts for this and the circuit turns on at 0.2V above the cutout and off at the cutout.
I had initially intended to mount the relay within the switch but decided against this for a number of reasons:
- Alternative relays can be used for different applications, either a high or a low current version dependant on what is being switched.
- Voltage drop in your car can be significant, I measured a couple of volts difference from the battery to the outlet in the boot. By having the relay separate, I can mount the switch close to the battery and the relay close to the consumer (a cooler in my case) and get a more accurate reading on the battery condition.
A trim pot allows the cutout to be adjusted to a value between 12 and 13V. The pot used isn't the right value as it takes a long time to adjust the cutout. I only used it as I didn't have anything else to hand.... I recommend that this component is changed out for something more appropriate.
A method to display both the measured voltage and the cutout voltage was required. A small LCD screen is the obvious solution but I didn't have one at home. Instead a WS2818 LED was used and a series of flashes indicate the voltage, red for the cutout and blue for the input. A short flash indicates a zero and a long pause indicates the gap between digits. For example: flash, pause, flash flash, pause, flash flash flash flash flash, pause, quick flash equates to 12.50. This is shown in the attached video for the cutout voltage. Whilst not the most elegant solution, this method does allow you to get feedback on the current settings.
Step 2: Theory
The circuit uses a number of simple ideas that together allow for the correct functionality. Rather than repeating details of the background concepts I have included links to some reference material that I have found useful in the past. Please leave a comment if you wish further explanation on any item.
Voltage Regulator
The ATtiny requires 5v for operation and as a reference for the voltage measurement. This can easily be generated from the vehicles 12v battery though the use of a voltage regulator. This link provides a beginners introduction into the construction of a voltage regulator in a far better detail than I ever could!
Voltage Divider
The voltage in a car can vary between 12 and 15VDC dependant on if the engine is running or not (i.e. if the battery is charging). The ATtiny (or any microprocessor) can only measure up to 5 volts and hence a voltage divider is used to reduce the cars voltage down to a level that can be measured. Indoorgeek has written an instructable that outlines the concept of the voltage divider and why you should make your own. The resisters choosen for this project give an input voltage of 0 to approx 20VDC so there is some safety margin there for when the battery is charging.
Relay Driver
A microprocessor is unable to switch large loads directly and so a simple transistor switch circuit is used to drive a relay. Tarantula3 provides detail information on the operation of relays as well as how to switch them in this instructable.
Input / Output
The input / output section of the circuit consists of a momentary push button and a WS2812 LED. No resistors are required on the push button as the internal pull ups of the ATtiny are used. The WS2812 is controlled via the FastLED library (FastLED wiki). There are a couple of options for LED libraries but I have found FastLED to be easy to use and provides all the functions that I want.
Step 3: Case
I have just purchased a 3D printer and this seemed to be a great opportunity to learn 3D design and printing basics! There are a number of design packages to use but Fusion 360 was recommended to me by a friend and it turns out to be a fantastic product and relatively simple to understand. There are a large number of instructables on Fusion 360 and I recommend that you have a look at a few of them if you are just starting out.
The aim of the design was for a compact unit that allow for easy visability of the indicator lamp. Some of the key design features are:
- I found some plastic that refracted the light and used this to combine the switch and the indicator lamp. A thin wall holds the plastic in place so that slides up and down onto the momentary switch.
- A hole was left in the side so that the trim pot can be adjusted
- The terminal strip was left exposed for ease of connection.
- The circut board is held in place by the two half of the cover clamping down on it.
- A small grid of holes are located by the voltage regulator for air flow (note that there is very little current draw and the regulator doesn't actually heat up.
All fastenings were via self tapping screws. It depends on the accuracy of your printer but I made the holes for the screws slightly smaller than required and then drilled them to the correct size after printing. This ensured that the screws correctly "bit" into the plastic.
I recommend that you get a good quality vernier caliper and measure once, twice and three times to ensure that you get the design right. Once you think you are complete, rotate the design in every direction to ensure that there aren't any unexpected "features".
The Ender 3 printer comes with the Creality Slicer and while this is ok, I could not get retraction* to work. After much research and testing I downloaded Ultimaker Cura. I wish I had done this much sooner as it is a great product and the prints produced are a lot better quality (and retraction works!).
* Retraction is the process which pulls back the print filiment and lifts the extruder nozzle slightly when the print head has to move any distance. Enabling retraction reduces "stringing" and prevents the nozzle dragging across your freshly printed surface.
Step 4: Circuit
I always prototype my circuits on a breadboard. This allows for easy diagnostics when things aren't going quite as planned! Once the circuit is correct it can then be transferred to a PCB or a prototype board. I used a prototype board in this case as the circuit is relatively simple and I haven't quite got myself set up for making PCBs, yet.
Layout the compontents on the board and then think about where the tracks would run. Then walk away and come back and have another look. I find that have a break and then looking again allows for alternative, and ofter better, layouts to be thought out. The correct method is to use a layout program but due to the simple nature of what I do, I have always found trial and error to work just as well.
Two circuit boards were used, one for the main controller and another for the switch / LED. This allowed the switch to be accurately placed so that the correct pressure was being apply by the plastic button. I had intended to connect the two boards together using a plug but it turned out that there wasn't enough room and hence they ended up being soldered together. The keen eye will spot that I used a red wire for the negative connection, this was an error as I was doing the board upside down..... I don't recommend this and always stick to the common conventions when building circuits.
I used a holder for the ATtiny for two reasons:
- allows the microprocessor to be removed for programming if need be, and
- allows the circuit to be powered up without the microprocessor installed in order for voltages to be checked
Once all your solder joints are complete, carefully inspect all joints and tracks to ensure there are no unintended bridges.
Step 5: Software
The code for this unit is very simple. It measures the voltage and compares it with the cutout. The relay output is turned off or on based on this comparison. Each time through the main loop, the cutout is adjusted based on user input and the voltage / cutout is displayed if the switch is pressed.
The code is attached and is heavily commented, let me know if you want any further details though. I am sure there is more efficient ways of doing this but it works!
Arjun Ganesan has written a very good guide to programming the ATtiny which I used successfully for my first project. I highly recomend that you build the shield that he describes and this makes the process very simple. There are a number of shields that you can buy but we are DIYers!
Attachments
Step 6: Post Construction Thoughts
The unit works in the manner expected and will be of use (once we can leave the house again!). Hopefully we will never have to beg a jump start off another camper... There are a couple of thoughts that I have had though that would improve the unit.
Power Saving
There are a number of options for the ATtiny to conserve power. I haven't measured the current draw of the unit yet but will do so and try to minimise the power usage of the monitoring circuit.
Input Protection
There should be a diode to protect the input of the voltage regulator. I wasn't paying attention and swapped the positive and negative on the input when hooking up to the car. This resulted in needing to change out the voltage regulator and could have been avoided by the addition of a diode.
Position of Cover Labels
Put simply, they are too low and are covered by the connectors. They have been raised in the STL files attached to this "ible.
Is it the Best Solution?
For where I am in life right now? Yes! BUT if I was keeping the car, I would install a second, deep cycle,
battery. This gives maximum run and allows a number of items to be run while parked up for the night.
I hope this instructible has given some insight into my automatic battery cutout switch and it allows you to develop something similar or to use the concepts in something completely different!
Participated in the
Motor Vehicle Contest
2 Comments
3 years ago
this is so handy, nice job!
Reply 3 years ago
Thanks for the feedback. It was fun to make and made me learn a few new things!