Analog Interrupt for detecting water

Is there a way to have an interrupt on an analog signal (using MKR GSM 1400)?

I'm creating a remote sensor project that would detect the presence of water and ping a server.

My actual sensor is essentially two metal contacts hooked to 3.3v and ground. When I submerge the sensor in water, the voltage increases, but only slightly. I'd like to have an interrupt based on some threshold I set. Is this possible?

I've also floated the idea of going into a deep sleep and using the timer interrupt to make periodic readings.

Thanks!

Do a search, using your favorite search engine, on the words ‘comparator circuit.’

greathow:
My actual sensor is essentially two metal contacts hooked to 3.3v and ground. When I submerge the sensor in water, the voltage increases, but only slightly. I'd like to have an interrupt based on some threshold I set. Is this possible?

Is it really necessary to use an interrupt? if you were 5 or 6 (or 60) millisecs late detecting the presence of water would it matter?

...R

I've never used interrupts.... And I don't know if you can set an analog threshold to trigger an interrupt... But are you sure you need one? What are you interrupting?

From what you've said, it's just reading continuously (or periodically) in a loop and if "something happens" you need "do something" (transmit a message). I don't see anything else going-on that you need to interrupt or anything time-sensitive where you'd have to interrupt whatever is going-on.

greathow:
using MKR GSM 1400
I'm creating a remote sensor project that would detect the presence of water and ping a server.

My actual sensor is essentially two metal contacts hooked to 3.3v and ground. When I submerge the sensor in water, the voltage increases, but only slightly.
Thanks!

Doubt you will get much help with the new MKR range of Arduinos at this stage.

I would think the voltage would decrease if you would do that,
unless you use two different metals and the water is acidic.
Did you use intenal pull up on the pin (assuming the MKR has that), or an external pull up resisor.
Leo..

Thanks for the replies. My thought was that I could possibly use an interrupt to wake from 'deep sleep' using the LowPower library. I'm mainly trying to optimize battery life. The timing isn't super sensitive, it just needs to detect the water in about 10-20 seconds.

As mentioned, perhaps an interrupt isn't necessary. I can probably just go into deep sleep for a while, and wake up periodically. It looks like LowPower.DeepSleep(milliseconds) would do the trick. I'll probably need to do some tests and check power consumption.

Wawa:
I would think the voltage would decrease if you would do that,
unless you use two different metals and the water is acidic.
Did you use intenal pull up on the pin (assuming the MKR has that), or an external pull up resisor.
Leo..

In my tests, I used an external pull-down resistor. When not submerged, it read 0 volts. When submerged, it read around .5 volts (if I recall correctly.)

If you want to measure resistivity of the water, and you have connected the sensor to pin and ground,
then you need a pull up resistor (between pin and 3.3volt).
The pin now should read max A/D value when not submerged, and a lower value when there is water between the contacts.
Don't convert to volts. It's not a volmeter you're making. Just work with the A/D values.
Experiment with the pull up resistor value, to get max differential readings. 10k is a good start.

You might want to connect the pull up resistor not to VCC (3.3volt), but to an output pin that you set HIGH just before reading the sensor.
That will minimise corrosion. Set the pin LOW again after the reading.
Leo..

Hi,
If you are looking at long time monitoring, like months/years, you will have corrosion problems with your sensor.

If you are detecting water, not moisture, you would be better off with a float switch.


Tom... :slight_smile:

greathow:
Thanks for the replies. My thought was that I could possibly use an interrupt to wake from 'deep sleep' using the LowPower library.

AFAIK for that to happen you need an external device that puts a HIGH voltage onto the Arduino interrupt pin. If the Arduino is asleep it can't monitor things.

Another option is to use the WatchDog timer to wake the Arduino at intervals and check the water state at (say) every 20th interval. You could probably arrange for it to be asleep for 90% of the time.

Have you seen Nick Gammon's low power tutorial?

...R

A float sensor, being basically a simple on/off switch, can provide the wake-up interrupt you're looking for.

Analog inputs don’t work in sleep modes, but you can have the Arduino sleep for about 8 seconds and wake using the watchdog timer. Make one measurement, then decide to sound the alarm or go back to sleep.

A “bare bones” Arduino could run like that on 2xAA batteries for a couple of years without battery replacement.

Agreed, Nick Gammon’s low power tutorial is an outstanding resource.