Skip to content

Commit

Permalink
add new example for sensor health check
Browse files Browse the repository at this point in the history
  • Loading branch information
hasenradball committed Nov 24, 2023
1 parent c6b65b5 commit fc8956c
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions examples/AM2302_sensor_health_check/AM2302_sensor_health_check.ino
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: ");

Check failure on line 43 in examples/AM2302_sensor_health_check/AM2302_sensor_health_check.ino

View workflow job for this annotation

GitHub Actions / spellcheck

erros ==> errors
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

View workflow job for this annotation

GitHub Actions / spellcheck

timout ==> timeout

Check failure on line 46 in examples/AM2302_sensor_health_check/AM2302_sensor_health_check.ino

View workflow job for this annotation

GitHub Actions / spellcheck

erros ==> errors
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);
}

0 comments on commit fc8956c

Please sign in to comment.