Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KC868-A4 dht22 problem
#1
i'm using a dht22 and input 1 and output1.
i made a simple code where i'm showing the dht22 value in the serial monitoring and  when the intput1 is colsed i made the output1 in the ON state, and if the input1 is open the ouptput1 is OFF.
in the simulation everting work fine and the value of the dht22 sonsor is correct.

but when i add an lamp in the output1 and turn it on and off the value of the dht22 becomes null.
i tried to modify the code like add a delay... but no result. dht22 becomes null.

 here is my simple source code:
Code:
#define output1 4
#define input1   36


#include "DHT.h"
#define DHTPIN 13     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE);



int temperatureSonde=0;

void setup() {
 
  Serial.begin(9600);
dht.begin();

pinMode(output1,OUTPUT);
pinMode(input1,INPUT);
}

int loading=0;

void loop() {

if (digitalRead(input1)==0 && digitalRead(output1)==0){digitalWrite(output1,1);
//delay(100);
}
else if(digitalRead(input1)==1 && digitalRead(output1)==1){digitalWrite(output1,0);
//delay(100);
}


/*********************humidity***************************/
// Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very s0 sensor)
  float h = dht.readHumidity();


  // Check if any reads failed and exit early (to try again).
  if (isnan(h) ) {
      Serial.println("Failed to read from DHT sensor!");
    }


  Serial.print(F("Humidity: "));
  Serial.println(int(dht.readHumidity()));

/********************************************************/





delay(100);

}// end loop()
Reply
#2
do you have replaced another power supply for a test. or let your lamp long distance with the board?
read DHT22 need time, maybe larger time of your delay.
Reply
#3
i tried all the possibilities(change lots of power supplies, add delay and change time of delay...)
everything work fine if the outputs are empty but when i add something in the output the dht22 value becomes null.
please if you have a KC868-A4 and a sonsor try it by yourself.
Reply
#4
ok, we can test it. Do your load work with AC220V?
Reply
#5
I used a dc 12v relay and the lamp 220v. 
I took pictures for what im using. 
I give the KC868-A4 his own power supply but no change.


Attached Files Image(s)
           
Reply
#6
we have tested , no problem with hardware. i think you can check your source code. 
here is our test code work with DHT11 sensor.
Code:
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
#include <DHT.h>
#define output1 4
#define input1   36
DHT dht13(13, 11);

void setup() {

  Serial.begin(9600);
  dht13.begin();

pinMode(output1,OUTPUT);
pinMode(input1,INPUT);
}


void loop() {
Serial.println(dht13.readTemperature());
delay(1000);
if (digitalRead(input1)==0 && digitalRead(output1)==0){digitalWrite(output1,1);
//delay(100);
}
else if(digitalRead(input1)==1 && digitalRead(output1)==1){digitalWrite(output1,0);
//delay(100);


}// end loop()
}
   
   
   
Reply
#7
The problem comes when turn in on and off many times.
For me the second or the third times the value becomes null.

I will try with the same code and try to see where the problem comes

i tried withe same code as yours, the diffrent is that i used dht22.
when i close and open the input many times, the values becomes nan.


Attached Files Image(s)
           
Reply
#8
now i removed the dc 12V relay and it works without problem.
without your test i couldn't think that the problem comes from this relay
Reply
#9

You can try this:
Code:
#include "DHT.h"

#define output1 4
#define input1   36

int Temperature = 0;
int Humidity = 0;

#define DHTPIN 13     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

unsigned long SwitchReadloop = millis();
long SwitchReadloopint = 20; //you can change the time duration as you need loop time (in millisec)

unsigned long Temploop = millis();
long Temploopint = 2000; //you can change the time duration as you need loop time (in millisec)


void setup() {

Serial.begin(9600);
dht.begin();

pinMode(output1,OUTPUT);
pinMode(input1,INPUT);
pinMode(DHTPIN, INPUT);
}

void loop() {

unsigned long CurrentTime = millis();

if(CurrentTime - SwitchReadloop > SwitchReadloopint){
    SwitchReadloop = CurrentTime;

if (digitalRead(input1)==LOW && digitalRead(output1)==LOW)
{
digitalWrite(output1,HIGH);
}

else if(digitalRead(input1)==HIGH && digitalRead(output1)==HIGH)
{
digitalWrite(output1,LOW);
}

}

/*********************humidity***************************/
// Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very s0 sensor)

if(CurrentTime - Temploop > Temploopint){
    Temploop = CurrentTime;

  float h = dht.readHumidity();
  float t = dht.readTemperature();


  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

else{
Humidity = h;
Temperature = t; // data in *Celcius
}

Serial.print("Humidity: ");
  Serial.println(Humidity);

  Serial.print("Temperature: ");
  Serial.println(Temperature);
}

}// end loop()
(03-13-2023, 11:19 PM)Joseph.o Wrote: i'm using a dht22 and input 1 and output1.
i made a simple code where i'm showing the dht22 value in the serial monitoring and  when the intput1 is colsed i made the output1 in the ON state, and if the input1 is open the ouptput1 is OFF.
in the simulation everting work fine and the value of the dht22 sonsor is correct.

but when i add an lamp in the output1 and turn it on and off the value of the dht22 becomes null.
i tried to modify the code like add a delay... but no result. dht22 becomes null.

 here is my simple source code:
Code:
#define output1 4
#define input1   36


#include "DHT.h"
#define DHTPIN 13     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE);



int temperatureSonde=0;

void setup() {
 
  Serial.begin(9600);
dht.begin();

pinMode(output1,OUTPUT);
pinMode(input1,INPUT);
}

int loading=0;

void loop() {

if (digitalRead(input1)==0 && digitalRead(output1)==0){digitalWrite(output1,1);
//delay(100);
}
else if(digitalRead(input1)==1 && digitalRead(output1)==1){digitalWrite(output1,0);
//delay(100);
}


/*********************humidity***************************/
// Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very s0 sensor)
  float h = dht.readHumidity();


  // Check if any reads failed and exit early (to try again).
  if (isnan(h) ) {
      Serial.println("Failed to read from DHT sensor!");
    }


  Serial.print(F("Humidity: "));
  Serial.println(int(dht.readHumidity()));

/********************************************************/





delay(100);

}// end loop()
Reply
#10
i am not have DHT22 sensor, only have DHT11 sensor. i suggest you replace another sensor for a test.
A4 board have many users, no one feedback this problem.
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)