Project tutorial
Arduino Control AC Water Heater temperature

Arduino Control AC Water Heater temperature © CC BY-NC-SA

How to control water temperature using arduino and water heater element like PID controller

  • 10,210 views
  • 0 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

This is one of the most interesting and hardest experiment to do, Why?because the circuit we want to build is a little bit hard and tricky.

Most of the tutorial in the internet do it with relay to turn on-off the AC heater to increase the temperature,it's not an accurate way to control the water temperature,and will not be able to reach to your target temperature.

To explain it in a simple example: you want to increase a temperature of the water to be about 60 degree Celsius,With a relay when you reach to 60 degree Celsius,the relay turn off the Heater, that makes the temperature decrease rapidly so the relay will turn on and increase temperature rapidly again , so the relay will turn on-off within a short time which will damage the relay and maybe damage the heater it self.

Best way to adjust the temperature by control AC voltage output applied on AC heater.

build a (crappy) AC triac circuit not just unprofessional but also will not work well,With inappropriate heatsink,no protection from ac short circuit or overload current, and most important no protection for you,any small fault might kill you,be careful.

So let's see the best way to control AC heater, and offer a high protection from electrical shock hazard,and give us a full control over the water temperature.

We want to control AC Water heater, and control the water target temperature with temperature sensor feedback signal,and we want to control Applied AC voltage on the AC water heater so we can control accurately the water temperature.

We will use an LCD to show all information an parameters on it.

the components we need are:

  • Arduino Board"I used arduino Nano".
  • Power Cable C14.
  • OLED 0.96 inch display.
  • DS18B20 water proof temperature sensor.
  • 4.7K resistor
  • Breadboard and solderless jumper
  • Oscillscope"optional".

You can check all feature about sugar and support sugar team on indiegogo Now:

http://igg.me/at/sugdev/x

As we see no need for any naked wire, or cutting any AC wires to connect the components together "like in the relay circuits".

and we will use an oscilloscope to see the AC voltage waveform and ensure the sugar device control the applied ac voltage on water heater.

in the final all you need to do is

  • Connect to connect the water heater element to Sugar device output socket.
  • Connect the AC power cable to sugar device to power it up.
  • connect the RJ12 cable between sugar device and arduino, use RJ breakout to connect the cable to Arduino nano.

and you need a glass of water too put the heater inside it with the DS18B20 sensor

well during this test, i faced something may happen for everyone, the power consumption by the AC Heater was larger than 300W and the AC current was higher than I expected, thanks for Sugar device , the ac fuse protect the circuit and cut off the power source, for such a circumstances,Sugar is capable to protect your self and equipment you use from any short circuit or overload fault.

all similar circuits on the internet won't do that, you will be under the mercy of AC current which will damage all unprotected component and put you life under threat.

remember safety is a priority.

and with sugar I safely remove the fuse and replace it by a new one,no need to open the device or touch any dangerous ac components.

last thing to say:you need to observe the temp target and the sensor temp and adjust the value of the output voltage in the code go to "" void UpdatePWM() "" and change the value to match your requirements

See the video to see how the circuit works

If you like our project we hope you support us on indiegogo Now

http://igg.me/at/sugdev/x

and you can see the oscilloscope waveform shows how the sugar control AC Voltage output

Code

Arduino Full codeArduino
the project code
#include <SPI.h>
#include <Wire.h>
#include <OneWire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
OneWire  ds(2);  // on pin 2 (a 4.7K resistor is necessary)
const int SugarPin  =9;
int HeaterPWM=13;
int voltage_perc;
const int delayTime=1000;
float Temp;
float T_diff=0.0;
float Target_T=90;
int MenuCounter=1;
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()   {                
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 
  display.clearDisplay();
  display.display();
  // define arduino PWM as an output
  pinMode(SugarPin,OUTPUT);
  //define Button as an input with PullUp resistor
  //  pinMode(Sugar_Pot ,INPUT);
  
  MainMenu();
  display.display(); 
  delay(3000); 
  display.clearDisplay();
  display.display();  
  ControlPanel();
}
void MainMenu()
{
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setCursor(20,5);  
  display.print("Sugar");      
  display.setCursor(20,35);    
  display.print("Device");    
  delay(3000);
}
void UpdateReading()
{
  display.setTextSize(3);
  display.setCursor(20,30);   
  display.setTextColor(WHITE);  
  switch(MenuCounter)
  {
  case 1:
  display.print(Target_T);    
  break;    
  case 2:
  display.print(Temp);    
  break;
  case 3:
  display.print(voltage_perc);    
  break;  
  }  
  display.display();    
  MenuCounter++;
  if(MenuCounter>3){MenuCounter=1;}
}

void ControlPanel()
{
  display.clearDisplay(); 
  display.display();        
  display.setTextSize(2);
  display.setTextColor(WHITE);
  switch(MenuCounter)
  { 
  case 1:
  display.setCursor(5,5);  
  display.print("Sensor T");        
  break;
  case 2:  
  display.setCursor(5,5);    
  display.print("Target T");    
  break;
  case 3:    
  display.setCursor(5,5);    
  display.print("AC volt%");    
  break;
  }
  display.display();    
}

void loop()
{
 ReadTempSensor();
 delay(500); 
 ControlPanel(); 
 UpdatePWM(); 
 UpdateReading();
}

void UpdatePWM()
{
T_diff=Target_T-Temp;
if(T_diff>=40)
{
 HeaterPWM=64;//full voltage; 
 voltage_perc=100; 
}
else if(T_diff<40&&T_diff>=30 )
{
 HeaterPWM=54;//full voltage; 
 voltage_perc=85;
}
else if(T_diff<30&&T_diff>=20 )
{
 HeaterPWM=48; //60%
 voltage_perc=75; 
}
else if(T_diff<20&&T_diff>=10 )
{
 HeaterPWM=38; //50%
 voltage_perc=50; 
}
else if(T_diff<10&&T_diff>=2 )
{
 HeaterPWM=30; //30%
 voltage_perc=30;
}
else if(T_diff<2 )
{
 HeaterPWM=12; //0%
 voltage_perc=0;
}
analogWrite(SugarPin,HeaterPWM);
}
void ReadTempSensor()
{
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    return;
  }  

 
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      type_s = 1;
      break;
    case 0x28:
      type_s = 0;
      break;
    case 0x22:
      type_s = 0;
      break;
    default:
      return;
  } 

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  Temp=celsius;
  fahrenheit = celsius * 1.8 + 32.0;
}

Schematics

Project schematic
Schematic
Aya0xvh2kuk4tm6v8jc3

Comments

Similar projects you might like

Arduino Temperature Control

Project tutorial by Team pandhoit

  • 18,266 views
  • 10 comments
  • 28 respects

Health Kit: Humidity and Temperature Control

Project tutorial by Diana Khalipina

  • 5,515 views
  • 2 comments
  • 42 respects

Automatic Temperature Based Fan Control (for Media Cabinets)

Project tutorial by Vess Bakalov

  • 5,263 views
  • 4 comments
  • 24 respects

Servo Control with TV Remote Control

Project showcase by eldo85

  • 5,591 views
  • 5 comments
  • 17 respects
Add projectSign up / Login