Skip to content

Commit

Permalink
Add Example for ESP8266 with Sensor Array
Browse files Browse the repository at this point in the history
  • Loading branch information
hasenradball committed Apr 23, 2024
1 parent bd94e35 commit 657ed1a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <Arduino.h>
#include <AM2302-Sensor.h>
#include <ESP8266WiFi.h>


// Create Sensor Object array with std:array
std::array<AM2302::AM2302_Sensor, 3> 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);
}

0 comments on commit 657ed1a

Please sign in to comment.