Project Description

   Practical demo on controlling an LED from a browser.

This post is a practical demo on controlling an LED from a browser.
Arduino ETHERNET SHIELD is used here. The Browser acts as a CLIENT & the SHIELD acts as a SERVER listening on HTTP PORT 80.
This demo is done on a Local Area Network .This means that the PC from where Browser is operated & the ETHERNET shield both are connected to the same NETWORK. You may have a Router in top of your Network.The Ethernet shield is connected to one of the RJ45 connector of the Router using a STRAIGHT Ethernet cable.The PC from where you start your browser is also connected to the same Router , to another RJ45 connecter or through WIFI , if your Router is WIFI enabled.
Once you connect the RJ45 cable to Ethernet shield, the left LED on RJ45 socket glows Green.This indicates a successful link made to Router.

img_20161030_1536191_thumb

image-5_thumb1

Digital pin 2 is used to connect to an LED through a resistor.
Digital pin 13 is occupied by Ethernet shield , so the built in LED on pin13 cannot be used.
When the Ethernet shield is connected to the Router an IP address is allotted by DHCP of the Router.As it is Dynamic & keeps changing on every boot up , we assign the IP using the code :
byte ip[] = { 192, 168, 0, 150 };
Note that , this IP should be in the same range of your Network.
To know the range , Open Network sharing center
Click on your connection & then the DETAILS tab
Here you can see the Gateway IP & IPV4 of your PC.You should assign an IP in the same range
In my case the gateway IP is 192.168.0.1
So I’m assigning the IP of Ethernet shield by changing the last byte of the address , say, 192.168.0.150

image-1_thumb

On computer Networks the machines or devices play 2 different roles : CLIENT & SERVER.
For e.g a web browser is a CLIENT that connects to other machines to request web pages or files.
The device or machine that serves the information is the SERVER.
SERVERs wait until a CLIENT connects & starts conversation with them.
PORTS allow different types of messages to be received by different pieces of software running on same server.For e.g Server software that accepts connection over FTP will usually run on port 21.WEB server software usually accepts connection over HTTP on port 80. In this demo we use he WEB SERVER.
Now open up the browser on a PC which is in the same network as Shield.
Type in the address 192.168.0.150
The following CLIENT REQUEST & SERVER RESPONSE happens in the background.

image-6_thumb1

image-21Instead of LED you can connect a Relay board & then control any home device through the contacts of the Relay.The above setup is the basic to start with Home Automation.
This demo is done on Local Area Network .It can be extended to Internet of Things through Port Forwarding & DDNS set up which is explained in another post.

Source : https://alselectro.wordpress.com/tag/ethernet-shield/

Tags : 201610, W5100, Ethernet Shield, Arduino

Author : Saravana