+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Newbie level 5
    Points: 1,623, Level: 9
    Achievements:
    7 years registered

    Join Date
    Sep 2010
    Posts
    10
    Helped
    0 / 0
    Points
    1,623
    Level
    9

    Help required for Arduino Uno Heater Controller

    I am a novice in Arduino. I am working on a temperature controller for a hot plate. I have a PT100 as sensor which is being driven by a 1mA constant current source. As the resulting output voltage is quite low, I am using an OpAmp for a gain of 11. The output of the OpAmp is connected to pin A4 of the Arduino.

    The desired temperature is set by means of a potentiometer, the output of which (0-5V) is connected to pin A1 on the Arduino.

    The PWM output for the heater is from Pin 9 and is fed to an opto-isolator (the output of which is connected to a Triac, which in turn controls the power to the heater element).

    All this works quite well, except for a bug that I have not been able to find:
    On switching on, the PWM output is zero. It activates only when the potentiometer setting is brought quite low. After that, the setting can be changed as desired and everything works well. For example, if the potentiometer setting is for say, 150 degrees, the system will work just fine as long as it is not switched off (or if the power is not disrupted). In case of switching off (or power failure), followed by a subsequent switching on, the PWM output remains zero. It is only on bringing the potentiometer to a relatively lower setting that the PWM output gets reactivated. Once it does, then the potentiometer can safely be brought back to the original (or any other desired setting) and everything works just fine.
    Can anyone help me in finding the bug? I want that on switching on, the system should start working right away and control the heater (PWM) so as to attain the temperature as set by the potentiometer.

    My sketch is as below:
    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    
    // Heater Controller 
     
    int heatingInPin = A1;// Heating pot slider connects here
    int sensorPin = A4;// Temp Sensor output (amplified) connects here
    int heaterPin = 9;// PWM heater output is available here
    int tempDiff;
     
    int sensorCount;// this holds the value of the Temperature Sensor after amplification
    int heatSetCount;// this holds the value of the Temperature Control Pot
    int pulseWidth;
     
    void setup(){
     
    pinMode(heaterPin, OUTPUT);
    }
    void loop()
    {
    sensorCount = analogRead(sensorPin);
    sensorCount = (sensorCount - 247);// apply offsetvalue  
    heatSetCount = analogRead(heatingInPin);
     
    heatSetCount = map(heatSetCount, 31,1023,0,440);// This gives a maximum temp of 400 degrees
     
    if (sensorCount >= heatSetCount)
    {
    analogWrite(heaterPin,0);
    }
     
    else
    {  
    tempDiff = (heatSetCount - sensorCount);
     
    if (tempDiff >= 25)
    {
      pulseWidth == 255;// heater is full ON
    }
    else
    {
      pulseWidth = (10 * tempDiff);
    }
     analogWrite (heaterPin,pulseWidth);
    }
    delay (10);
    }
    Last edited by bassa; 17th April 2019 at 07:42. Reason: add code tag

  2. #2
    Advanced Member level 5
    Points: 16,186, Level: 30

    Join Date
    Nov 2012
    Posts
    2,967
    Helped
    716 / 716
    Points
    16,186
    Level
    30

    Re: Help required for Arduino Uno Heater Controller

    See line number 35.


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  3. #3
    Advanced Member level 2
    Points: 4,878, Level: 16
    Achievements:
    7 years registered
    ZASto's Avatar
    Join Date
    Jan 2008
    Location
    Messy Corner, 44°47'31.56"N, 20°28'9.16"E
    Posts
    574
    Helped
    115 / 115
    Points
    4,878
    Level
    16

    Re: Help required for Arduino Uno Heater Controller

    PWM and Triac on AC is not good.
    Make no mistake between my personality and my attitude.
    My personality is who I am.
    My attitude depends on who you are.



    •   AltAdvertisment

        
       

  4. #4
    Newbie level 5
    Points: 1,623, Level: 9
    Achievements:
    7 years registered

    Join Date
    Sep 2010
    Posts
    10
    Helped
    0 / 0
    Points
    1,623
    Level
    9

    Re: Help required for Arduino Uno Heater Controller

    Thank you, mate. I understand that it should be "pulseWidth - 255." Although I don't see how it will affect the working of the sketch, I will try it out tomorrow and revert. Thanks once again.



    •   AltAdvertisment

        
       

  5. #5
    Advanced Member level 2
    Points: 4,878, Level: 16
    Achievements:
    7 years registered
    ZASto's Avatar
    Join Date
    Jan 2008
    Location
    Messy Corner, 44°47'31.56"N, 20°28'9.16"E
    Posts
    574
    Helped
    115 / 115
    Points
    4,878
    Level
    16

    Re: Help required for Arduino Uno Heater Controller

    Quote Originally Posted by chi239 View Post
    I am a novice in Arduino. I am working on a temperature controller for a hot plate. I have a PT100 as sensor which is being driven by a 1mA constant current source. As the resulting output voltage is quite low, I am using an The PWM output for the heater is from Pin 9 and is fed to an opto-isolator (the output of which is connected to a Triac, which in turn controls the power to the heater element).
    PWM and Triac are not playing well together.
    Make no mistake between my personality and my attitude.
    My personality is who I am.
    My attitude depends on who you are.



  6. #6
    Advanced Member level 5
    Points: 16,186, Level: 30

    Join Date
    Nov 2012
    Posts
    2,967
    Helped
    716 / 716
    Points
    16,186
    Level
    30

    Re: Help required for Arduino Uno Heater Controller

    I understand that it should be "pulseWidth - 255."
    No, it should be a single equal sign (= and not ==).

    Make the suggested change, compile and upload again and report the outcome.


    1 members found this post helpful.

  7. #7
    Newbie level 5
    Points: 1,623, Level: 9
    Achievements:
    7 years registered

    Join Date
    Sep 2010
    Posts
    10
    Helped
    0 / 0
    Points
    1,623
    Level
    9

    Re: Help required for Arduino Uno Heater Controller

    Hello c_mitra,

    Thank you for your suggestion. I made the correction and now it is working fine.

    Thank you once again! :-)



    •   AltAdvertisment

        
       

  8. #8
    Advanced Member level 5
    Points: 16,186, Level: 30

    Join Date
    Nov 2012
    Posts
    2,967
    Helped
    716 / 716
    Points
    16,186
    Level
    30

    Re: Help required for Arduino Uno Heater Controller

    As others have pointed out, using a triac with a PWM signal is not the right way to control the output power. You should use a power MOSFET with a PWM signal (with additional driver, if needed). If the heater is low power (say <500W) you can use rectified and filtered power to driver the heater in series with the power transistor. If you are having a big heater (say >1000W), you may use a triac with a zero crossing detector and calculate the trigger time from temp difference (set point-actual point).

    There is another mistake in your software. Sometimes the temp overshoots and actual temp can be higher than the set point. If the temp diff is negative (actual temp > set temp), pulse width should be set zero. That will allow the actual temp to come below the set temp. That needs to be fixed.



  9. #9
    Newbie level 5
    Points: 1,623, Level: 9
    Achievements:
    7 years registered

    Join Date
    Sep 2010
    Posts
    10
    Helped
    0 / 0
    Points
    1,623
    Level
    9

    Re: Help required for Arduino Uno Heater Controller

    Hello c_mitra,

    Thank you for your suggestions. I am already using a zero-crossing detector detector with the triac for heater control. I didn't mention it in my earlier post for the sake of brevity.

    Regarding the case of negative temp difference, it is also taken care of in lines 24-26 of my sketch.

    Thank you once again.



--[[ ]]--