ethernet thumbnail

Arduino – Webserver with an Arduino + Ethernet Shield

589 Flares 589 Flares ×

This project is all about using an Arduino with an Ethernet shield. I’ll be controlling one LED and a servo, but you can apply this method to control any electronic device you want. (such as DC motors, buzzers, relays, stepper motors, etc..)

1a

And I’ll be using a brand new arduino board that my friend at BJTechNews Sent me!
Check his youtube channel here for some awesome advices about computers and smartphones.

Introduction:

The code provided when uploaded and connected to the internet it creates a webserver in your LAN and you simply use the IP to access that webserver through your browser. After that it shows a webpage similar to that one below. When you press the button “Turn On LED” your url will change  to: “http://192.168.1.178/?button1on” the arduino will read that information and It turns the LED On.

By default the IP is “192.168.1.178″. That also can be found on the arduino code provided.

Untitled
Check this Video tutorial below ! (Includes demonstration)


Parts Required: 

  • 1x Arduino Uno
  • 1x Ethernet Shield
  • 1x 220 Ohm Resistor
  • 1x LED
  • 1x Micro Servo Motor
  • 1x Breadboard
  • Jumper Cables3a

Schematics:

[Schematics]

Upload this Arduino Code Below:

Note:

If you try this project. You can only access that IP address from your home. This means you must be connected to the same router that you’re ethernet shield is connected to. That picture below is from me accessing my webserver with my iPad.

a

Thanks for reading, you can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page.

P.S. Don’t forget there’s a new video every other Thursday!

Download All My Projects
Enter your email below and you can get instant access to all my projects for free

33 Comments

  • alain frenois

    Reply Reply November 8, 2013

    great achievement and very useful for achieving a home automation with relay perifairique comander of the 220 v or 110 v

    • Rui

      Reply Reply November 9, 2013

      Thanks for your feedback!
      yes that’s exactly what I want to show.
      you can use this code to apply to your own projects for home automation

  • Er Ajinkya Dixit

    Reply Reply November 9, 2013

    Wow…. really awesome project dude. You can use HTML also to create attractive and powerful web application i.e. webpage. I will give you link about that.
    This is the link here : http://internetofthings-pune.blogspot.in/2013/07/this-is-open-source-home-automation.html

    • Rui

      Reply Reply November 11, 2013

      Hi!!
      Thanks for the feedback Er Ajinkya Dixit!
      Yes we can customize the CSS file and the HTML to create a better webpage. But I’m not very experienced in that programming languages yet. So I’ve just made a basic webpage with my knowledge :)
      Thanks for the resource!
      My next webpage will be more customized.

    • Rui

      Reply Reply November 11, 2013

      Hi!!
      Thanks for the feedback Er Ajinkya Dixit!
      Yes we can customize the CSS file and the HTML to create a better webpage. But I’m not very experienced in that programming languages yet. So I’ve just made a basic webpage with my knowledge :)
      Thanks for the resource!
      My next webpage will be more customized.

  • Con

    Reply Reply November 17, 2013

    Hi do you have the source code for webpage?

    • Rui Santos

      Reply Reply November 17, 2013

      Hi,
      yes Con. You can download the source code for the webpage here:
      http://randomnerdtutorials.com/download
      Or simply click the like or tweet button and the download link will unlock.

      the best way is by entering your email and you’ll have access to a secret page where you can
      download all my projects every time I release a new one.

      thanks for stopping by,
      Rui Santos

      • Con

        Reply Reply November 17, 2013

        hmm I pressed like but only got the source code for the arduino not the browser

        • Con

          Reply Reply November 17, 2013

          ignore my previous comments, thanks for the code

  • Khaled

    Reply Reply January 8, 2014

    would u please send me the android webpage source code

    • Rui Santos

      Reply Reply January 8, 2014

      what you mean by the android webpage?
      That webpage can be accessed through your tablet/smartphone browser…
      and all the code used can be download on this page if you click like.
      Thanks for leaving a comment,
      Rui

  • Decka

    Reply Reply January 14, 2014

    what a nice project rui, but it’s the first time i saw arduino ethernet shield, can you make a tutorial about how to configure ip address or something like that on ethernet shield, or how to configure that on router using dhpc?

    • Rui Santos

      Reply Reply January 15, 2014

      Thanks Decka.
      Right now I’m working on a different project related to the Ethernet shield.
      So stay tuned, because that project will be released soon…
      I might do what you’re looking for later though.
      All the best,
      Rui

      • Decka

        Reply Reply January 17, 2014

        okay, good luck on your project bro.
        keep it up…

      • Decka

        Reply Reply January 17, 2014

        btw it’s dhcp not dhpc, sorry for typo…

        • Rui Santos

          Reply Reply January 18, 2014

          Yeah I know, I got it!
          Unfortunelety I don’t have time right now to do that. as i said… maybe later

          Have a nice day,
          Rui

  • nataraj

    Reply Reply January 18, 2014

    hi sir,

    Thank you very much for your reply and i need some more details like i want to get the sensor value through html . .and.i want to know what is going on home through sensor..suppose if any human is enter into the home .it has to inform to web page through HTML using PIR sensor…. so this kind of application i need…i hope you will understand very well,..please do the needful to complete my project as soon as possible…..

  • Jaap

    Reply Reply February 2, 2014

    Hi,
    Really great projects here! I learned a lot.
    A question:
    I see when clicking the buttons on the page they work oke for a while bit after some time the site seems to hang. Sometimes texts messed up and nothing works anymore. Do you recognize this? Is there a solution?
    I see it happens running IE on my PC but also running Chrome browser and Safari on my iPad.

    • Rui Santos

      Reply Reply February 2, 2014

      Thanks jaap.
      I’m glad you’re enjoying my projects!

      That never happened to me.
      It might be a problem with your network/ethernet shield.
      In another project I’ve made recently I noticed that sometimes if the ethernet shield is connected for too long, It gets disconnected and no longer works until you reset manually the arduino.

      With this webserver project I’ve tested to run for 17hours, 8 hours, 32hours and It worked just fine.
      Now what I recommend you to do,
      is to comment the project with Serial.print() commands and see where the problem is coming from and how long it takes until it stops…

      Just one more question which ethernet shield are you using?
      (the one with the Wiznet 5100 chip?)

      • Jaap

        Reply Reply February 2, 2014

        Hello Rul,
        Thanks for your help!
        Yes, it’s a shield with the Wiznet 5100 chip. I ordered it from BangGood. Worked fine in other projects.
        You wrote: “17hours, 8 hours, 32hours…” but have you also done some testing by using all buttons one after another multiple times? Let’s say 10 time.

        • Jaap

          Reply Reply February 3, 2014

          Hello Rui,
          I think the problem is fixed.
          Changed the delay time from 1 to 100 in this part of the sketch:

          client.println(“”);
          delay(100);

          And now my page keeps running…
          :-)

          • Rui Santos

            February 5, 2014

            I’m glad to hear that ! :)
            Thanks for trying my project Jaap.

            Have a nice day,
            Rui

  • seva

    Reply Reply February 23, 2014

    I cann’t open the link :(

    • Rui Santos

      Reply Reply February 25, 2014

      Which link Seva?

      • seva

        Reply Reply March 9, 2014

        if you can help me control the lights via the web, control light intensity,

        • Rui Santos

          Reply Reply March 12, 2014

          Search on the web for a PWM project to control the lights intensity.
          Then change my code for this project.
          so instead of controlling an led to turn on/off you’re going to increase or decrease the light.

          Thanks for asking,
          Rui

  • Constantinos Lambrou

    Reply Reply March 12, 2014

    I notice the code references a CSS file. Is it possible to have the code be stand alone? Meaning one would not have to host a CSS file?

    • Rui Santos

      Reply Reply March 12, 2014

      yes, you can customize the html without the CSS file.
      The CSS just makes it easy to customize the html without repeating the same styling options again and again.

      Thanks for asking,
      Rui

  • Murp

    Reply Reply April 16, 2014

    Hi Rui, I’m trying to adapt your code to control 8 LEDs through internet but I have one problem…With 4 leds, works ok,but if I configure a 5th led, don´t work…..

    Can I send you the code to some email to see if you see any faults?? (Ide recognizes the code without errors..)

    Thanks and regards :)

    • Rui Santos

      Reply Reply April 18, 2014

      Hi Murp,
      I don’t have the time to debug your code I’m sorry…
      I don’t know how experienced you are with Electronics, so just a few questions
      are you defining the right LED’s pins properly as inputs? are your LED’s in the right way?

      • Murp

        Reply Reply April 18, 2014

        Hi Rui, no problem :)

        To your questions, no and yes..Leds are configured as “int” –> outputs and all is connected ok (It works ok with 4 but not with 5..With 5, the buttons are on screen but don´t work if I press any…)

        The code, I think that works right (No error on IDE, less than 20000 bytes), but I don´t understand what´s the matter…

        With 4, I configured twice:

        Pins 2,3,4 and 5
        Pins 6,7,8 and 9

        And all works ok (Arduino,leds,proto connetions,code…), and for that, I discarded all parts of the system like bad or broken components..

        Thanks for all..

        Regards :)
        (About my experience with electronics, let’s say my level is medium jeje)

Leave A Response

* Denotes Required Field