-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new example for sensor health check
- Loading branch information
1 parent
c6b65b5
commit fc8956c
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
examples/AM2302_sensor_health_check/AM2302_sensor_health_check.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* AM2302-Sensor_Example.ino | ||
* | ||
* Author: Frank Häfele | ||
* Date: 24.11.2023 | ||
* | ||
* Object: Health check of AM2302-Sensor with Arduino IDE | ||
*/ | ||
|
||
#include <AM2302-Sensor.h> | ||
|
||
AM2302::AM2302_Sensor am2302{7}; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
while (!Serial) { | ||
yield(); | ||
} | ||
Serial.print(F("\n >>> AM2302-sensor Health Check <<<\n\n")); | ||
|
||
// put your setup code here, to run once: | ||
//set Pin | ||
am2302.begin(); | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
digitalWrite(LED_BUILTIN, LOW); | ||
} | ||
|
||
void loop() { | ||
static int checksum_err{0}, timeout_err {0}; | ||
// put your main code here, to run repeatedly: | ||
digitalWrite(LED_BUILTIN, HIGH); | ||
auto status = am2302.read(); | ||
if (status == AM2302::AM2302_ERROR_CHECKSUM) { | ||
++checksum_err; | ||
} | ||
if (status == AM2302::AM2302_ERROR_TIMEOUT) { | ||
++timeout_err; | ||
} | ||
Serial.print("\n\n"); | ||
Serial.print("status of sensor read(): "); | ||
Serial.println(status); | ||
|
||
Serial.print("Number checksum erros: "); | ||
Serial.println(checksum_err); | ||
|
||
Serial.print("Number timout erros: "); | ||
Check failure on line 46 in examples/AM2302_sensor_health_check/AM2302_sensor_health_check.ino GitHub Actions / spellcheck
|
||
Serial.println(timeout_err); | ||
|
||
Serial.print("\nTemperature: "); | ||
Serial.println(am2302.get_Temperature()); | ||
|
||
Serial.print("Humidity: "); | ||
Serial.println(am2302.get_Hunidity()); | ||
digitalWrite(LED_BUILTIN, LOW); | ||
delay(5000); | ||
} |