Hi Community,
Iam now working on my very first Arduino Project. Hardware is Uno R3, SMD and two AM2302 Sensors.
In short, I wish to measure Temperature and Humidity from an Outdoor and Indoor Sensor, to determine if ventilation is a good idea.
Indoor is a Basement with low Temperatures, so hot air at high Humidity from Outside will condensate when let into the cold Basement. And I want to avoid this.
To begin with, I started out with available Example Code and modified it to try reading two identical Sensors.
This resulted in the below:
/*
* AM2302-Sensor_Example.ino
*
* Author: Frank Häfele
* Date: 21.11.2023
*
* Object: Measure Sensor Data of AM2302-Sensor with Arduino IDE
*/
#include <AM2302-Sensor.h>
constexpr unsigned int O_SENSOR_PIN {7U};
AM2302::AM2302_Sensor Outdoor{O_SENSOR_PIN};
constexpr unsigned int I_SENSOR_PIN {8U};
AM2302::AM2302_Sensor Indoor{I_SENSOR_PIN};
void setup() {
Serial.begin(115200);
while (!Serial) {
yield();
}
Serial.print(F("\n >>> AM2302-Sensor_Example <<<\n\n"));
// set pin and check for sensor
if (Outdoor.begin()) {
// this delay is needed to receive valid data,
// when the loop directly read again
delay(3000);
}
else {
while (true) {
Serial.println("Error: Outdoor sensor check. => Please check sensor connection!");
delay(10000);
}
}
if (Indoor.begin()) {
// this delay is needed to receive valid data,
// when the loop directly read again
delay(3000);
}
else {
while (true) {
Serial.println("Error: Indoor sensor check. => Please check sensor connection!");
delay(10000);
}
}
}
void loop() {
// put your main code here, to run repeatedly:
auto status = Outdoor.read();
Serial.print("\n\nOutdoor sensor Status(): ");
Serial.println(status);
Serial.print("Outdoor Temperature: ");
Serial.print(Outdoor.get_Temperature());
Serial.println("°C");
Serial.print("Outdoor Humidity: ");
Serial.print(Outdoor.get_Humidity());
Serial.println("%RH");
// I tried to copy the content from line 58-60, to obtain similar functionality for Indoor Sensor. This doesn't work.
// auto status = Indoor.read();
// Serial.print("\n\nIndoor sensor Status(): ");
// Serial.println(status);
Serial.print("Indoor Temperature: ");
Serial.print(Indoor.get_Temperature());
Serial.println("°C");
Serial.print("Indoor Humidity: ");
Serial.print(Indoor.get_Humidity());
Serial.println("%RH");
delay(5000);
}
The Output looks like this:
Outdoor sensor Status(): 0
Outdoor Temperature: 25.30°C
Outdoor Humidity: 39.80%RH
Indoor Temperature: 25.10°C
Indoor Humidity: 40.60%RH
Unfortunately, the Indoor Sensor Data never changes, which indicates that I don’t read it properly.
I think that the problem originates from the
// auto status = Indoor.read();
If I uncomment this line, the following Error Message appears:
C:\Users\fnielsen\OneDrive - Agilent Technologies\Dokumenter\Arduino\AM2302_Sensor_Example2\AM2302_Sensor_Example2.ino: In function 'void loop()':C:\Users\fnielsen\OneDrive - Agilent Technologies\Dokumenter\Arduino\AM2302_Sensor_Example2\AM2302_Sensor_Example2.ino:73:9: error: conflicting declaration 'auto status'auto status = Indoor.read();^~~~~~C:\Users\fnielsen\OneDrive - Agilent Technologies\Dokumenter\Arduino\AM2302_Sensor_Example2\AM2302_Sensor_Example2.ino:58:9: note: previous declaration as 'signed char status'auto status = Outdoor.read();^~~~~~exit status 1
Compilation error: conflicting declaration 'auto status'
Basically, I don’t have any desire to use this way of reading the Sensors. If a less complicated way exists then I would prefer this, as long as I’m able to distinguish between Indoor and Outdoor.
Thank you for any help.
Best Regards,
Flemminglassen