How to get output pulses to relay

Hi Guy´s

I´m trying to read a analog signal from a temp sensor and regulating a 1kw electronic relay to achive a stable temperatur..

In this i need the arduino to give this relay pulses.. according to the temp ie: faster the more effect i need then slower as i approches the set temp value

Been trying fixed on/off but then the temp swings are to great

Any help would be most greatful

Best regards

/ Andy

With a relay, forget it. Especially with a 1kW element. If you want to pulse it, go for a SSR (Solid State Relay). But remember, most have zero cross detection aka you can only pulse them at max 100/120Hz. But that should be plenty and I would even stay above 1s as minimum on time.

And to get what you want, have a look at PID controllers. There are multiple PID libraries out but you do need to study PID controllers in order to make them work (half decent). There is NO out of the box solution and/or parameters.

I did a similar thing with my redneck Sous Vide cooker. I used one of those cheap DS18B20 temp sensors in my crock pot, and one of those cheap relay modules to turn it on and off.

I thought I might need a fancy schmancy PID algorithm to keep it close to the set temp, but I was pleasantly surprised. With just a simple "turn on if it gets below the set point and turn off it it goes above the set point" algorithm, it keeps the temp within .5 degrees F above the set point and 1 degree below. Cycle times are anywhere between 1 and 4 minutes.

Now granted my crock pot is only 150 watts, and it's full of water so it takes a while to see the results after you toggle the power. But even my cheap relay is rated for 10 amps at 125 or 250 volts AC, and that's within your 1kW range. There are a couple of issues with using relays for pulses. How long are these "pulses" going to be? My pulses are 1-5 minutes long, and that works fine. But mechanical relays are mechanical devices and have a limited number of times they can cycle. Do you care if your relay is clicking away at 2 or three times a second?

Mechanical relays are also relatively slow. Mine says 10 ms. There's no way you can catch a zero crossing or anything like it at those speeds. So you would be limited in what you can do.

Here's a duty cycle type controller using a thermistor and SSR to control a 300 watt heating element. You may be able to adapt to your application. Change set point by typing temperature in celsius times 10 in top of Serial monitor and press [ENTER]. Ex. 24 degrees C = 240.

// basicNtc_x

#define NTC_PIN A0
#define NTCSERIESRESISTOR 10000
#define THERMISTORNOMINAL 10257
#define BCOEFFICIENT 3427
#define ntcTempERATURENOMINAL 25

const byte pwrPin = 7; // output pin to SSR
int32_t tEnd = 30000, // cycle time in milliSeconds, 30 seconds here
        DC;
uint32_t tStart;
float ntcTemp, offset = 0.2;
int SeP = 220, // desired set point * 10, 22 degrees here
    temp, err;

void setup()
{
  Serial.begin(9600);
  Serial.println("    basicNtc_x.ino");
  pinMode(pwrPin,OUTPUT);
}
void loop()
{
  if(millis() - tStart >= tEnd)
  {
    tStart += tEnd;
    float reading = analogRead(NTC_PIN);
    ntcTemp = 1.0 / (log (NTCSERIESRESISTOR / ((1024 / reading- 1) *
    THERMISTORNOMINAL)) / BCOEFFICIENT + 1.0 / (ntcTempERATURENOMINAL +
    273.15)) - 273.15 + offset;
    temp = ntcTemp * 10;
    Serial.print(temp / 10); Serial.print(".");
    Serial.print(temp % 10); Serial.print("\t");
    Serial.print(SeP / 10); Serial.print(".");
    Serial.print(SeP % 10); Serial.print("\t");
    Serial.println(err);
    err = constrain(SeP - temp,0,10); DC = err * tEnd / 10;
  }
  if(err <= 0)
    digitalWrite(pwrPin,LOW);
  else if(err >= 10)
    digitalWrite(pwrPin,HIGH);
  else    
    digitalWrite(pwrPin,millis() - tStart < DC);
    
  if(Serial.available() > 0)
    {
      SeP = Serial.parseInt();
      Serial.println(SeP / 10.0,1);
    }  
}