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
