working soil sensor

This commit is contained in:
2021-04-10 23:17:56 +02:00
parent 42830e1200
commit 50dff40902
2 changed files with 29 additions and 5 deletions

View File

@@ -14,7 +14,7 @@
#if defined(USE_ARDUINO)
#define RH_RX_PIN 11
#elif defined(USE_ESPRESSIF)
#define RH_RX_PIN 12
#define RH_RX_PIN D8
#endif
#define RH_BUF_LEN 5
@@ -22,6 +22,9 @@ uint8_t rh_buf[RH_BUF_LEN];
#define RH_ASK_MAX_MESSAGE_LEN RH_BUF_LEN
const int AirValue = 800; //replace the value with value when placed in air
const int WaterValue = 345; //replace the value with value when placed in water
RH_ASK driver(RH_SPEED, RH_RX_PIN);
@@ -29,6 +32,7 @@ RH_ASK driver(RH_SPEED, RH_RX_PIN);
float t = 0;
float h = 0;
long bat = 0;
int soil = 0;
/**
* Message identifier constants:
@@ -37,6 +41,7 @@ long bat = 0;
#define MSG_TEMP 0x01
#define MSG_HUMID 0x02
#define MSG_BAT 0x03
#define MSG_SOIL 0x04
#define MSG_ERR 0xee
void setup() {
@@ -71,6 +76,14 @@ void loop() {
Serial.print(t);
Serial.println(" %");
break;
case MSG_SOIL:
// Soil Humidity:
Serial.println("0x04 Soil Humidity");
memcpy(&soil, &rh_buf[1], 2);
Serial.println(soil);
Serial.println(map(soil, AirValue, WaterValue, 0, 100));
break;
case MSG_BAT:
// battery data
Serial.println("0x03 Battery");