Hello All,
I choose to measure soil moisture with a Watermark sendor and an electric interface for Watermark (SMX)
The SMX give 3 options to read the result: Voltage, courent and frequency.
Look at the page 3, first schema. There is a small paragraph about freuency output.
I created my breadboard but I have not test it yet because I have no expertise to develop a code to read the frequency with a digital read.
I wonder if PulseIN or FreqCounter would help me read frequency on a digital pin connected to my sensor
It's look like FreqCounter whatch a Digital pin and return the frequency. That righ?
Someone can share an expemple or an experience?
Thank a lot
Here is an example of how to determine the frequency of an input. Put a frequency up to 28kHz into a digital pin, and an Arduino will output the frequency to the serial monitor:
// input pin can be any digital input
const byte inputPin = 2;
boolean inputState = false;
boolean lastInputState = false;
long count = 0L;
unsigned long previousCountMillis = millis();
const long countMillis = 500L;
void setInputState() {
inputState = digitalRead(inputPin);
}
void setup() {
pinMode(inputPin, INPUT);
Serial.begin(115200);
}
void loop() {
// runs every time thru the loop
setInputState();
// count every transision HIGH<->LOW
if (inputState != lastInputState) {
count++;
lastInputState = inputState;
}
// ------- every half second, count is equal to Hz.---------------
if (millis() - previousCountMillis >= countMillis) {
previousCountMillis += countMillis;
// show Hz on Serial too if available
Serial.print(count);
Serial.println(" Hz");
// reset to zero for the next half second's sample
count = 0L;
}
}