Ethernet shield Guide for arduino

Ethernet shield Guide for arduino

Arduino Ethernet Shield

The Arduino Ethernet shield allows an Arduino board to connect to the internet using the Ethernet library and to read and write an SD card using the SD library.

Connecting the Shield

To use the shield, mount it on top of an Arduino board (e.g. the Uno). To upload sketches to the board, connect it to your computer with a USB cable as you normally would. Once the sketch has been uploaded, you can disconnect the board from your computer and power it with an external power supply.
Connect the shield to your computer or a network hub or router using a standard ethernet cable (CAT5 or CAT6 with RJ45 connectors). Connecting to a computer may require the use of a cross-over cable (although many computers, including all recent Macs can do the cross-over internally).

Network Settings

The shield must be assigned a MAC address and a fixed IP address using the Ethernet.begin() function. A MAC address is a globally unique identifier for a particular device. Current Ethernet shields come with a sticker indicating the MAC address you should use with them. For older shields without a dedicated MAC address, inventing a random one should work, but don't use the same one for multiple boards. Valid IP addresses depend on the configuration of your network. It is possible to use DHCP to dynamically assign an IP to the shield. Optionally, you can also specify a network gateway and subnet.

SD Card

The latest revision of the Ethernet Shield includes a micro-SD card slot, which can be interfaced with using the SD library




Connecting the Ethernet shield


 The Arduino Ethernet Shield allows you to easily connect your Arduino to the internet. This shield enables your Arduino to send and receive data from anywhere in the world with an internet connection. You can use it to do fun stuff like control robots remotely from a website, or ring a bell every time you get a new twitter message. This shield opens up endless amounts of possibility by allowing you to connect your project to the internet in no-time flat.


setting it up is as simple as plugging the header pins from the shield into your Arduino.






Setup




















There is also an on-board micro SD slot which enables you to store a heck-of-a-lot of data, and serve up entire websites using just your Arduino. This requires the use of an external SD library, which does not come bundled with the software.


plug the Arduino into your computer's USB port, and the Ethernet shield into your router (or direct internet connection).


Next, open the Arduino development environment. I highly recommend upgrading to Arduino 1.0 or later (if you have not done so already). This version of the software has built in DHCP support, and does not require manually configuring an IP address.


To figure out what IP address has been assigned to your board, open the DhcpAddressPrinter sketch. This can be found at:


File --> Examples --> Ethernet --> DhcpAddressPrinter


Once open, you may need to change the Mac address. On newer versions of the Ethernet shield, you should see this address on a sticker attached to the board. If you are missing a sticker, simply making up a unique mac address should work. If you are using multiple shields, make sure each has a unique mac address.


Once the mac address is properly configured, upload the sketch to your Arduino, and open the serial monitor. It should print out the IP address in use.




The following code lights up an LED depending on the URL that is sent to the Arduino:


/*
  Web Server Demo
  thrown together by Randy Sarafan

 Allows you to turn on and off an LED by entering different urls.

 To turn it on:
 http://your-IP-address/$1

 To turn it off:
 http://your-IP-address/$2

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Connect an LED to pin D2 and put it in series with a 220 ohm resistor to ground

 Based almost entirely upon Web Server by Tom Igoe and David Mellis

 Edit history:
 created 18 Dec 2009
 by David A. Mellis
 modified 4 Sep 2010
 by Tom Igoe

 */

#include <SPI.h>
#include <Ethernet.h>

boolean incoming = 0;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
IPAddress ip(191,11,1,1); //<<< ENTER YOUR IP ADDRESS HERE!!!

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup()
{
  pinMode(2, OUTPUT);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.begin(9600);
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
       
        //reads URL string from $ to first blank space
        if(incoming && c == ' '){
          incoming = 0;
        }
        if(c == '$'){
          incoming = 1;
        }
       
        //Checks for the URL string $1 or $2
        if(incoming == 1){
          Serial.println(c);
         
          if(c == '1'){
            Serial.println("ON");
            digitalWrite(2, HIGH);
          }
          if(c == '2'){
            Serial.println("OFF");
            digitalWrite(2, LOW);
          }
       
        }

        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
  }
}





To make this work connect the positive lead an LED to pin D2, and the negative lead in series with a 220 ohm resistor to ground.


To turn on the LED enter this into your browser:
http://[YOUR IP ADDRESS HERE]/$1


To turn off the LED enter this into your browser:
http://[YOUR IP ADDRESS HERE]/$2


Note: You should obviously replace [YOUR IP ADDRESS HERE] with your IP address.


click to know your ip --> whatismyip




 Sources: instructables, google, arduino.cc

25 comments:

  1. I was looking for this
    thanks, it's save my day

    ReplyDelete
    Replies
    1. Great Article IoT Projects for Students

      Deep Learning Projects for Final Year

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  2. Wow that's a wonderfull blog having all details & helpful. AC Power Cord

    ReplyDelete
  3. Wow that's a wonderfull blog having all details & helpful. Power Cord

    ReplyDelete
  4. How to access ethernet globally?? Like from any network??

    ReplyDelete
  5. It's truly awesome and I like to read this type of impressing article. So I like to thank you for sharing a great article.

    ReplyDelete
  6. This is good and all but it's hard to use an ethernet shield today when you can use wifi and a nodemcu web server. Great tutorial btw!

    ReplyDelete
  7. Excellent article. Each and every aspect of Ethernet is comprehensively explained very easily. I am glad to see this valuable information.

    ReplyDelete
  8. bitcoin exchanger is popular website that works all around the globe where you can sell your crypto coins for cash amount and get paid into any currency of your choice, it is outstanding source for you.

    ReplyDelete
  9. This information is well but if you using cables you must buy from smartect cables specialy its cat6 plenum because i am also use this and i am very satisfied and they also provide 1000ft cables this is a new brand and it gives cheap price with good quality

    ReplyDelete
  10. Hotmail is one of the finest email services ever build. It has several features which makes it more attractive and powerful. Yet some technical issues may arise due to lack of knowledge. So it is advisable to call at Hotmail Customer Service Number 1-800-382-3046 for best and instant help from the experts 24*7.
    Hotmail Issues and their solutions

    ReplyDelete
  11. Nice Blog, Thanks for sharing an amazing... Keep Posting customer portal solutions

    ReplyDelete
  12. Download, Install & Activate MS Office Product by visiting the official website of MS Office. Click on the following link to know more about MS Office office.com/setup | www.office.com/setup

    ReplyDelete
  13. Great information provided by you... if you facing this same issues the dial visit our blog:-
    How to Connect Canon MX490 Printer to WiFi

    ReplyDelete

  14. My travel life have been easier with Garmin Express. Plus I can get all the additional knowledge through their blogs. I use the Garmin app and is totally upto the mark. I recommend everyone to use Garmin Gps Update and get Garmin life time map update or call +1-888-309-0939 for instant help from Garmin GPS experts.

    ReplyDelete

  15. I did not know the entire benefits of Garmin Nuvi Update. But since I have read this blog on map update, I have installed all available updates for my garmin device. I must say that this piece of blog has helped me improve navigation experience. I am not suggesting all my friends to read this blog and get Garmin Map Update with this team. For detailed information, you can contact us at toll-free number +1 888-309-0939. Our Garmin GPS professionals will provide instant help.

    ReplyDelete
  16. If you want to fix Windows Cannot Connect to HP Printer, You must make sure to completely install the latest version of Windows, such as drivers and software.The faulty or corrupted printer drivers also causes an error. To download the latest drivers.

    ReplyDelete
  17. Roku gives you the easiest way to stream your favorite movies and other videos to your TV. Along with that, you also get the solution to access the Roku TV by the best quality of remote access control. However, you need to have a Roku.com/link code enter to access the features of Roku TV.

    ReplyDelete
  18. The smartphones and Systems that make sure the user is updated i.e. Garmin Express Update with the location and not missing through most of the devices manufactured for functioning with the help of the Global Positioning Technology.

    ReplyDelete
  19. The recent Garmin express updates help in renewing the crucial data inside GPS. In the Garmin Express map update is also included that offers alteration to roads and locations in the map in your navigation devices. Update your map through Garmin.com/express to enhance the efficacy by selecting all eco-friendly roads.

    ReplyDelete