Some time ago I showed you how to set up an internet control system for your Arduino. — but it had to remain connected to the computer via USB in order to maintain an Internet connection. If you have an ethernet shield this is not needed. Today we’ll be looking at setting up an Arduino as a primary web server so we can host our own device management website.
You will need:
- Arduino or an Arduino clone, as detailed here.
- Ethernet Shield (~$35) — make sure you get the version that matches your Arduino as they are not all compatible
- Spare port on router or switch and Ethernet cable
- WebServer example provided in Arduino app
Setting
The Ethernet shield uses pins with 10 to 13 to manage network connectivity, so don’t include them in your project; pin 4 is also used for the SD card, but we won’t be using that today.
First things first — open File -> Examples -> ethernet -> webserver, which is provided in the Arduino IDE. Find the lines referring to the MAC and IP address.
The MAC address for me was found on the box — yours may be on the shield itself. Adjust the first line of values - you need to leave the previous bit 0x . From a technical standpoint, it doesn’t matter what you put in here, as long as you don’t have conflicting values on your subnet — but even so, it was a manufacturer-assigned address, so we should probably stick with that. Just know that if you get it wrong, it will still work.
Next comes the IP address. We need a specific fixed address so that we can properly set up port forwarding — the shield is capable of receiving an address from DHCP, but this is only useful if it will be used simply as a client and not as a server. Enter an IP address that is not used and remembered on your local network, the IP address of your router, and 255.255.255.0 (subnet). If none of this makes sense to you, read our free and detailed guide to home networking.
Port forwarding
Edit the line labeled EthernetServer (number) and change the number to 8081 . This will configure our server to listen on port 8081 in case your ISP blocks web traffic on the traditional port 80.
Download the demo at this point and test it from your local machine. You will of course also need to connect an Ethernet cable. Keep the USB plugged in as we need it for power — you can change it to 9V later, but we’re still testing.
Noob Tip: if you are getting this error, it means that you have mistakenly placed capital letter O instead of 0 in the MAC address area. There is no O! in hexadecimal values. If you’re really a beginner, it might be worth checking out our Arduino guide for !