Intelligent water heater is On/Off temperature controller. The controller will try to maintain the water in temperature in given range (min and max temperature). In this system user will be able to set minimum temperature and maximum temperature. The heater will be switched on when the water temperature is below minimum temperature and switched off when it goes higher than the maximum temperature.
we are using PTC thermistor to measure the water temperature. you can also use DS18B20(water proof) as well with little code modification. LCD is used to show visual feedback like present temperature and users settings. The keyboard interface is simple , it only consists three buttons. One is save/menu button. The other two buttons are used to edit the value. The settings will be saved to EEPROM, so even after power reset the settings will be available.
Lets go through some of the methods, full code is available here.
This is the method that is doing actual calculations , converting the ADC value to the temperature, I took this logic form Adafruit site. The results are accurate enough for hobby project. This method will call ReadADC() method with the channel number(In this case I have attached the sensor to the PC1). To increase the consistency in the reading you can increase the NUMSAMPLES, temperature calculation will be based on the average of the ADC readings.
This method will be executed periodically (1 sec), will be called from ISR (Interrupt service routine). It will compare the present temperature with defined max and min temperature and control the load accordingly.
Most of the User Interface is managed in this method. I tried to keep this method as generic as possible so that it can be used in other projects. The method will take a value (only 8 bit numbers) which we needs to be updated , a string which will be displayed on LCD along with number and location if you want to save the updated number in EEPROM you can pass the address. for example if you want update the max temperature setting the method call would look like this (Assume that EEPROM location is 3)
In the main method you will see logic to setup the IO lines and calling the update method on based on the keys press.
you can find full source code here . LCD connections are available in source code, load should be connected to PB2, the following schematic shows how you should connect keys and thermistor to development board