From 657ed1aab9980a465e59e9020404f2d562abca66 Mon Sep 17 00:00:00 2001 From: hasenradball Date: Tue, 23 Apr 2024 23:51:54 +0200 Subject: [PATCH] Add Example for ESP8266 with Sensor Array --- ...duino_Nano_AM2302_Sensor_Array_Example.ino | 9 +-- ...os_D1_mini_AM2302_Sensor_Array_Example.ino | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 8 deletions(-) create mode 100755 examples/Wemos_D1_mini_AM2302_Sensor_Array_Example/Wemos_D1_mini_AM2302_Sensor_Array_Example.ino diff --git a/examples/Arduino_Nano_AM2302_Sensor_Array_Example/Arduino_Nano_AM2302_Sensor_Array_Example.ino b/examples/Arduino_Nano_AM2302_Sensor_Array_Example/Arduino_Nano_AM2302_Sensor_Array_Example.ino index 6816972..3b4e73b 100644 --- a/examples/Arduino_Nano_AM2302_Sensor_Array_Example/Arduino_Nano_AM2302_Sensor_Array_Example.ino +++ b/examples/Arduino_Nano_AM2302_Sensor_Array_Example/Arduino_Nano_AM2302_Sensor_Array_Example.ino @@ -18,7 +18,7 @@ constexpr int PIN_1{4}; constexpr int PIN_2{11}; constexpr int PIN_3{12}; -// Create Sensor Object array with std:array +// Create Sensor Object array AM2302::AM2302_Sensor sensor_arr[SIZE] = { AM2302::AM2302_Sensor{PIN_1}, AM2302::AM2302_Sensor{PIN_2}, @@ -46,17 +46,10 @@ void setup() { void loop() { // put your main code here, to run repeatedly: - Serial.print("\tSensor Status : "); for (size_t i = 0; i < SIZE; ++i) { Serial.print(sensor_arr[i].read()); Serial.print("\t"); - //Serial.print("\tTemperature: "); - //Serial.print(sensor_arr[i].get_Temperature()); - //Serial.println(" °C"); - //Serial.print("\tHumidity: "); - //Serial.print(sensor_arr[i].get_Humidity()); - //Serial.println(" %\n\n"); } Serial.print("\n\tTemperature : "); for (size_t i = 0; i < SIZE; ++i) { diff --git a/examples/Wemos_D1_mini_AM2302_Sensor_Array_Example/Wemos_D1_mini_AM2302_Sensor_Array_Example.ino b/examples/Wemos_D1_mini_AM2302_Sensor_Array_Example/Wemos_D1_mini_AM2302_Sensor_Array_Example.ino new file mode 100755 index 0000000..d60272d --- /dev/null +++ b/examples/Wemos_D1_mini_AM2302_Sensor_Array_Example/Wemos_D1_mini_AM2302_Sensor_Array_Example.ino @@ -0,0 +1,71 @@ +/* +* Wemos_D1_mini_Sensor_Array_Example.ino +* +* Author: Frank Häfele +* Date: 23.04.2024 +* +* Objective: + Measure sensor data of AM2302-Sensor-Array with Arduino IDE. + Use 3 sensors and compare them with serial output +*/ + +#include +#include +#include + + +// Create Sensor Object array with std:array +std::array sensor_arr{ + AM2302::AM2302_Sensor{4}, + AM2302::AM2302_Sensor{5}, + AM2302::AM2302_Sensor{0} +}; + + +void setup() { + WiFi.mode(WIFI_OFF); + // put your setup code here, to run once: + Serial.begin(115200); + while(!Serial) { + yield(); + } + Serial.print(">>> Test Sensor Array of AM2302 (DHT22) Sensors <<<\n\n"); + delay(5000); + + for (size_t i = 0; i < sensor_arr.size(); ++i) { + Serial.print("Sensor "); + Serial.print(i); + Serial.print(" available - "); + Serial.println(sensor_arr[i].begin()); + } + Serial.print("\n"); + delay(3000); +} + +void loop() { + // put your main code here, to run repeatedly: + + Serial.print("\tSensor Status : "); + for (size_t i = 0; i < sensor_arr.size(); ++i) { + Serial.print(sensor_arr[i].read()); + Serial.print("\t"); + //Serial.print("\tTemperature: "); + //Serial.print(sensor_arr[i].get_Temperature()); + //Serial.println(" °C"); + //Serial.print("\tHumidity: "); + //Serial.print(sensor_arr[i].get_Humidity()); + //Serial.println(" %\n\n"); + } + Serial.print("\n\tTemperature : "); + for (size_t i = 0; i < sensor_arr.size(); ++i) { + Serial.print(sensor_arr[i].get_Temperature()); + Serial.print("\t"); + } + Serial.print("\n\tHumidity : "); + for (size_t i = 0; i < sensor_arr.size(); ++i) { + Serial.print(sensor_arr[i].get_Humidity()); + Serial.print("\t"); + } + Serial.print("\n\n"); + delay(10000); +}