1

I am working on a project on Arduino OLED MAX6675 thermocouple and SSR for my oven. My problem is when my SSR goes in LOW or HIGH state it turn ON and OFF several times before going to permanent HIGH or LOW state. This make my load(Heater) on and off many times. Since the temperature crosses the set-point to change the output state, the process temperature will be cycling rapidly, going from below set-point to above, and back below. This frequent ON OFF will damage my SSR and heater. My Question. Is there any hardware or software solution. To reduce the frequency of ON OFF . I can’t increase the delay() time because it make my button input slow. My codes are below.

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include "max6675.h"

//oled
//oled i2c addresss
#define OLED_ADDR 0x3C
Adafruit_SSD1306 display(-1);
// 128 x 64 pixel display
#define SSD1306_LCDHEIGHT 64

//MAX6675
//Pin initialization
int so = 2;
int cs = 3;
int sck = 4;
MAX6675 thermocouple(sck, cs, so);
float current_temp;
int set_temp;
int const h_temp = 2;

//Button
int button_up = 7;
int button_down = 8;
int button_upv;
int button_downv;

//SSR
int ssr_u = 10;
int ssr_d = 12;

void setup() {
    Wire.begin();
    delay(1000);

    // initialize and clear display
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(8, 20);
    display.println("Welcome..");
    display.display();
    display.clearDisplay();
    delay(1000);

    //Button
    pinMode(button_up, INPUT);
    pinMode(button_down, INPUT);
    set_temp = 20;
    pinMode(ssr_u, OUTPUT);
    pinMode(ssr_d, OUTPUT);
}

void loop() {
    current_temp = thermocouple.readCelsius();
    delay(100);
    button_upv = digitalRead(button_up);
    button_downv = digitalRead(button_down);

    //button
    if (button_upv == HIGH && set_temp < 180) {
        set_temp = set_temp + 5;
    }
    if (button_downv == HIGH && set_temp > 20) {
        set_temp = set_temp - 5;
    }

    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(5, 10);
    display.println(current_temp);
    display.setCursor(5, 30);
    display.println(set_temp);

    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(30, 40);
    if (button_upv == HIGH) {
        display.println("Up");
    }
    if (button_downv == HIGH) {
        display.println("Down");
    }
    display.display();

    //SSR
    if (current_temp < set_temp - h_temp) {
        digitalWrite(ssr_u, HIGH);
        digitalWrite(ssr_d, HIGH);
        delay(500);
    }
    if else(current_temp > set_temp + h_temp) {
        digitalWrite(ssr_u, LOW);
        digitalWrite(ssr_d, LOW);
        delay(500);
    }
}

Thanks in advance for help

5
  • Which arduino board do you use? Are you using a 3.3v arduino board and a counterfeit ssr? Please explain better what you have and how it is powered. Google for hysteresis. You need to put some hysteresis into your sketch.
    – Jot
    Sep 25, 2018 at 16:37
  • I am using pro mini 5v and 40 amp SSR.
    – Himanshu
    Sep 25, 2018 at 17:01
  • 1
    the keyword is hysteresis forum.arduino.cc/index.php?topic=526806.0
    – Juraj
    Sep 25, 2018 at 17:10
  • Is there any hardware solution like adding a capacitor so that voltage remaining constant for few seconds
    – Himanshu
    Sep 26, 2018 at 6:33
  • 2
    Hysteresis will just be way easier in software. Sep 26, 2018 at 7:22

1 Answer 1

7

You need to implement hysteresis. Set two temperature points around set_temp. One a little higher to be a limit for turning the heater off and a one a little lower then set_temp to turn the heater on.

You only need to change your if else condition a little

if (current_temp < set_temp - HYST_VALUE) {
  digitalWrite(ssr_u, HIGH);
} else if (current_temp > set_temp + HYST_VALUE) {
  digitalWrite(ssr_u, LOW);
}

you could start with

int const HYST_VALUE = 1;
7
  • Is there any hardware solution like adding a capacitor so that voltage remaining constant for few seconds
    – Himanshu
    Sep 26, 2018 at 6:43
  • 1
    this is a regulation problem, not simply solvable by hardware. the temperature could oscillate around your set temperature long time. implementing hysteresis is how it is done in all thermostats
    – Juraj
    Sep 26, 2018 at 7:16
  • I edited the answer
    – Juraj
    Sep 26, 2018 at 7:23
  • Hello juraj I tried the same as you said but this code freeze loop somewhere. I am doing something wrong somewhere please help.I tried the same code.
    – Himanshu
    Sep 26, 2018 at 12:28
  • Hello juraj I also change my sketch in question please check it.
    – Himanshu
    Sep 26, 2018 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.