Introduction: Add Ethernet to Any Arduino Project for Less Than 10$

So you have a neat Arduino project going on. Wouldn't it be nice to add Internet connectivity and do it on the cheap as well? This Instructable will show you how to add Internet connectivity in the form of an Ethernet interface for a few dollars and in less than half an  hour. More info at: http://hwstartup.wordpress.com/

Step 1: Order an ENC28j60 Ethernet Module on EBay

Apart from your Arduino, you need a read-made Ethernet module. You can easily get these on eBay for as low as 10$. Just search eBay for ENC28J60 module. In addition, you need to have a bit of electrical wire, a soldering iron and some soldering 'tin'.

Step 2: Wire Up the Ethernet Module

Now it's time to wire up the module. Either use a connector to put on the Ethernet module header or solder straight onto the pins (like I did). You will need just six wires, I used about 3-4 inches length, but this is not critical (as long as it's not a foot long).

Wire up as following (ENC = module side):
- ENC SO -> Arduino pin 12
- ENC SI -> Arduino pin 11
- ENC SCK -> Arduino pin 13
- ENC CS -> Arduino pin 8
- ENC VCC -> Arduino 3V3 pin
- ENC GND -> Arduino Gnd pin

Markings are on the module in white text. The result should look similar to the picture.

If you done this rigt, the LEDs on the module will light up when the Arduino is powered. Stick in an Ethernet cable and the LEDs on the Ethernet connector should light up, showing local Ethernet traffic.

Step 3: Arduino Code

Last step is to upload Arduino code to connect to the Internet. For the ENC28J60 chip/module, there are two Arduino libraries available: Ethershield (development has stopped) and Ethercard (the newest).

Load a Sketch that let's the Arduino act as a webserver, like this example:

// This is a demo of the RBBB running as webserver with the Ether Card
// 2010-05-28 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,1,203 };

byte Ethernet::buffer[500];
BufferFiller bfill;

void setup () {
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
  ether.staticSetup(myip);
}

static word homePage() {
  long t = millis() / 1000;
  word h = t / 3600;
  byte m = (t / 60) % 60;
  byte s = t % 60;
  bfill = ether.tcpOffset();
  bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n"
    "\r\n"
    "<meta http-equiv='refresh' content='1'/>"
    "<title>RBBB server</title>"
    "<h1>$D$D:$D$D:$D$D</h1>"),
      h/10, h%10, m/10, m%10, s/10, s%10);
  return bfill.position();
}

void loop () {
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);
  
  if (pos)  // check if valid tcp data is received
    ether.httpServerReply(homePage()); // send web page data
}

With a bit of hacking, you can easily add code to display analog values read off the analog pins for instance.


Step 4: Done!!!

That's it, you just hooked up your Arduino to the Internet for less than 10$. 

More interesting Arduino stuff at: http://hwstartup.wordpress.com

Comments

author
kiwidoc (author)2017-04-13

The CS pin can be made to be 8 if you wish: ether.begin(sizeof Ethernet::buffer, mymac, 8) is all that is required. Great tutorial tho..

author
cassy73 (author)2017-02-14

Hi All!

New UIPEthernet release is available (2.0.3).

Added support for Intel ARC32, Nordic nRF51, and Teensy boards.
The Errata#12 corrected.

The Issues corrected.

You can download from: https://github.com/UIPEthernet/UIPEthernet/archive/v2.0.3.zip

and from: https://github.com/UIPEthernet/UIPEthernet/archive/master.zip

Best Regards

author
cassy73 (author)2016-12-08

Hi All!

You can use UIPEthernet library for ENC28j60 arduinos (AVR,STM32F,ESP8266).

You can download this library from: https://github.com/UIPEthernet/UIPEthernet

Best Regards

author
cassy73 (author)cassy732016-12-16

Hi All!

Direct link to full repository compressed ZIP file:

https://github.com/UIPEthernet/UIPEthernet/archive...

Best regards

author
cassy73 (author)cassy732016-12-29

Hi All!

New version available:1.2.1

- Added Abstract Print class to MBED for full compatibility (Can use print, println with uip objects.)

- All examples working properly with MBED compiler.

Best regards

author
captclearleft (author)2016-09-19

Nice tutorial. Thanks, and for those with problems.

ANSWER TO PROBLEM: (Sep 2016) Pin 10 for CS, NOT pin 8.

author
reck3 (author)captclearleft2016-12-06

Thanks changing from pin 8 to 10 sorted out my issue... cheers!

author
YetAnotherMike (author)2016-07-24

Since the ethernet module itself has some programmability I can see it being an invaluable tool for a network technician... Maybe someone could write a snippet of code to blink the LEDs on a network switch in a user defined pattern (just in case several were in use at once)... a pattern different than normal network traffic (maybe blink the 10-100 LED)... then the tech could plug this into a network wall jack and then find the blinking switch port... power it with three AA cells...
Picture a building with 4 jacks per cubicle, 400 cubicles per floor, and 18 floors... now find the switch port for jack #3 in cubicle 307 on the 11th floor.... Yes, a consistent wiring pattern can find the patch panel, but then there is the tangle of patch cords. I'd pay $50 for this in a heartbeat!

author
RuslanA7 (author)2016-06-18

Somebody knows how to fix those errors while compiling?:

"...Arduino\libraries\ethercard-master\EtherCard.h:252:41: warning: 'prog_char' is deprecated [-Wdeprecated-declarations]

void emit_raw_p (PGM_P p, uint16_t n) { memcpy_P(ptr, p, n); ptr += n; }

^"

I get lots of those.

Same thing when trying to use UIPEthernet

author
ryuhemanth (author)2016-02-01

I am using UIPEthernet library, connection is same except using arduino pin 10 instead of 8.

author
inflamers (author)2016-01-10

Not working for me, I guess wiring is correct because it works with Ethercard library. The flashlight is blinking, but I cannot ping it. Any idea ?

author
spicymeatboll (author)inflamers2016-01-20

Which library are you using then? Ethercard is the only use that uses pin 8 (for CS). If you're using Ethernet or UIPEthernet you will need to move it to pin 10.

author
Jaime183 (author)2015-09-30

author
KingEverest (author)2015-06-08

Can this be used as a replacement of the Ethernet Shield?

author
hansc44 (author)KingEverest2015-06-09

Yes indeed.

author
MárcioS7 (author)hansc442015-08-31

Could I connect with just 4 wires?? (I mean, I have a USB Ethernet adapter... Is it possible to use for this?)

author
KingEverest (author)hansc442015-06-09

Thank you, you just helped me solve something.

author
MárcioS7 (author)2015-08-31

Could I connect with just 4 wires?? (I mean, I have a USB Ethernet adapter... Is it possible to use for this?)

author
bhargavp1 (author)2015-07-18

Hi,

I have used new library and downloaded above program. Also connected wires as described.

When I connect Ethernet cable, connection shows at 10 MbPS, but I am not able to ping the controller.

My Laptops IP is : 192.168.1.76

Subnet Mask : 255.255.255.0.

What could be the problem ?

author
snoop911 (author)2015-05-25

Has anyone experimented with how fast data can be clocked in/out of the ENC? For example, the datasheet says SCLK can be up to 20Mhz!

I'd be interesting to see how much thruput will change if going to a parallel interface like on the ENC624J600. There's also an ethernet based bootloader for the ENC624J600 that I've been meaning to get (from brushelectronics.com) but I think it uses the (rather closed) microchip tcp/ip stack.

author
xfinder (author)2015-05-18

Thank you for your help.
great working.

author
rohit.kay.7 (author)2015-04-12

I am using UIP Ethernet library along with the Module

The problem is

Whenever ro connect any AC load (single phase) ,

After one or two commands , the arduino is disconnect from the Network !

Any suggestions ? On what to do

author
rohit.kay.7 (author)2015-03-20

Can someone give an easy explanation of the code ?

author
francisroan (author)2013-05-17

Hi well i did bought the bigger version of this module but i really wanted to know how to actually communicate the arduino to the actual internet and not the LAN..! could you pls tell us how..?

author
felixa1 (author)francisroan2014-12-12

It is technically connected to the internet! You can get things FROM the internet with this setup, but to host over the internet, you need to port forward your router/modem.

author
sirous66 (author)2014-12-05

Do you know whether this would work with netarduino 1?

author
diy_bloke (author)2014-11-28

I have used a similar module and it is indeed a very cheap way to connect to ethernet.
However time can be your friend. The W5100 shield nowadays is also fairly cheap and a W5100 module is about 6-7 euro.
Check aliexpress:

http://www.aliexpress.com/item/TOP-Mini-W5100-LAN-Ethernet-Shield-Network-Module-board-for-Arduino-Best/1990146986.html

author
diy_bloke (author)diy_bloke2014-11-28

in fact the W5100 shield is cheaper than the 5100 module: around 5 euro:

http://www.aliexpress.com/wholesale?catId=0&initiative_id=AS_20141128122559&SearchText=ethernet+shield+w5100

author
ScottG6 (author)2014-10-23

gearbest has them for under $5. old post but still good modules.

http://www.gearbest.com/development-boards/pp_2271...

author
snoop911 (author)2014-09-26

Would this work with an Arduino Mega? Does it require code change and/or different pins?

author
madrian ovidiu (author)2014-06-07

Hello,

I'm
contacting you regarding a project that I have. I'm using Arduino Uno
and enc28j60 module and some XBees. The main problem is regarding the
connection to the LAN/Internet. I'm using some sensors and I'm trying to
view the sensors reading on the web. I used a lot of libraries but I
can't see nothing. I connected the enc28j60 module with a cable directly
to the computer and in the browser I am typing the IP but nothing to
see. What am I doing wrong? Please help.

author
diy_bloke (author)madrian ovidiu2014-09-01

have you forwarded your internet IP to yr enc28J60 IP?

author
vamsi danda (author)2014-05-14

hey im using arduino mega 2560 please tell me the exact pin mapping for that

author
diy_bloke (author)vamsi danda2014-08-30

http://www.geeetech.com/wiki/images/d/d7/ENC-table.jpg

author
francisroan (author)2013-05-05

Hi could you please tell us how to connect this module with the arduino to communicate to the outside world(the internet) and not just the LAN . I want it to send me emails.!

Pls help.

Thank you for your time.!

author
diy_bloke (author)francisroan2014-08-30

might be too late for you but maybe someone else is helped by this often asked question:
The answer is as for any computer om yr LAN that you want to get to from the internet: in your router you have to set up portforwarding to the local IP of the computer you want to get to.
If you would forward port 80 to the IP nr of this module and run a webserver on it, then http://your_internet_ip/ will bring you to yr module.
If you forward another port, say 8080 then you do this:
http://your_internet_ip:8080

author
chriskendall1 (author)2014-07-12

...goes over a sample sketch and references a good library for these.

author
Sreenivas_Cyient (author)2014-06-06

Hi all,

I am unable to execute it properly , below errors are coming

//***

Ethernet_Test_One:7: error: 'Ethernet' has not been declared

Ethernet_Test_One:8: error: 'BufferFiller' does not name a type

Ethernet_Test_One.ino: In function 'void setup()':

//***

i hope i doing mistake in adding .h file,

could please tel me how to proceed futher

author
djoike (author)2014-04-24

Thanks for this article, it made it a lot easier to pick which ethernet element to choose.

I do wonder though, how processing-intensive this approach is compared to using the W5100? As you wrote in another comment, the W5100 does more on-chip (TCP/IP work).

My concern is: If your code is very timing sensitive, is it even feasible to have ethernet communication going on on the same arduino? And would it be more realistic with the W5100?

Say for example, you're using the arduino to run an AC light dimmer, where you need to detect the zero-crossing of AC power sine curves, and open/close a TRIAC unit some specific time after that, you're very dependent on the loop not being stalled by operations that take a long time.

I may be barking up the wrong tree here...

author
Hansaplast (author)2014-03-27

Great article!

I've been playing with a comparable [eBay: $18 w/Arduino Nano] ethernet shield, also based on the ENC28J60.

I tried a few libraries (ETHER_28J60, EtherCard and UIPEthernet) and found UIPEthernet to work very well as well, specially since it's a drop-in replacement library for the "standard" Ethernet Library that comes with your Arduino IDE. So all the Ethernet Examples included with your Arduino IDE work by just replacing the "#include <Ethernet.h>" with "#include <UIPEthernet.h>".

http://www.tweaking4all.com/hardware/arduino/ardui...

author
demonspells made it! (author)2014-03-14

Hello,

Thanks for a perfectly simple tutorial, I was able to set it up in less than 10 minutes, all thanks to you.

1926685_601661906583579_13647449_n.jpg
author
mickeypop (author)2013-04-07

There are similar at dx.com for about $5.90 and work with Arduino's ethernet library right out of the box.   Shipping is free.

They also have many other Arduino add-ons at very good prices.

For you other hackers, this can be a great source and save money at the same time.

author
TheZuke! (author)mickeypop2013-10-08

And here is one on That Auction Site for less than that....

http://www.ebay.com/itm/like/111114905350?lpid=82

author
classtopher (author)2013-05-24

I was expecting to see a level converter between the 5v arduino and 3v Ethernet enc28 board on the data lines. I've seen other DIY arduino Ethernet boards that use it. But yours indicates that is not necessary? Thanks.

author
kyle brinkerhoff (author)2013-04-30

awsome! i purchased one of these modules on amazon for 7 bucks and i tried getting it running but failed but this is alot more clear than the translated chinese instructions. THANKS A TON!

author
hansc44 (author)kyle brinkerhoff2013-05-02

Hi Kyle,

How far have you come?
- Do you have the LED on the PCB on?
- When you connect to your router/modem, do you see the LEDs on the Ethernet connector light up?
- What do you see on your serial port (copy here?)?

Hope this helps you.

Hans

author
kyle brinkerhoff (author)hansc442013-05-03

well heres what i got, i used the example script that uses dhcp to obtain an ip and it basically says it cant obtain an ip, im gonna check my wiring....

photo.JPG
author
hansc44 (author)kyle brinkerhoff2013-05-05

Kyle,

Traveling now, so I cannot help now. Sorry.

author
kyle brinkerhoff (author)hansc442013-05-05

oh its all good, its wiring on my end that just has to be troubleshooted

author
jerbs (author)2013-04-26

I'm getting an Ethernet has not been declared error while compiling.. anyone else with this problem?

About This Instructable

284,876views

400favorites

License:

More by hansc44:Arduino: Use LED as a light sensorAdd Ethernet to any Arduino project for less than 10$
Add instructable to: