To work with this project, you must know your Arduino Ethernet Shield's MAC address and IP address to communicate properly over the Internet.
Current Arduino Ethernet Shields come with a dedicated and uniquely assigned 48-bit MAC (Media Access Control) address which is printed on the sticker. Write down your Ethernet shield's MAC address so you can refer to it later. The following image shows an Ethernet shield with the MAC address of 90-A2-DA-0D-E2-CD:
You can rewrite your Arduino Ethernet Shield's MAC address using hexadecimal notations, as in 0x90
, 0xA2
, 0xDA
, 0x0D
, 0xE2
and 0xCD
, with the leading 0x
notation recognized by C compilers (remember that the Arduino programming language is based on C) and assembly languages.
If not present, you can use one that does not conflict with your network. For example:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
You can assign an IP address to your Arduino Ethernet Shield by one of the following methods:
The network devices we will use for this experiment are the following:
The following steps will explain how to determine your network IP address range with a Windows 8.1 installed computer, and select a valid static IP address.
B04844_01_06.ino
from the code folder of this chapter.#include <SPI.h> #include <Ethernet.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 1, 177 }; EthernetServer server(80); void setup() { Serial.begin(9600); Ethernet.begin(mac, ip); server.begin(); Serial.print("IP Address: "); Serial.println(Ethernet.localIP()); } void loop () {}
The DHCP can be used to automatically assign a valid IP address to the Arduino Ethernet Shield. The only address you need is the MAC address of the Ethernet shield. Pass the MAC address as a parameter to the Ethernet.begin()
method.
Upload the following Arduino sketch to your Arduino board, and open the Arduino Serial Monitor to see the auto-assigned IP address by the DHCP. Use this IP address to access your Ethernet shield through the Internet. Remember, this IP address may be changed at the next start up or reset.
Open your Arduino IDE and type or paste the following code from the sketch named B04844_01_07.ino
from the code folder of this chapter:
#include <SPI.h> #include <Ethernet.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; EthernetServer server(80); void setup() { Serial.begin(9600); Ethernet.begin(mac); server.begin(); Serial.print("IP Address: "); Serial.println(Ethernet.localIP()); } void loop () {}
3.135.198.174