DTH22(AM2320) With Photon

Hello,

I don’t have experience in photon with DTH22 (AM2320) devices. I am planning to setup photon with humidity and temparature sensor. fine. But its returing zero
Connection details


AM2320 -1 pin connected to VBAT 
AM2320 -2 pin connected to D0 and 4.7ohm VBAT
AM2320 - 3 pin connected to GND
AM2320- 4 pin connected to D1 and 4.7ohm VBAT



I used AM2321.h file for implementation. Which is returning Temprature and humidity value as zero.

Code i used is below,

// This #include statement was automatically added by the Particle IDE.
#include <AM2321.h>
#include <application.h>
#include <Particle.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


AM2321 am2321;

char str[8];
unsigned long result = 0;
unsigned int temp, humi = 0;
unsigned int amID = 0;
String motion_detect;
int movement_detected = 0;
int publish_period = 5000; //Publish to console interval in ms
bool publish = 1;
double humidity = 0;
double tempf = 0;


//Initialize a timer to publish data to the console at an interval
Timer publishtimer(publish_period, publishToggle);

void setup() {
    pinMode(D6, INPUT_PULLDOWN);
    //Define a variable that's readable from a cURL (This is what gets published on the website)
    Particle.variable("MotionK1", movement_detected);
    Particle.variable("Humidity", humidity);
    Particle.variable("Temprature", tempf);

    publishtimer.start();
    am2321.begin();
    Serial.begin(9600);
}

void loop() {
    if(digitalRead(D6)==1){
        motion_detect = "Occupied";
    }
    else{
        motion_detect = "Empty";
    }

    //Publish data to the console and update the particle.variable
    if(publish){
      Particle.publish("Room_K1", motion_detect, PRIVATE);
      movement_detected = digitalRead(D6);
      Particle.publish("Humidity",String(humidity),PRIVATE);
      Particle.publish("Celsius",String(tempf),PRIVATE);
      publish=0;
    }

  amID = am2321.readID();
	result = am2321.readAll();
	humi = result>>16;
	temp = result&0xFFFF;

	Serial.print("ID: ");
	Serial.print(amID);
	Serial.print(", Temp: ");
	Serial.print(temp/10.0);
	Serial.print(", Humi: ");
	Serial.println(humi/10.0);
    delay(2000);
}


void publishToggle(){
    publish = 1;
}

I’d use this library to communicate with DHT22 sensors
https://build.particle.io/libs/PietteTech_DHT/0.0.5/tab/example/DHT_simple.ino

BTW, VBAT is not a power output. You should either use 3v3 or Vin

Hello,

Thank you very much for your response.
I have changed the pin to 3v3 and changed to D3 for SDA. But i am getting values -5.00.

If you are using the PietteTech library -5 suggests DHTLIB_ERROR_ACQUIRING
Have you left SCL floating - I have no AM2320 sensors that also feature a SCL pin so I’m not sure what’s happening when that pin is pulled high.
My DHT22 & DHT11 sensors only feature Vin, GND and SDA (some with a fourth pin N/C)

Hi, I just saw this and am working with DHT22 and AM2320.

I think the one I see in the pic above is the AM2320, but that is an I2C version - I think there could be some confusion here with the AM2302, which I believe is about the same as the DHT22

2 Likes