search

Testing AM2302 (DTH22) on Adafruit Feather HUZZAH (step 3)


For this, I purchased:

solderless breadboard (3 pack) – $9.99 eachhttps://www.amazon.com/gp/product/B01EV6LJ7G

Adafruit AM2302 temperature & humidity sensor – $15 eachhttps://www.adafruit.com/product/393

 

Connect the AM2302 sensor to the Feather using the breadboard:

Download the DHT-sensor-library from Adafruit’s Github

Unzip and place the folder in

On a PC:   /Program Files (x86)/Arduino/libraries/DHT-sensor-master-library

On a Mac:   /Documents/Arduino/libraries/DHT-sensor-master-library

Sketch –> Include Library –> Manage Libraries

Search for “Adafruit Unified” and install “Adafruit Unified Sensor“.

File –> Open –> browse to

On a PC:   /Program Files (x86)/Arduino/libraries/DHT-sensor-master-library/examples/DHTtester/DHTtester.ino

On a Mac:   /Documents/Arduino/libraries/DHT-sensor-master-library/examples/DHTtester/DHTtester.ino

Be sure to set the correct data pin (second line of code) and upload to the Feather.

After it uploads, click Tools –> Serial Monitor

You should now see temperature and humidity data refreshing on your screen every 2 seconds. Since the data pin is pin #2, the same as the blue LED, it blinks with each read.

 

DHTester.ino


// Example testing sketch for various DHT humidity/temperature sensors // Written by ladyada, public domain #include "DHT.h" #define DHTPIN 2 // what digital pin we're connected to // Uncomment whatever type you're using! //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); dht.begin(); } void loop() { // Wait a few seconds between measurements. delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) float f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) || isnan(f)) { Serial.println("Failed to read from DHT sensor!"); return; } // Compute heat index in Fahrenheit (the default) float hif = dht.computeHeatIndex(f, h); // Compute heat index in Celsius (isFahreheit = false) float hic = dht.computeHeatIndex(t, h, false); Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.print(" *C "); Serial.print(f); Serial.print(" *F\t"); Serial.print("Heat index: "); Serial.print(hic); Serial.print(" *C "); Serial.print(hif); Serial.println(" *F"); }

 

close
search

Hi, guest!

settings

menu