I have 6 relays hooked to my Arduino mega. the relays get triggered by 6 different moisture sensors and when one moisture sensor goes dry the mega triggers multiple relays for 10 seconds then shuts of all the relays but the one that is supposed to be triggered.
AWOL:
Such a shame some of us can't see your code.
Im sorry you cant see my code. I added it as a link as I can not post it because it is over the 9000 word limit . please download the code and view it that way. I don't make the limits . again download the attached code to view .
Are you shure this is correct? Most of relay modules use inverted logic. They engaged when input signal is Low.
Switch off all your relays in Setup()
I understand your logic on when the relay should be off and should be on but for this instance it makes no difference as I can change the NO and NC positions to work one way or the other. what im interested in is why three to four relays come on when only getting signal from one moisture sensor. so again ill explain.
I have six relays that are triggered by IF, IF ELSE statements.
// Read the input on analog pin 10
int waterSensor1 = analogRead(A10);
// Water sensor 1 relay control
if (waterSensor1 <= 1000)
{
digitalWrite(waterPin1, HIGH); // turn on relay
}
else if (waterSensor1 >= 500)
{
digitalWrite(waterPin1, LOW); // turn off relay
}
// Read the input on analog pin 11
int waterSensor2 = analogRead(A11);
// Water sensor 2 relay control
if (waterSensor2 <= 1000)
{
digitalWrite(waterPin2, HIGH); // turn on relay
}
else if (waterSensor2 >= 500)
{
digitalWrite(waterPin2, LOW); // turn off relay
}
// Read the input on analog pin 12
int waterSensor3 = analogRead(A12);
// Water sensor 3 relay control
if (waterSensor3 <= 1000)
{
digitalWrite(waterPin3, HIGH); // turn on relay
}
else if (waterSensor3 >= 500)
{
digitalWrite(waterPin3, LOW); // turn off relay
}
// Read the input on analog pin 13
int waterSensor4 = analogRead(A13);
// Water sensor 4 relay control
if (waterSensor4 <= 1000)
{
digitalWrite(waterPin4, HIGH); // turn on relay
}
else if (waterSensor4 >= 500)
{
digitalWrite(waterPin4, LOW); // turn off relay
}
// Read the input on analog pin 14
int waterSensor5 = analogRead(A14);
// Water sensor 5 relay control
if (waterSensor5 <= 1000)
{
digitalWrite(waterPin5, HIGH); // turn on relay
}
else if (waterSensor5 >= 500)
{
digitalWrite(waterPin5, LOW); // turn off relay
}
// Read the input on analog pin 15
int waterSensor6 = analogRead(A15);
// Water sensor 6 relay control
if (waterSensor6 <= 1000)
{
digitalWrite(waterPin6, HIGH); // turn on relay
}
else if (waterSensor6 >= 500)
{
digitalWrite(waterPin6, LOW); // turn off relay
}
my problem Is that when I have input from the moisture sensor of any input it triggers multiple relay for on cycle and then upon the next cycle it shuts all but the desired relay off. so essentially for 10 seconds each triggered cycle all of the relay go high for 10 seconds and the n again upon the next cycle only the required relay stays on. I could delay only one second but this is not a desired solution.
// Begin DHT11
dht.begin();
// Begin TFT
tft.begin();
If you cut out the ~~dumb~~ pointless comments and maybe factored your code, you could've fit it into a regular post.
(I don't make the limits either)
AWOL, im not here to argue. im here looking for help finding a solution. I appreciate your feedback but if I remove all of the comments then the code becomes unreadable to most. if you have help that you can't give without the code being posted directly I would appreciate it. If not I can surely modify it. I am not stupid yet I am no WIZ at the logic of coding this is why im asking for help not giving it.
No, if you remove the comments that obviously repeat what the executable code says, you make the code more legible to anyone who can read it. (Less fluff (or "lint", for the Atlantically-challenged))
If your code can be posted in code tags on the forum, more people can, and will, read it.
everone:
I understand your logic on when the relay should be off and should be on but for this instance it makes no difference as I can change the NO and NC positions to work one way or the other. what im interested in is why three to four relays come on when only getting signal from one moisture sensor. so again ill explain.
I have six relays that are triggered by IF, IF ELSE statements.
As I said already - - Switch off all your relays in Setup()
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
What happens to your moisture readings from the analogRead when the sensor gets wet(ter)?
Thanks.. Tom...
Hello Tom,
I am using Flying Fish MH series sensors from Amazon. I have matched 6 sensors so that they read the same values for wet and dry. dry the sensors read 1000 and above and the readings go lower as they get wetter.
Im sorry about the Circuit. it is way to complicated to draw.
if (waterSensor1 <= 1000)
{
digitalWrite(waterPin1, HIGH); // turn on relay
}
else if (waterSensor1 >= 500)
{
digitalWrite(waterPin1, LOW); // turn off relay
}
.
.
.
If sensor 1 is less than 1001 it is cleared to turn on but you also want it off if the value is over 499. Are you sure those are the values you want?
I read this as follows.
If water sensor one is less than or equal to 1000 write digital pin 32 high (turn on relay one) else if water sensor one is greater than or equal to 500 writhe digital pin 32 low (turn relay one off).
If the sensor is dry turn the water on or if the sensor is wet turn the water off.
everone:
I read this as follows.
If water sensor one is less than or equal to 1000 write digital pin 32 high (turn on relay one) else if water sensor one is greater than or equal to 500 writhe digital pin 32 low (turn relay one off).
If the sensor is dry turn the water on or if the sensor is wet turn the water off.
Is this how it reads to you?
So what happens when the water sensor reads 750? In your implementation that is less than 1000 and so the pin is set high. Because the first if is true, the "else" never gets executed and the ">= 500" code won't run.
as the soil dries out, the analog sensor value climbs until it hits 1000; water valve on
the soil moisture content gets higher and higher and the sensor output drops; when it hits 500, the soil
moisture content is sufficiently high; water valve off