Okay I hope I renamed everything accordingly LoL
That is better, except that you overwrote the code in the previous post. That is frowned upon here. It makes posters look like idiots, commenting on code that looks perfectly OK by later readers.
Always post new code in a new reply.
You now turn the relay on or off in response to a UDP message. But, the whole idea behind UDP is that the sender sends them and doesn't care if anyone is listening, or not. So, you should not rely on getting a "Hey, turn the pump off, the well is dry" message.
You need to record when you turn the pump on. Are you sure that LOW turns the relay off? Most relay shields use LOW for on and HIGH for off.
unsigned long pumpOn = 0;
unsigned long pumpTime = 15000; // Run pump for 15 seconds
void loop()
{
// Get the packet
switch(ch)
{
case '0': // if 0 is sent via udp then do this -->>
digitalWrite(Relay, LOW); // Turn Relay Off
break;
case '1':
digitalWrite(Relay, HIGH);
pumpOn = millis();
break;
}
// Don't let the pump run forever
unsigned long now = millis();
if(pumpOn > 0) // Is pump on?
{
if(now - pumpOn > pumpTime)
{
// Turn the pump off
pumpOn = 0;
}
}
}