Trip relay(s) when a device is discovered on LAN

I’ve been researching this a lot over the last couple of days and i’m surprised that I haven’t found a solution. I keep ending up on labby.co.uk but it seems the project has been removed.

I am looking for code to trip two relays when a phone is connected to the local network which will open a garage door one to provide power and the other to activate the switch. (the garage door opens on its own if it is left plugged in)

I know that this has been done before however each project that I’ve found has since been abandoned and I have not been able to get it to work properly. I would think this project would be popular within the home automation realm so I am hoping to be pointed in the right direction.

I’m using Arduino Uno with an Ethernet shield.

-Respectfully, allthenamesweretaken

Maybe this topic isn’t as popular as I thought it would be.

Here is the code that I’ve come up with in case anyone is interested. PM me if you need support.

Maybe this topic isn’t as popular as I thought it would be.

Here is the code that I’ve come up with in case anyone is interested. PM me if you need support.

#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
/* YourDuino Example: Relay Control 1.10
Handles “Relay is active-low” to assure
no relay activation from reset until
application is ready.
terry@yourduino.com /
/
-----( Import needed libraries )-----/
/
-----( Declare Constants )-----/
#define RELAY_ON 0
#define RELAY_OFF 1
/
-----( Declare objects )-----/
/
-----( Declare Variables )-----/
#define Relay_1 2 // Arduino Digital I/O pin number
#define Relay_2 3
/

Ping Example
This example sends an ICMP pings every 500 milliseconds, sends the human-readable
result over the serial port.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 30 Sep 2010
by Blake Foster
/
#include <SPI.h>
#include <Ethernet.h>
#include <ICMPPing.h>
#include <Twitter.h>
Twitter twitter(“xxxxxxxxxxxxxxxxxxxxx”);
char aopen[] = “Garage door open!”;
char aclosed[] = “Garage door closed!”;
/
-----( Declare Variables )-----*/
#define Relay_1 2 // Arduino Digital I/O pin number
#define Relay_2 3
byte mac = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // max address for ethernet shield
byte ip = {10,0,0,6}; // ip address for ethernet shield
IPAddress pingAddr(10,0,0,72); // ip address to ping
SOCKET pingSocket = 0;
char buffer [256];
ICMPPing ping(pingSocket, (uint16_t)random(0, 255));
void setup()
{
//-------( Initialize Pins so relays are inactive at reset)----
digitalWrite(Relay_1, RELAY_OFF);
digitalWrite(Relay_2, RELAY_OFF);
//—( THEN set pins as outputs )----
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
delay(500); //Check that all relays are inactive at Reset
// start Ethernet
Ethernet.begin(mac, ip);
Serial.begin(9600);
}
void loop()
{
ICMPEchoReply echoReply = ping(pingAddr, 4);
if (echoReply.status == SUCCESS)
{
sprintf(buffer,
“Reply 1[%d] from: %d.%d.%d.%d: bytes=%d time=%ldms TTL=%d”,
echoReply.data.seq,
echoReply.addr[0],
echoReply.addr[1],
echoReply.addr[2],
echoReply.addr[3],
REQ_DATASIZE,
millis() - echoReply.data.time,
echoReply.ttl);
}
else
{
sprintf(buffer, “Echo request failed1; %d”, echoReply.status);
delay(250);
ICMPEchoReply echoReply = ping(pingAddr, 4);
// After ping is unsuccessful (phone offline) check again so that the garage door cycles only when the phone is first
//offline then online so that it doesn’t continue the open/close cycle during the entire time the phone is online
if (echoReply.status == SUCCESS)
{

sprintf(buffer,
“Reply[%d] from: %d.%d.%d.%d: bytes=%d time=%ldms TTL=%d”,
echoReply.data.seq,
echoReply.addr[0],
echoReply.addr[1],
echoReply.addr[2],
echoReply.addr[3],
REQ_DATASIZE,
millis() - echoReply.data.time,
echoReply.ttl);

digitalWrite(Relay_1, RELAY_ON);// turn on power
delay(500); //wait for a 1/2 second
digitalWrite(Relay_2, RELAY_ON);// press button to open
delay(500); //wait for a 1/2 second
digitalWrite(Relay_2, RELAY_OFF);// depress button to open door
delay(500); //wait 180 seconds to open door
digitalWrite(Relay_2, RELAY_ON);// press button to close
delay(500); //wait for a 1/2 second
digitalWrite(Relay_2, RELAY_OFF);// depress button to close
delay(500); //wait for a 1/2 second
// wait for a second
digitalWrite(Relay_1, RELAY_OFF);// kill power
delay(500);
}
sprintf(buffer, “Echo request failed2; %d”, echoReply.status);

}
Serial.println(buffer);
delay(500);
}