Ethernet controlled LED HELP?

I am trying to control an led on my arduino from a PHP script on another website, but I cannot find anything to do this on Google. I've looked everywhere and there just doesn't seem to be a basic tutorial on how to do this. I would greatly appreciate if someone who knew how to do this could tell me. PLEASE HELP SOON. XD XD XD XD

You need to explain in more detail your desired setup. Are you going to use an ethernet shield on your arduino?

Hi,

Please try this:

<?php
    $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    $msg = "Hello";
    $len = strlen($msg);

    socket_sendto($sock, $msg, $len, 0, '192.168.1.25', 12345);
    socket_close($sock);
?>

in this example "192.168.1.25" is destination IP address, "12345" is UDP port

Because this is very interesting for me too I try to expand…
Just provide some test and all work :slight_smile:

  1. I upload on my server two PHP files. LED1_ON.php and LED1_OFF.php

LED1_ON.php

<?php
    $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    $msg = "FF0101";
    $len = strlen($msg);

    socket_sendto($sock, $msg, $len, 0, 'xxx.xxx.xxx.xxx', 12345);
    socket_close($sock);
?>
<?php
    $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

    $msg = "FF0100";
    $len = strlen($msg);

    socket_sendto($sock, $msg, $len, 0, 'xxx.xxx.xxx.xxx', 12345);
    socket_close($sock);
?>
  1. Arduino Ethernet (with ENC28J60) have connected to IP 'xxx.xxx.xxx.xxx'
    It has 4 relays (leds) connected to board.
    Here is code:
#include "EtherShield.h"

uint8_t mymac[6] = {0x00,0x70,0x7C,0xE4,0x8A,0xB8};
uint8_t myip[4] = {xx,xx,xx,xx};

#define BUFFER_SIZE 750
static uint8_t buf[BUFFER_SIZE+1]; 

EtherShield es=EtherShield();

uint16_t plen, dat_p;

///----------------------------------------------------------
void setup(){
  
  Serial.begin(9600); 
  pinMode(5, OUTPUT); 
  pinMode(6, OUTPUT); 
  pinMode(7, OUTPUT); 
  pinMode(8, OUTPUT); 
  es.ES_enc28j60Init(mymac);
  es.ES_init_ip_arp_udp_tcp(mymac,myip, 80);

} // end setup
///----------------------------------------------------------
void loop(){
  
    // read packet, handle ping and wait for a tcp packet:
    dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
    
    if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){          // We have UDP packet !
       Relay_Control();
       buf[IP_PROTO_P]=0;
    }    
    
} // end loop

void Relay_Control(){
                    
  if ((buf[42]=='F')&(buf[43]=='F')){

      if ((buf[44]=='0')&(buf[45]=='1'))  // Relay 01
         {
         if ((buf[46]=='0')&(buf[47]=='1')) digitalWrite(8, 1);
         if ((buf[46]=='0')&(buf[47]=='0')) digitalWrite(8, 0);
         return;
         }
                      
      if ((buf[44]=='0')&(buf[45]=='2'))  // Relay 02
         {
         if ((buf[46]=='0')&(buf[47]=='1')) digitalWrite(7, 1);
         if ((buf[46]=='0')&(buf[47]=='0')) digitalWrite(7, 0);
         return;
         }
                      
      if ((buf[44]=='0')&(buf[45]=='3'))  // Relay 03
         {
         if ((buf[46]=='0')&(buf[47]=='1')) digitalWrite(6, 1);
         if ((buf[46]=='0')&(buf[47]=='0')) digitalWrite(6, 0);
         return;
         }
                         
      if ((buf[44]=='0')&(buf[45]=='4'))  // Relay 04
         {
         if ((buf[46]=='0')&(buf[47]=='1')) digitalWrite(5, 1); 
         if ((buf[46]=='0')&(buf[47]=='0')) digitalWrite(5, 0); 
         return;
         }
                                         
    }                  
} // end Relay_Control

I successfully control first relay (led) using this two files.

Can somebody who knows PHP help me to make one PHP file with buttons for control all 4 relays (leds) ….