Reading between GROUND and A0? or... What is this circuit doing?

I am having a cb designed to sense water ( conductivity to analog input ). I tried to design the circuit myself (I did make a simple prototype) but realized that, if I wanted to make a production stable system I would need some help. So this is the board that was designed, and now I am trying to understand what all its doing so that I can learn how to do it myself in the future. The designer has been very helpful, but I am not paying him to teach me, and I have already asked a dozen questions of him, so I figured I should ask the community some of these things.

In the attached image, you can see the ADC pin is marked, and a GND pin is next to it. In my prototype I used 3.3v first, then switched to GPIO pin set to high, to supply current, that was then sensed by ADC pin if water was present (~800 value) vs ~0 if no water.

But in the circuit designed here, it is GND and ADC for the two probes that would contact water. And I do not understand. I am very new.. about 3 weeks ago I got my first board, and built my first circuit, so following the board, and what its doing is... well its all a bit fuzzy.

Code. I do not have code yet for this board layout, but my prototype code was like this. (well... before I added the sleep stuff it worked with prototype... so just ignore the sleep part as it does not work right now.)

But my real question is just about sensing analog to ground.... am I reading the board wrong, am I missing something, or how does this work?


#include <LowPower.h>

static const int TRIGGER = 7;
const int ELECTRODE = 5;
const int analogInPin = A0;
int lastMillis = 0;
long onMills = 0;
long onDelay = -1;
long sense = -1;
bool switchState = false;
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value to output to a PWM pin
String sensorStr = "";

void setup() {
Serial.begin(4800);
pinMode(TRIGGER, OUTPUT);
}

void loop() { // local var: type declaration at compile time
digitalWrite(ELECTRODE, HIGH);
yield();
delay(100);
sense = millis() + 500;
while(sense > millis()) {
sensorValue = analogRead(analogInPin);
yield();
sensorStr = String(sensorValue);
Serial.println(sensorStr);

Serial.write(",");
Serial.write(sensorValue);
if(sensorValue > 950) {
onMills= millis() + 5000; // 1 seconds before turn off.
} else if (onMills < millis()) {
switchState = false;
}

while(sense < millis()) {
if (switchState) {
digitalWrite(TRIGGER, HIGH);
Serial.write("switch on");
} else {
Serial.write("no water sensed, going to sleep");
digitalWrite(TRIGGER, LOW);
digitalWrite(ELECTRODE, LOW);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
}

}

}

thanks for any thoughts / help

What is the function “ yield()” in your code ?

I think the designer of the board should specify what voltage ranges the analog output has; it is difficult to tell from the board picture.
For example, if you the voltage output is 0-12 V and use that directly, you could damage the Arduino.
You would need a voltage divider in this case.

Do you have a schematic?

Typically, you'd have a [u]voltage divider[/u] where one of the resistors is the resistance of the water.

It looks like you've got a relay and relay driver but I don't know what else...

Yes, it is 5v to everything on the right side of the board. 12-24 in, is dropped down to 5v at or near the U1 L1 markings. The bigger trace from that area that goes up to the top right (looking at the picture) pin on the relay and then to the rest of the board, is 5v.

the yield(); no bloody clue. I was trying to read analog after waking and was getting strange readings, so I tried delay, and i saw yield used somewhere.... something about handing control back to main loop... i dont know. but the code I will figure out later, not to worried about it yet. mostly just trying to understand this circuit better.

Dropbox link not working (shouldn't be used anyway).

yield() is an ESP8266 thing,
to give it's single core a breather to do WiFi things during (too) long executions of code.

Which Arduino are you actually using.
Reading a sensor with an ESP8266 board could be an issue,
because of the 100k:220k voltage divider present on the analogue input.
Need all the details to advise.
Leo..

The ESP8266 has a watchdog timer(WDT) that is turned on by default. If the watchdog timer isn't periodically reset then it will automatically reset your ESP8266. The watchdog is reset every time loop() runs or you call delay() or yield() but if you have blocking code then the watchdog may time out, resulting in a reset.

The delay() function doesn't cause WDT reset because it automatically calls yield() to prevent that.

You can reset the WDT inside your blocking code with:

ESP.wdt_reset()