src/main.cpp
// Returns a moisture value between 0 and 100, where 0 is dryest and 100 is fully submersed
Returns a moisture value between 0 and 100, where 0 is dryest and 100 is fully submersed
Returns a moisture value between 0 and 100 where 0 is dryest and 100 is fully submersed
void updateMoistureReadings() {
  digitalWrite(PIN_MOISTURE_VCC, HIGH); 
  delay(100); 
  for (int i = 0; i < NUM_MOISTURE_SENSORS; i++) {
    int adc = analogRead(PINS_MOISTURE[i]);
    if (adc >= MAX_MOISTURE_VALUE && adc <= MIN_MOISTURE_VALUE) {
      sensorReadings.moisture[i] = uint(map(adc, MIN_MOISTURE_VALUE, MAX_MOISTURE_VALUE, 0, 100));
    }
  }
  digitalWrite(PIN_MOISTURE_VCC, LOW); 
  int avgMoisture = 0;
  for (int i = 0; i < NUM_MOISTURE_SENSORS; i++) {
    avgMoisture += sensorReadings.moisture[i];
  }
  sensorReadings.avgMoisture = (uint) round(avgMoisture / NUM_MOISTURE_SENSORS);
}
void updateMoistureReadings ( ) { digitalWrite ( PIN_MOISTURE_VCC , HIGH ) ; delay ( 100 ) ; for ( int i = 0 ; i < NUM_MOISTURE_SENSORS ; i ++ ) { int adc = analogRead ( PINS_MOISTURE [ i ] ) ; if ( adc >= MAX_MOISTURE_VALUE && adc <= MIN_MOISTURE_VALUE ) { sensorReadings . moisture [ i ] = uint ( map ( adc , MIN_MOISTURE_VALUE , MAX_MOISTURE_VALUE , 0 , 100 ) ) ; } } digitalWrite ( PIN_MOISTURE_VCC , LOW ) ; int avgMoisture = 0 ; for ( int i = 0 ; i < NUM_MOISTURE_SENSORS ; i ++ ) { avgMoisture += sensorReadings . moisture [ i ] ; } sensorReadings . avgMoisture = ( uint ) round ( avgMoisture / NUM_MOISTURE_SENSORS ) ; }
Returns a moisture value between 0 and 100, where 0 is dryest and 100 is fully submersed
Returns a moisture value between 0 and 100 where 0 is dryest and 100 is fully submersed
// Turn the sensors on // Small delay to make sure the sensor(s) have power // Read from the available moisture sensors and  // If we got an erroneous reading, just disregard it // Map the analog value to a value between 0 and 100 for easier reading // Turn the sensors off again // Get the average value of all moisture sensors