28 lines
671 B
C++
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);
|
|
} |