DHT22 temperature reading with remote Xbee

Thread Starter

zazas321

Joined Nov 29, 2015
936
Hey. I am trying to make my Xbee router send temperature readings to coordinator. I have set up my Xbees as AT Router and API Coordinator and managed to get them talking to each other, I can write digital HIGH or LOW to a remote Xbee. However, I am having troubles sending my DHT22 temperature sensor reading my coordinator. I have tried following this guide:
Code:
#define DHTPIN 3     // what digital pin we're connected to
#include "DHT.h"
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);

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

  }
void loop() 
{ 
if (Serial.available() >=21) {
if (Serial.read() == 0x7E){ 
//skip over the API frame bytes we don’t want 
for (int i =0; i<19; i++) { 
  byte skip = Serial.read(); 
} 
  float t = dht.readTemperature();
   Serial.print(t); 
  delay(100);
I have tried setting my D3 pin of remote router both ADC and digital input - I am not getting anything printed on the serial monitor.

I believe I cannot use his approach when using my sensor, because based on his code, he is using MSB and LSB whereas in my case, I do not need to set these two bits.


Any ideas how to send temperature form remote Xbee to coordinator?
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Hey. I have been working on it but still no results. Here is more details about the setup:


As you can see, I have set my D3 as digital input and sampling rate as 3E8.
C:
#include "DHT.h"
#define DHTPIN 3 //D3 pin
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
void setup() {
dht.begin();
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
if(Serial.available()){
float temp= dht.readTemperature();
Serial.println(temp);}
delay(1000);
}
The output I get is nan
 

Attachments

Last edited:

Thread Starter

zazas321

Joined Nov 29, 2015
936
I have connected DHT22 to my microcontroller to test if the DHT22 is working:
C:
#include <DHTesp.h>
DHTesp dht;

#define DHTPIN 2 //D3 pin
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

void setup() {
dht.setup(DHTPIN, DHTesp::DHTTYPE);
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(dht.getMinimumSamplingPeriod());
  float temperature = dht.getTemperature();


Serial.println(temperature,1);
delay(1000);+

}
And it is working, I get a temeprature reading
 

Attachments

Top