@@ -190,7 +190,13 @@ void sensor::loop_hcsr04() {
190
190
if (chan == 3 && this ->ads1115_devices ->at (i).topic_chan4 .length ()==0 ) continue ;
191
191
192
192
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
+
194
200
String topic = " " ;
195
201
switch (chan) {
196
202
case 0 :
@@ -234,15 +240,15 @@ void sensor::loop_hcsr04() {
234
240
device->device .setCompareChannels (channel);
235
241
device->device .startSingleMeasurement ();
236
242
while (device->device .isBusy ()){}
237
- raw = device->device .getResultWithRange (-4096 ,4096 );
243
+ raw = device->device .getResultWithRange (-4096 ,4096 , 3300 );
238
244
return (uint16_t ) abs (raw);
239
245
}
240
246
#endif
241
247
242
248
void sensor::loop () {
243
249
/* start measuring soil moisture, every 60sec */
244
250
#ifdef USE_ADS1115
245
- if (millis () - this ->previousMillis_moisture > 60 *1000 ) {
251
+ if (millis () - this ->previousMillis_moisture > 5 *1000 ) {
246
252
this ->previousMillis_moisture = millis ();
247
253
loop_ads1115_moisture ();
248
254
}
0 commit comments