# ThermalOptimizer

This design uses a ATMEGA328pb microcontroller and features a 8-30V power supply, a temperature sensor input (analog or digital), an analog 8-30V voltage sensor, a 0-30V digital input, a touch button with integrated LED/light sensor, an LCD, and 2 open collector outputs (one with PWM) and a relay.

## Usage
The ThermalOptimizer circuit board is used in the [RefrigeratorOptimizer](https://www.thefloatinglab.world/en/fridge.html) and production version of the [HotWaterManager](https://www.thefloatinglab.world/en/boilers.html).

## Open Source
The ThermalOptimizer is designed with KiCad 8.0, and released under the GNU GENERAL PUBLIC LICENSE, as supplied with this design.

## Software
The HotWaterManager is an *open source project*, the software that runs on the ThermalOptimizer can be found in the [HotWaterManager GIT](https://git.thefloatinglab.world/thefloatinglab/hotwatermanager).

## Notes
The hardware should be reasonably self explanatory. A few notes:

- PD2 is connected to the output of the built-in touch sensor.
- Analog input PC1 is used to measure the voltage of the power supply. The resistors are dimensioned to be able to measure voltages up to 30V. This would accomodate 12V and 24V systems.
- PC5 is the input of the temperature sensor. For analog sensors, a pull up resistor of 10k should be used, but for digital sensors, a pull up resistor of 3k3 is better. The software pulls PE1 to high, which is connected to a pullup resistor of 4k7 in parallel to the 10k resistor if a digital sensor is detected.
- PC2 can be used as an analog input but is in the existing software applications used as a digital input, to detect 12-24V volts. In the RefrigeratorOptimizer it is connected to the compressor diagnostic output, in the HotWaterManager it is connected to the contact/ignition wire of the engine.
- The outputs PB3, PC0 and PC4 are used to control the backlight of the LCD, which gives us 8 luminance values. Some resistors are put in series, the reason was availability of the specific values. A single PWM output could also be used instead, but it wouldn't work during sleep of the microcontroller.
- The LED (connected to PB5) is also used as a light sensor and can be used to control the LCD backlight intensity. This is achieved by pulling the normal LED output PB5 to LOW, the PE2 output to HIGH, so that the LED is connected in reverse. Then the voltage is taken away and the ADC of PE2 is used to measure how much the voltage has dropped in a certain amount of time (5ms). The more light, the faster the voltage drops. This works best with red LED's, and worst with blue LED's. A blue LED can be used but it will already give a "dark" output in twilight.
- The microcontroller does not use a crystal but instead uses its own internal oscillator. ***Be very careful if you set the fuses / upload a bootloader, if you set the oscillator/clockspeed to EXTERNAL you brick the ThermalOptimizer!*** The external crystal outputs are left unused in this design, so in theory it should be possible to connect a temporary crystal to unbrick the microcontroller, but it will be very difficult as the board is not designed for this. The clockspeed should be (at least) 4MHz to reliably read out the digital temperature sensors. Higher clockspeeds than 4MHz offer no advantage in the existing software applications but just consume more power.
