Hey whats up all.
Hope that its all good.
I need help with a project.
I want to help a farmer get water to his dam
So when the dam is empty the Arduino main unit should receive a input high for empty and low for full and forward the commands on to the second unit.
The units are connected over Ethernet to wireless antennas
The second unit receives the command switch on or off, but with this unit for safety reasons,so that the motor don't burn out, when switched on and connection was lost or main unit lost power, to switch off automatically after 1 min or if before the 1 min is over the command off is received to switch off
I do have a receiving code without the timer
#include <SPI.h>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // needed for Arduino versions later than 0018
#include <Ethernet.h>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Ethernet board connected
#include <EthernetUdp.h>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // UDP library from: bjoern@cs.stanford.edu 12/30/2008
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };Â Â Â Â // MAC Address
IPAddress ip(192, 168, 0, 10);Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // IP Address
unsigned int localPort = 8888;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Local IP port to listen on
byte gateway[] = { 192, 168, 0, 1 };Â Â Â Â Â Â Â Â Â Â Â Â // internet access via router
byte subnet[] = { 255, 255, 255, 0 };Â Â Â Â Â Â Â Â Â Â Â Â // Subnet Address
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];Â Â Â Â Â Â Â Â Â // buffer to hold incoming packet
EthernetUDP Udp;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // An EthernetUDP instance to let us send and receive packets over UDP
int Relay = A0;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Relay Pin A0
                       Â
                              Â
void setup() {Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // run setup only once on boot
 Ethernet.begin(mac,ip);                  // Enable Ethernet
 Udp.begin(localPort);                   // Start UDP Connection
 pinMode(Relay, OUTPUT);                  // Pin Mode
 Serial.begin(9600);                    // Start Serial Output
 Serial.write("SYSTEM BOOT");               // Send Power on to serial
 digitalWrite(Relay, LOW);                 // tell the pin to turn off
                             Â
      }                       // end of setup
void loop()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Start Running System
{
 int packetSize = Udp.parsePacket();            // if there's data available, read a packet
 if(packetSize)
 {
 int read = Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE); // read the packet into packetBufffer
  packetBuffer[read] = 0;
  char ch = packetBuffer[0];
switch(ch)
{
case '0':Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // if 0 is sent via udp then do this -->>
 digitalWrite(Relay, LOW);                 // Turn Relay Off
break;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // end of case 0
case '1':Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // if 1 is sent via udp then do this -->>
 digitalWrite(Relay, HIGH);                 // Turn Relay On
break;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // end of case 1
default :Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // if recived info via udp and not found in the case do this -->>
  Serial.print("No Case Found for: ");           // if case not found send info via serial
  Serial.print(ch);                    // send udp info back to serial
break;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // end of case not found
}
}
 delay(15);                        // waits 15ms for udp input wait ...
}Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // end system run, but now loop and start system run again