Temperature control !!!

Hi,

I want to control temperature with DHT21 and SSR(solid State Relay). I am using Arduino nano. When I use the device ON-OFF mode LCD shows me temp. when heater is active LCD shows temperature value appears to be rising steadily, like this 35.1-35.2-35.3… when heater is not active LCD shows temperature value appears to be decreasing steadily, 35.3-35.2-35.1…

If I am programming to drive to SSR with PWM signal, LCD is like a mad. Temperature is not stable on LCD screen. 35.1-37.3-36.4-38.5…

I think the PWM signal affects the DHT21 data signal. because when I take of PWM signal wire, temperature value is stable on LCD screen or it changes steadily. What can I do?

DHT pin 2
PWM pin 11

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd {0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE};

#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);
int a;
void setup() {
  Serial.begin(9600);


  lcd.begin(16, 4);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("  Kaan Kulucka  ");
  lcd.setCursor(0, 1);
  lcd.print("   Sistemleri   ");
  delay(2000);

  dht.begin();
}
void loop() {

  float temp = dht.readTemperature();
  float hum = dht.readHumidity();

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("isi =");
  lcd.print(temp);
  lcd.print("C");

  lcd.setCursor(0, 1);
  lcd.print("Nem =");
  lcd.print(hum);
  lcd.print("%");
  delay(100);

if (temp < 35.7) {
    a = 0;
    analogWrite(11, a);
    }
  if (temp > 35.6 && temp < 37.7) {
    a = 255 - (37.7 - temp) * 255 / 2;
    analogWrite(11, a);
    }
  if (temp > 37.6) {
    a = 255;
    analogWrite(11, a);
    }
  Serial.print(a); Serial.print("--"); Serial.println(temp);
}

Probably because you can't drive a SSR with PWM.

Ok, that might not be true. Is this an AC or DC SSR? Is your heater powered from mains or DC? Please post a schematic.

What are you heating?

PerryBebbington:
Probably because you can’t drive a SSR with PWM.

Ok, that might not be true. Is this an AC or DC SSR? Is your heater powered from mains or DC? Please post a schematic.

What are you heating?

Hi, thank for answer. I will heating incubator. I am new for Arduino and I am trying something. SSR is for Arduino, it is working with 5V Dc and it is controlling 220V-AC. I tried PID but I couldn’t. this SSR working stable1-0 (on-OFF) mode.

You can't control mains like that, with PWM.

It worries me that you think you can, that tells me you don't know enough about mains to be messing with it.

I have a schematic but I couldn't share on this forum.

For what reason?

The way you do what you want to do is very slow PWM, which means you will probably have to write your PWM controller in software. You need the output to change state every few seconds. I don't know what the slowest speed you can get PWM to work on a Uno, but if it is not something like maybe 1/10 Hz then you will have to write code to do the PWM. Maybe aim for a cycle time of 10 to 20 seconds. You will have to experiment. minimum on and minimum off time maybe 1 second.

PerryBebbington:
For what reason?

The way you do what you want to do is very slow PWM, which means you will probably have to write your PWM controller in software. You need the output to change state every few seconds. I don't know what the slowest speed you can get PWM to work on a Uno, but if it is not something like maybe 1/10 Hz then you will have to write code to do the PWM. Maybe aim for a cycle time of 10 to 20 seconds. You will have to experiment. minimum on and minimum off time maybe 1 second.

I added the shematic after my message.

thanks for help

I added the schematic after my message.

Thank you.


How to post an image
Yes, it's a pain!

PerryBebbington:
Yes, it's a pain!

Pain ??? What ?

yusiskan:
Pain ??? What ?

The system for posting images in this web site is a pain!

Simple Edit, Copy & Paste with img tags, save. Takes 15 seconds.

URLs are worse, forum keeps adding characters to start and end of links, can't edit them out in Chrome ...