Hello everyone,
Situation: i have DHT11 temp and humidity sensor which I get data from perfectly. Thing is, that I need to turn on first relay if temp is higher than 22, and other relay if humidity is more than 50. Problem is that it turns on and then after about 0.5 seconds turns off and it repeats like that. I'm transfering my data from arduino to matlab and plot temperature and humidity graphs with it but I don't think it has anything to do with this problem.
Here's my arduino code (some words are from my country but I think you should be able to understand everything):
#include <DHT11.h>
int pin=8;
DHT11 dht11(pin);
int dregmeON = 7;
int tempON = 6;
float tempRiba = 22;
float humiRiba = 50;
void setup()
{
pinMode(dregmeON, OUTPUT);
pinMode(tempON, OUTPUT);
Serial.begin(9600);
digitalWrite(dregmeON, HIGH);
digitalWrite(tempON, HIGH);
}
void loop()
{
int err;
float temp, humi;
if((err=dht11.read(humi, temp))==0)
{
//Serial.print("temperatūra:");
Serial.print(temp);
//Serial.print(" drėgmė:");
Serial.print(humi);
if(temp>tempRiba) {
Serial.print(1);
}
if(temp<tempRiba) {
Serial.print(0);
}
if(humi>humiRiba) {
Serial.print(1);
}
if(humi<humiRiba) {
Serial.print(0);
}
if(temp==tempRiba) {
Serial.print(0);
}
if(humi==humiRiba) {
Serial.print(0);
}
Serial.println();
}
else
{
Serial.println();
Serial.print("Error No :");
Serial.print(err);
Serial.println();
}
if(temp>tempRiba) {
digitalWrite(tempON, LOW);
}
if(temp<tempRiba) {
digitalWrite(tempON, HIGH);
}
if(humi>humiRiba) {
digitalWrite(dregmeON, LOW);
}
if(humi<humiRiba) {
digitalWrite(dregmeON, HIGH);
}
if(temp==tempRiba) {
digitalWrite(tempON, HIGH);
}
if(humi==humiRiba) {
digitalWrite(dregmeON, HIGH);
}
delay(1000);
}
and here is my matlab code which I dont think has anything to do with the problem:
s = serial('COM6');
laikas=100;
i=1;
while(i<laikas)
fopen(s)
%%fprintf(s, 'Čia perduodami duomenys')
out = fscanf(s);
Temp(i)=str2num(out(1:5));
subplot(211);
plot(Temp,'g');
axis([0,laikas,10,50]);
title('DHT11 Temperatūros rodmuo');
xlabel('---> Laikas*1,83 s');
ylabel('---> Temperatūra °C');
grid
Humi(i)=str2num(out(6:10));
subplot(212);
plot(Humi,'m');
axis([0,laikas,20,100]);
title('DHT11 Drėgmės rodmuo');
xlabel('---> Laikas*1,83 s');
ylabel('---> Drėgmė %');
grid
Temp(i)
Humi(i)
fclose(s)
i=i+1;
drawnow;
end
delete(s)
clear s