Exploring Arduino: Arduino + Ethernet + DHCP with EtherTen


In the last post on Arduino, I briefly wrote about my experiments with setting up a wireless communication between a host computer and an Arduino board using XBee. Here, we explore talking to the world of the Internet(s!) using Arduino. Time for giving your Arduino an IP address! Instead of using an Ethernet shield on an Arduino UNO, I thought the EtherTen might be a better idea to try, since it has onboard Ethernet. I am glad, I chose Etherten for various reasons!

EtherTen

Arduino Webserver

Hook up your Arduino to your computer and plug in the Ethernet cable into the board, with the other end connected to a router. If you see the Webserver example (under File -> Examples -> Ethernet) shipped with the Arduino IDE, you will see that it uses the Arduino Ethernet library.

It however requires you to set up a static IP address for your Arduino. However, in a multi-user home/university network, there is a fair chance that the IP addresses are allocated dynamically, hence I would like to use DHCP in my Webserver sketch. Now, that said: using dynamic IP address for a web server isn’t the greatest of ideas technically. But, we shall not go there in this exercise.

I used Georg Kaindl’s Arduino DHCP library to obtain the IP address dynamically and integrated with the Web server example. Here is the complete sketch. Once, you compile and load the sketch to your board, and open the Serial Monitor, you should see something like this:


Attempting to obtain a DHCP lease...
A DHCP lease has been obtained.
My IP address is 10.0.0.97
Gateway IP address is 10.0.0.138
DNS IP address is 10.0.0.138

Now, go to your web browser, and type in: 10.0.0.97:8080 and you should see:

Arduino sends the sensor readings from the Analog pins 0-5 (I don't have any sensor connected to this pins, so they are just random readings)

Now, let us use the telnet  program to send a request to our Arduino:

Telnet session

Resources and misc.

That’s it for this time. (My previous posts on Arduino.)

8 thoughts on “Exploring Arduino: Arduino + Ethernet + DHCP with EtherTen

  1. Arduino and the Internet? Easy. « freetronicsblog

  2. Hello Amit, I am currently working on a project for my university, and I need to be able to connect on the schools network with an arduino through wireless. So i need DHCP support, do you have any recommendations ?

    thank you

  3. Hi, thanks for this post. I am now able to read the digital signals in my browser when the pc is connected to the same net, i.e. arduino ethernet connected to the router and pc connected wirelessly to the same router. What’s the next step to access these readings from outside this local net? If I try to connect to IP:8080 from my mobile phone over 3G I get an error message (“this webpage is not available” in chrome).

    Thanks for your help

    Mauri

  4. PowerGen Power-U Dual Port USB Car Charger charges your iPad, iPhone, iPod, HTC, Blackberry, MP3 Players, Digital Cameras, PDAs, Mobile Phones.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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