Make your arduino and his best ethernet friend talk to the world

The wireless connection goes wild, and i think these days no one barely to use or provide the RJ45 cable to connect his device to the world. Rather to use the hotspot connection like wireless@sg that opens in almost every area in Singapore, but the problem was how i can still use my arduino board with his best friend ethernet shield to connect to the world? The ethernet shield uses the RJ45 cable to connect, old and classy connection style, but not that bad. For the development purpose for example, I will use my macbook laptop to build the code, compile, and straight away transfer the binary output to the board thru usb connector. Meanwhile, I can still do the debugging inside the running device, to monitor the tcp flow connection. The ethernet shield seems only can reached the laptop’s ethernet port with internal dhcp full duplex peer to peer.

While my laptop connected wirelessly to the world, and my shield connected locally with the ethernet cable, the question is how to merge these two networks? Good news yo! For the macbook user, apple did a good job to provide a good solution for by sharing the internet connection, so that my shield also can connect to the world, yippee. How? Ok lets see the following steps below.

First, make sure your computer connected, try to ping the thru the console, easy stuff.


Ok, now we gonna to do the internet sharing inside the laptop, sharing the internet connection from WiFi connection to the Ethernet port. Go to “Sharing” menu under “System Preferences”, setup “WiFi” value on “Share your connection from” field, setup “Ethernet” value on “To computers using” field, and enable the “Internet Sharing” service.


After done the internet sharing, next we can validate the tcp connection by checking what kind of ip assigned inside the laptop, please remember the laptop in here became a internet gateway host as well, the dhcp server also supply automatically, so that the shield no need to assign the ip manually. Go to the terminal and type “ifconfig” and find the “bridge0” interface, in this example the host ( laptop ) has local ip “”.


Lets connect the arduino board with the usb cable and the ethernet shield with the RJ45 cable into the laptop.


Now, how to do to make sure that this arduino is properly connected to the world? It’s easy, we just need like a ping application installed inside the board, and try to ping the for this example and display the result inside the serial terminal that connected thru the usb cable.

First, we need the ping library for the arduino, and i found this powerful icmp ping library, it was free and u can download easly. This is the power of the open source community outside there, somebody build the one and share it to the arduino community. To use that ping library, it was very simple, just by typing “ICMPPing ping( socket )” at the beginning to create the ping object and type “ping( timeout , remoteIP , stringLineResult)” to do the ping. Calling to ping usually do often so i decided to put this module in the loop function and set the delay function for the latency period between the ping process, in this example i put one second delay.

[gist /]

Done the sketch, lets move to compile and run the board.


Inside the “setup” function, I only use the statement “Ethernet.begin( macAddress )” function in the beginning, in here i don’t assign the ip address manually, and lets the dhcp server from the laptop decided. It successfuly defined with local ip address “” in the arduino board, display the local ip by calling “Ethernet.localIP()” function. Finally the ping is done and running well, from the picture above, we can see that from the arduino board can reached the with total maximum 66ms, pretty quite fast from this starbucks place, lolx.

FIN :-)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s