diff options
author | Alphara <42233094+xAlpharax@users.noreply.github.com> | 2023-11-04 12:59:53 +0000 |
---|---|---|
committer | Alphara <42233094+xAlpharax@users.noreply.github.com> | 2023-11-04 12:59:53 +0000 |
commit | 9cb5a1dab096ba3d7babe1fc2d2717f5cea65cb8 (patch) | |
tree | b24338efcbb2b9b2ebbe5a6225b034966edd0ffe /learning_examples/DHT_Unified_Sensor_esp32 | |
parent | 8b0b2077604d6bb7c6a5b5591ccd4d56e14e406a (diff) |
Indeed many changes to start off optimistically:]
Pretty much just learned how to use the board, the components, wiring of things and how to use a breadboard.
Also I have been really frustrated to learn that arduino ides and bunch of other things work absolutlely terrible under linux and not only. It even works buggy ways within Windows (i also tried legacy versions and achieved the same conclusion).
Anyways, not really much to detail other than my learning process.
Diffstat (limited to 'learning_examples/DHT_Unified_Sensor_esp32')
-rw-r--r-- | learning_examples/DHT_Unified_Sensor_esp32/DHT_Unified_Sensor_esp32.ino | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/learning_examples/DHT_Unified_Sensor_esp32/DHT_Unified_Sensor_esp32.ino b/learning_examples/DHT_Unified_Sensor_esp32/DHT_Unified_Sensor_esp32.ino new file mode 100644 index 0000000..f3a91e3 --- /dev/null +++ b/learning_examples/DHT_Unified_Sensor_esp32/DHT_Unified_Sensor_esp32.ino @@ -0,0 +1,85 @@ +// DHT Temperature & Humidity Sensor +// Unified Sensor Library Example +// Written by Tony DiCola for Adafruit Industries +// Released under an MIT license. + +// 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 <Adafruit_Sensor.h> +#include <DHT.h> +#include <DHT_U.h> + +#define DHTPIN 4 // Digital pin connected to the DHT sensor +// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 -- +// Pin 15 can work but DHT must be disconnected during program upload. + +// Uncomment the type of sensor in use: +//#define DHTTYPE DHT11 // DHT 11 +#define DHTTYPE DHT11 // DHT 22 (AM2302) +//#define DHTTYPE DHT21 // DHT 21 (AM2301) + +// See guide for details on sensor wiring and usage: +// https://learn.adafruit.com/dht/overview + +DHT_Unified dht(DHTPIN, DHTTYPE); + +uint32_t delayMS; + +void setup() { + Serial.begin(9600); + // Initialize device. + dht.begin(); + Serial.println(F("DHTxx Unified Sensor Example")); + // Print temperature sensor details. + sensor_t sensor; + dht.temperature().getSensor(&sensor); + Serial.println(F("------------------------------------")); + Serial.println(F("Temperature Sensor")); + Serial.print (F("Sensor Type: ")); Serial.println(sensor.name); + Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); + Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); + Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C")); + Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C")); + Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C")); + Serial.println(F("------------------------------------")); + // Print humidity sensor details. + dht.humidity().getSensor(&sensor); + Serial.println(F("Humidity Sensor")); + Serial.print (F("Sensor Type: ")); Serial.println(sensor.name); + Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); + Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); + Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%")); + Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%")); + Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%")); + Serial.println(F("------------------------------------")); + // Set delay between sensor readings based on sensor details. + delayMS = sensor.min_delay / 1000; +} + +void loop() { + // Delay between measurements. + delay(delayMS); + // Get temperature event and print its value. + sensors_event_t event; + dht.temperature().getEvent(&event); + if (isnan(event.temperature)) { + Serial.println(F("Error reading temperature!")); + } + else { + Serial.print(F("Temperature: ")); + Serial.print(event.temperature); + Serial.println(F("°C")); + } + // Get humidity event and print its value. + dht.humidity().getEvent(&event); + if (isnan(event.relative_humidity)) { + Serial.println(F("Error reading humidity!")); + } + else { + Serial.print(F("Humidity: ")); + Serial.print(event.relative_humidity); + Serial.println(F("%")); + } +} |