Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 4650846

Browse files
committed
korrektur Bodenfeuchte mappng
1 parent a87e362 commit 4650846

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/sensor.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,13 @@ void sensor::loop_hcsr04() {
190190
if (chan == 3 && this->ads1115_devices->at(i).topic_chan4.length()==0) continue;
191191

192192
raw = readADS1115Channel(&this->ads1115_devices->at(i), this->getAdsChannel(chan));
193-
level = map(raw, 0, 3300, 0, 100); // 0-3.3V -> 0-100%
193+
/* map voltage to a moisture-level
194+
* 0-3.3V -> 0-100%
195+
* moisture sensor gets 100% = dry, but we want a moisture: 100% = wet
196+
*/
197+
level = 100 - map(raw, 0, 3300, 0, 100); // 0-3.3V -> 0-100%
198+
if (Config->GetDebugLevel() >=4) Serial.printf("read moisture of ADS1115 (0x%02x) channel %d: raw: %d, calculated level: %d\n", this->ads1115_devices->at(i).i2cAddress, chan, raw, level);
199+
194200
String topic = "";
195201
switch (chan) {
196202
case 0:
@@ -234,15 +240,15 @@ void sensor::loop_hcsr04() {
234240
device->device.setCompareChannels(channel);
235241
device->device.startSingleMeasurement();
236242
while(device->device.isBusy()){}
237-
raw = device->device.getResultWithRange(-4096,4096);
243+
raw = device->device.getResultWithRange(-4096,4096, 3300);
238244
return (uint16_t) abs(raw);
239245
}
240246
#endif
241247

242248
void sensor::loop() {
243249
/*start measuring soil moisture, every 60sec */
244250
#ifdef USE_ADS1115
245-
if (millis() - this->previousMillis_moisture > 60*1000) {
251+
if (millis() - this->previousMillis_moisture > 5*1000) {
246252
this->previousMillis_moisture = millis();
247253
loop_ads1115_moisture();
248254
}

0 commit comments

Comments
 (0)