DTH22(AM2320) With Photon


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);


void loop() {
        motion_detect = "Occupied";
        motion_detect = "Empty";

    //Publish data to the console and update the particle.variable
      Particle.publish("Room_K1", motion_detect, PRIVATE);
      movement_detected = digitalRead(D6);

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

	Serial.print("ID: ");
	Serial.print(", Temp: ");
	Serial.print(", Humi: ");

void publishToggle(){
    publish = 1;

I’d use this library to communicate with DHT22 sensors

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


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