smart_garden/src/capacitiveSoilMoistureSensor.cpp
2020-06-29 15:34:23 +02:00

28 lines
671 B
C++

/*
Code for the Capacitive Soil Moisture Sensor
*/
#include <header.h>
const int numReadings = 20;
void setupCapacitiveSoilMoistureSensor() {
// pinMode(PIN_MS, INPUT);
}
int readCapacitiveSoilMoistureSensor()
{
int total = 0; // the running total
// read from the sensor:
for (int readIndex = 0; readIndex < numReadings; readIndex++)
{
total = total + analogRead(PIN_MS);
delay(2);
}
int measurement = total / numReadings;
Serial.print("soil moisture raw: ");
Serial.println(measurement);
// add the reading to the total:
//int measurement = analogRead(PIN_MS);
return map(measurement, VALUE_AIR, VALUE_WATER, 0, 100);
}