enc28J60 and Arduino (4)

luca 22/02/2012 18

In the following post, I’m going to show you how to power on a PC using the Wake on Lan feature and your Arduino.
Almost all the actual network adapters have a feature called Wake on Lan, that is the ability to “wake” the PC with a special command sent through the network.


Two main requirements to use this feature:

  • if your network adapter is not embedded in the motherboard, you have to connect them with a cable:

  • the WOL functionality has to be enabled in the BIOS:

A typical limit in WOL usage is that network adapter isn’t able to wake the PC if it was shut down by power loss. Actually, recent motherboards can enable WOL functionality even after a power loss; you can configure this feature in motherboard’s BIOS:

Magic Packet

The wake command is issued sending on the network a specific packet, called Magic Packet. This packet is receved by all the devices connected to local network because it presents – as destination MAC address – the broadcast address (FF:FF:FF:FF:FF:FF). It includes six bytes valued FF, followed by the target PC’s MAC address repeated 16 times.

Even if it’s not important which high level protocols you choose, it’s a convention to use UDP protocol and destionation port 7 or 9.


Note: EtherCard library had a bug in the Magic Packet creation. I solved the problem and my change has been accepted in the official repository: so make sure to download library’s latest version

You can use sendWol() method to send the Magic Packet; that method needs target PC’s MAC address as a parameter:

static byte targetmac[] = {0x00,0x1A,0x4B,0x38,0x0F,0x5C};

As usual, you can find a complete example in the GitHub repository related to this tutorial.

Using a network analysis tool like Wireshark, you can inspect the packet sent by Arduino and note that it’s correct:

  • in red the destination broadcast MAC address
  • in green the choice of IP and UDP protocol
  • in light blue the target PC’s MAC address repeated 16 times


  1. Arup 28/02/2012 at 10:28 - Reply

    Nice work. Next would be interfacing an GPRS shield with the same Arduino so that remote wakeup can be achieved. Of course after PC powers on, we can use it and access files remotely using remote desktop software.

    • luca 28/02/2012 at 10:38 - Reply

      Thanks Arup! It’s a good idea, a GSM shield has just been shipped to my home ;) Stay tuned for a new blog post about it!

  2. Gonzalo 07/03/2012 at 22:56 - Reply

    Great Job Luca , will work with wiz5100 ethernet shield?

    • luca 07/03/2012 at 23:06 - Reply

      Thanks Gonzalo,

      no, it won’t work because W5100 chip is very different from ENC28J60… as it is the chip chosen for the “official” ethernet shield, you can find a lot of documentation on Playground.

  3. Christian Leicht Jørgensen 11/04/2012 at 21:04 - Reply

    Thank you for this nice piece of code.
    It’s a shame it doesn’t work on the W5100 chip.
    Have some of you found a way to get it to work on the W5100 chip?

  4. Tiry 02/10/2012 at 21:15 - Reply

    thank you very much for correcting the library. I tried to fix it also, it is more useful now! Work fine with ENC2860 connected to Arduino. WOL ok for me. Thank’s again !

    • luca 02/10/2012 at 22:04 - Reply


  5. gl 05/05/2013 at 17:17 - Reply

    when i try to upload i get a ethernet not declared message.. and nu upload to the arduino uno

    i have the library in the correct folder?

    using IDE 1.0.4

    • luca 07/05/2013 at 08:22 - Reply

      Hi! Did you follow this tutorial about how to install the library?

  6. Francesco 21/05/2013 at 10:09 - Reply

    interessante articolo.
    io ho una scheda (non shield) con enc 28j60.
    volevo fare un wake-on-lan però in modo che ricevendo un magic su porta 9 ad esempio dal router, mi spedisca un magic packet come nell’esempio contenente il MAC del pc che voglio accendere. Quindi su ricezione del pacchetto e non su pressione del tasto ‘w’
    Inoltre non ho DHCP quindi dovrei impostare
    IP, Subnet mask e Gateway. Come faccio?
    Ma un elenco completo (con descrizione) delle primitive dentro a EtherCard dove lo trovo?
    Grazie, ciao

    • luca 22/05/2013 at 09:37 - Reply

      Ciao Francesco

      non ho capito bene la tua necessità: vuoi comandare il wake-on-lan da remoto? Ad es. pubblicando una pagina web da Arduino che puoi raggiungere via Internet con un pulsante “wake” che fa inviare il magic packet? In questo caso puoi combinare i miei due tutorial (wake on lan e accensione led da pagina web)

  7. Clubbby 03/10/2013 at 18:38 - Reply

    Thanks for this. I just had it in my head to make my media PC turn on over WOL along with an IR receiver waiting for a “Power” signal from our remote.

    I already have several ENC28J60’s and thanks to you I know that I can use one for just this task (assuming the media PC supports WOL, will check when I get home).

    • Clubbby 07/10/2013 at 23:58 - Reply

      I built this out yesterday and it works like a charm! Again, thanks.

  8. enrico 29/04/2014 at 23:36 - Reply

    si puo ank fare via usb?

  9. Landy 08/06/2014 at 12:53 - Reply

    I’m having trouble running this, even after downloading the library it reports errors. Could you help out?

    • luca 08/06/2014 at 20:06 - Reply

      Hi, which errors?

Leave A Response »

This website uses cookies to ensure you get the best experience on our website maggiori informazioni

Questo sito utilizza i cookie per fonire la migliore esperienza di navigazione possibile. Continuando a utilizzare questo sito senza modificare le impostazioni dei cookie o clicchi su "Accetta" permetti al loro utilizzo.