Hello,
I'm doing a little project to empty the water out of a bucket when the water is going to overflow.
When the high level is reached, the pump is started until the water goes under the low level.
https://photos.app.goo.gl/ZTmYnx8stNDWRabRA
The schema I use is as follow
Pin 2 and 3 correspond to high level and low level pin, are configured as INPUT_PULLUP and are grounded through a 10k resistor representing the resistance of the water.
The code I'm using is as follow
#define lowPin 2
#define highPin 3
#define greenLed 4
#define redLed 5
#define relayPin 6
void setup() {
pinMode(lowPin, INPUT_PULLUP);
pinMode(highPin, INPUT_PULLUP);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(relayPin, OUTPUT);
if (digitalRead(lowPin) and digitalRead(highPin)) {
digitalWrite(redLed, LOW);
digitalWrite(relayPin, HIGH);
digitalWrite(greenLed, HIGH);
} else
{
digitalWrite(redLed, HIGH);
digitalWrite(relayPin, LOW);
digitalWrite(greenLed, LOW);
}
}
void loop() {
while (digitalRead(lowPin) or digitalRead(highPin)){}
digitalWrite(redLed, HIGH);
digitalWrite(relayPin, LOW);
digitalWrite(greenLed, LOW);
while (!(digitalRead(lowPin) and digitalRead(highPin))){}
digitalWrite(redLed, LOW);
digitalWrite(relayPin, HIGH);
digitalWrite(greenLed, HIGH);
}
Now here is the issue : when the DC motor representing the pump is not plugged in, everything just works fine. The program waits for both pins to be grounded through the 10k (this correspond to full bucket). Then, then pump is switched on until both pins are high.
But with the motor, disconnecting one wire from the 10k resistor stops the motor immediately (instead of waiting for both the wires to be "ungrounded").
I'm completely puzzled as my motor circuit is completely isolated from the Arduino...
I also noticed that removing the 10k resistor (and connecting/disconnecting sensor pins directly to ground solves the problem), but it wiill be an issue within real circumstances
Any help would be greatly appreciated...
I also put a link to a video to demonstrate this issue.