I want to build automatic irrigation system with two pumps and two moisture sensors. I want to achieve that each moisture sensor is connected to one pump. I was successful with one moisture sensor and pump, but I failed to achieve that for the second sensor. I tried to change the code in many ways, but nothing works. I would appreciate any help with this issue.
This is the code:
int relayPin = 4;
int relayPin1 = 3;
int sensor_pin = A0;
int sensor_pin1 = A1;
int output_value1;
int output_value;
void setup() {
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
pinMode(sensor_pin, INPUT);
pinMode(relayPin1, OUTPUT);
pinMode(sensor_pin1, INPUT);
Serial.println("Reading From the Sensor...");
delay(2000);
}
void loop() {
output_value = analogRead(sensor_pin);
output_value = map(output_value, 550, 10, 0, 100);
Serial.print(output_value);
Serial.println("%");
if (output_value < 20) {
digitalWrite(relayPin, HIGH);
} else {
digitalWrite(relayPin, LOW);
}
output_value1 = analogRead(sensor_pin1);
output_value1 = map(output_value1, 550, 10, 0, 100);
Serial.print(output_value1);
Serial.println("%");
if (output_value1 < 20) {
digitalWrite(relayPin1, HIGH);
} else {
digitalWrite(relayPin1, LOW);
}
delay(1000);
}
What do your Serial.prints look like? Are you powering the relays from the Arduino's 5V pin? How are you powering the Arduino? How are you supplying power for the pumps? What is the pumps' voltage and current ratings?
The Serial.print looks like this one sensor works another not
03:06:08.370 -> -11%
03:06:08.370 -> 101%
Yes, I am powering the relay from the Arduino 5V pin.
The Arduino Uno R4 Wifi is powered via USB to the computer.
The pumps are soldered with a USB cable, plugged into a 5v adapter and attached to the relay.
I use a mini submersible pump the voltage is DC 3V/6V, and for 5V the current is 120mA.
I tried to switch to another sensor.No luck. I used your code to upload. Same thing only one sensor works another just ignores everything. Especially the relay LED on first sensor it turns normally, but for the second it just stays on all the time.
If both sensors are dry, what do the read? If submerged in water? If you switch sensor1's wire to A1 and sensor2's wire to A0, what do they read? Post a photo of the sensors.
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
Have you written some simple code that JUST reads your moisture sensors, does nothing else, to prove your hardware connections.
If not then please do it to prove your input circuit/
Do you have a DMM? (Digital MultiMeter)
Can you please post a link to specs/data of your moisture sensor?
And you could remove the relays for the moment, and replace each with a LED with series current limiting resistor to see if you maybe have another issue.
The code looks OK from under the umbrella here.
One small change woukd make the diagnostic sketch output easier to interpret:
Hello everyone! I found the issue. It turns out that the second sensor was connected to Vin, but it was supposed to be connected to 3.3v. I fixed it and now everything works as a charm.