Category: ARDUINO


NEX31     NEX21


VIDEO Support  :



Nextion is a  Human Machine Interface (HMI) programmable Touch Display.

Nextion includes a hardware part (a series of TFT boards) and a software part , NEXTION EDITOR.

The Nextion TFT board uses only one serial port to communicate. It lets users avoid the hassle of wiring. On board a 32 bit ARM processor is used STM32F030.

Nextion editor has mass components such as button, text, progress bar, slider, instrument panel etc. to enrich the interface design. Furthermore, the drag-and-drop function ensures that users spend less time in programming. With the help of this WYSIWYG editor, designing a GUI is a piece of cake.

BASIC & ENHANCED Models are available.

Basic models :

NX3224T028            NX4024T032      NX4832T035

Notes: NEXTION product numbering rules , eg. NX4024T032

40 -Horizontal resolution: 40=400
24 -Vertical resolution: 24=240

T  -Series model: T=Basic Model     K=Enhanced Model
032 -Display size:”032″ means 3.2 inch
R   -Touch screen type:N=non touch; R=resistive touch; C=capacitive touch

All basic models  are resistive touch screen display, 4M Flash, 3.5KByte RAM, 65k colors., except 3.5 inch model which has 16M Flash.

Before starting the project ,let us collect the essentials.






Image 6


Inkscape editor is required , if you need an image in your project. Using INKSCAPPE we can convert the image resolution to match that of Nextion display.

First , download theITEAD LIBRARY file  & unzip it. Copy the folder & paste it to C:/Program files/Arduino/Libraries

Rename the folder to Nextion.

Image 7

Open the Nextion folder & locate NexConfig file.

Right click and select Edit with Notepad++


Image 8

As the library is designed for ARDUINO MEGA , we need to do the following modifications in Configuration file , so that ARDUINO UNO can be used.

Image 9

Comment lines 27 & 32.

Change Serial2 to Serial at line 37.

Save the file,

Next , we download an image background for the project and use INKSCAPE to convert image to match our Nextion display which is 400 x 240 resolution.

You can download wanted imaged from

Huge collection of Both free and paid images are available for download.


Go to File –> Document Properties

Set the UNITS to PX (Pixel) ,Width as 400 & Height as 240 ( which matches our NEXTION Display Resolution),

Image 23

Close the Document properties. A new Canvas of size 400 x 240 is created .

Now click File –> Import and browse to the location of the downloaded image file & select it.


Image 24

The image is loaded on to Inkscape.You can see drag Handles on all sides of the image.

Use the handles to pull so that the image size fits inside the Canvas created,

Image 25

Click View –>  Zoom –> Selection

to Zoom the  picture.


Image 26


Now drag the handles so that the image fits exactly inside the 400 x 240 Canvas


Image 27

Click on File –> Save as and select the CAIRO PNG type to save the image.


Next proceed with the NEXTION EDITOR Installation.

Open NEXTION Editor.


Image 10

Click on File –> NEW & within a folder create  a new file , say ledonoff.

This will be stored as .HMI File.

On the next window select the model of NEXTION Display you have.

In my case it is 400 X 240 2.3 Inch.

Select the model & then click on DISPLAY

Image 11

Here select the orientation of display as 90 – HORIZONTAL

You can also select vertical if you have created vertical  image and  like to have vertical


Image 12

A canvas of size width 400 x  height 240 is created inside Display area of Nextion Editor.

Image 13

Now we have to generate a FONT file.


Select Height of Font & type of Font.

Provide a name for the file.

Image 14

Click Generate Font to see a .ZI font file created.Save that in the project foldet.

Finally click the “Add the Generated Font” message.

You can see the font file added to the FONTS Area.


Image 15

Next click on PICTURE tab . Then click the + symbol.

Image 16

Browse to the location of the image file ( 400 x 240) we created earlier using inkscape.

Select the image file , so that it is loaded inside the PICTURES area.

Image 17

Click on PICTURE under TOOLS area.

Then at the right side ATTRIBUTE Area you can see the id of the image as 1, object name as p0

Below that against pic , empty space iseen

Double click on the empty space against pic to see on a new window the picture selected .

Image 18

Select the picture seen on new window & click ok.

Image 19

Now the image fits inside the canvas created.

You can click on DEBUG to see if any error is generated.If any error seen then you have to create again the image exactly of size 400 x 240 using inkscape.

Image 20]


Next add 2 Buttons & a Text over the image by clicking on the elements under Tools area.


Image 22


Click on the first button and go to Attributes area.

Here you can see the id of the component as 2, object name objname as  bo.

Write down these attributes , which will be used in coding.

Scroll down to txt and change the name to LED ON.

You can also change the name of objname , but we leave it as b0 as generated.


Image 28

Same way click on second button and note the attributes  id 3 , objname  b1

Scroll down and select txt , change name to LED OFF.


Image 30

For the third element , just change the txt to STATUS.

You can drag the text element to make the text area bigger.

Image 31

Now click on first button LED ON.

In the EVENT Area click the TOUCH RELEASE EVENT & then put a tick mark

against Send Component ID

Image 32

Do this for the second button LED OFF , also.

Click the DEBUG button to start the simulator.

Now you can see the display created with buttons and Status text bar.

Click on the LED ON button.While you release the click, a HEX code is generated

inside the simulator return area.

65 00 02 00 FF FF FF

65 is the Touch Detection code

00 is page ID which is page 0 for our project.

02 Component ID which is 2  (LED ON button)

00 Button Release event

FF FF FF  End of Message

Image 34


Similarly click on LED OFF button.

While  released you see the following code

65 00 03 00 FF FF FF

Here you can see the 3rd hex code as 03 which is component id of LED OFF button.

This hex code is available at the serial port of display when the event occurs.

So we can easily read this code and decide on which button is operated.



Check out the full instruction  set wiki here :


Click on COMPILE button to generate the .TFT file.

This is the file to be uploaded on to the Nextion display.

To see the file generated go to File –> Open Build Folder

which opens a folder named BIANYI inside which you find the generated file.

Copy this file and paste inside your project folder.


Image 35


The .TFT file can be uploaded on to NEXTION display by 2 methods .

One is the USB – TTL method where we connect USB-TTL device to serial port of display.

5v to 5v , GND to Gnd , Tx to Rx , Rx to Tx

Connect the usb-ttl to PC and note the serial COM port allotted.

Click on UPLOAD button on the NEXTION Editor.

On the upload window select the COM port & set the Baud Rate to maximum , 115200.

As this method is slower , it is better to set high baud rate,

Click GO.

Image 39


Now you can see the file uploading info on screen and finally you can see your design on Nextion display.

Image 38


Image 40


The second method is SD card method.

Use a card reader to hold SD card and plug it to PC.

Select the SD card drive , right click to FORMAT.

Ensure that the SD card drive is selected, set the format to FAT 32,and click ok.

Once formatted , copy the .TFT file we compiled earlier,from BIANYI Folder to this SD card drive.

No other file should be in card.

Remove SD card and plug it on to Nextion Display.

Provide power to display.You can use the USB-TTL and connect only the 6v and GND.

The file gets loaded faster compared to other method.

Once completed , remove power and connect back power.

You can see the result on screen.


Now , let us connect Arduino with NEXTION display.

First connect 5v of Arduino to 5v of display.Then GND to GND.

The display goes on showing the designed screen.


Image 36

Upload the following code .

As we do not use Software serial in code , we have to upload code first and then connect

Tx of Arduino to Rx of Display, Rx of Arduino to Tx of Display.




#include <Nextion.h>

const int led = 13;

//Declare your Nextion objects , pageid, component id., component name

NexButton b0 = NexButton(0,2,”b0″);
NexButton b1 = NexButton(0,3,”b1″);
NexText t0 = NexText(0,4,”t0″);

//Register a button object to the touch event list

NexTouch *nex_listen_list[] = {

//Button b0 component popcallback function
// When ON button is Released the LED turns ON and the state text changes

void b0PopCallback(void *ptr){
t0.setText (“State:ON”);

//Button b1 component popcallback function
// When OFF button is released the LED turns OFF and the state text changes

void b1PopCallback(void *ptr){
t0.setText (“State:OFF”);
void setup(void) {
//Register the pop event callback function of the components




void loop() {


CODE walk through :

First we include the header file

#include <Nextion.h>
Then each component used is declared using NexButton function
We have 3 components bo,b1 & t0

bo component is defined as

NexButton b0 = NexButton(0,2,”b0″);

0 is the pageid , 2 is the component id & bo is the object name
Similarly other 2 components b1 & t0 are defined

Next we create a list array using NexTouch function for the Touchable components.
We have only 2 touchable components b0 & b1
The array list is created b0,b1 & NULL isadded finally.

Button b0 component popcallback function
When ON button is Released the LED turns ON and the state text changes

void b0PopCallback(void *ptr)

same way button b1 component popcallback function is declared.

Inside SET UP we attach the function created to corresponding Events.
When you click bo button boPopCallback function is called.
This is done by
Same way for b1 button.
Inside loop we repeatedly watch for the event trigger list.

The code and project files can be downloaded from here :–hmi-tft-lcd-nx4024t032.html

Connect an LED at pin 13 of Arduino through a resistor to GND.

Image 37

When you touch and release LED ON button , the LED is ON

When you touch and release LED OFF button , the LED goes OFF.

The STATUS is updated accordingly.



Arduino ProMini , as the name indicates , is a miniature version of UNO .It runs on 16 MHz crystal ,ATMEGA328 ,but lacks USB connectivity. There are 5V  (16MHz) & 3.3V (8MHz) versions. In this demo I use the 5v version.




There is a voltage regulator on board so it can accept voltage up to 12VDC. If you’re supplying unregulated power to the board, be sure to connect to the RAW pin and not VCC.

Vcc accepts only 5v.

The latest version of this board breaks out the ADC6 and ADC7 pins ,also adds footprints for optional I2C pull-up resistors.

To upload code on to pro mini , a USB-TTL adapter is required.There are many types of  USB adapters available.The most reliable one that works up to Windows 10  is the one built on CP2102 IC .

CP2102 adapters are available in 2 variants .One with 6 pins that include the DTR  , Data Terminal Ready , which handles the RESET required by the promini board.

The other board is commonly available one with 5 pins.Here RESET must be done manually on promini while code is uploaded.






First let us upload code using the 6 pin version .

The connections are

PROMINI                USB-TTL

DTR   —–>   DTR

TxO   —–>  Rx

RxI    ——> Tx

Vcc   ——> 5v

GND  ——> GND

In some Promini boards the DTR pin is printed as GRN.


Plug in the USB board to PC & open the Device Manager . If the driver is installed previously , a COM port will be allotted.Otherwise , download the silicon labs cp2102 driver from here & install.


Image 1

Open the Arduino IDE , feed in the COM port allotted.

Select Board as Arduino Pro or Pro Mini , Programmer as USBasp.

In newer versions of IDE there is option to select type of ProMini board.Under Processor select ATmega328 5v,16MHz

Image 2

From Examples open the BL;INK sketch

Image 3

Click on UPLOAD button.

The DTR pin of USB board takes care of the RESET  & your code will be uploaded to PROMINI without any manual reset.


Image 4

Uploading code using a 5 pin version , needs a manual RESET on PROMINI.

The connections are

PROMINI                USB-TTL

TxO   —–>  RxD

RxI    ——> TxD

Vcc   ——> 5v

GND  ——> GND



Plug in the USB to PC & note the COM Port allotted.

Open Arduino IDE .Feed in the COM port , select board as Arduino Pro or Promini & Programmer as USBASP

From Examples , open the BLINK Sketch

Image 2.1

Click on UPLOAD button.

Image 2.6

Watch out for the message at the bottom of IDE.

“ Compiling Sketch “ message appears first.

Then it changes to “Uploading”

Image 2.2

As  soon as you see “Uploading” message , gently press the RESET Key on Promini.

This should be done instantly , as soon as you see “UPLOADING” message.

Image 2.3



If the KEY Press is at the right time , your code will be uploaded successfully.



You can also use your UNO board to upload code on Promini.

To use the UNO board , you need to by pass the bootloader .For this  upload an empty code to UNO or connect the RST pin to GND

Connecting RST pin to GND bypasses the bootloader & only the serial converter IC located near the USB socket is used as USB-TTL.

The connection here is STRAIGHT & not reverse

Tx of Arduino UNO goes to Tx of Promini

Rx of UNO goes to Rx of Promini

Gnd to Gnd



Connect the USB cable to PC & open the IDE.

Select the port where UNO is connected.

Image 2.5


Select the board as Arduino Pro or ProMini

Image 3.1

Open the BLINK sketch & UPLOAD.

Watch out the message at the bottom of IDE.

Initially “Compiling Sketch “ appears.

Then the message changes to UPLOADING…


Image 6

Once you see UPLOADING… message  , press the RESET key on PROMINI.




The code is now Uploaded successfully.

Image 7

Support VIDEO :

cooltext753793315   cooltext753790696

In the previous post we’ve seen how to connect the Arduino ETHERNET SHIELD to a Router directly  & upload LM35 data to Thingspeak.

What if  you do not have physical access to your Router & your Laptop is connected over WIFI to the Router. Or you cannot run a RJ45 cable from Router to Ethernet shield.

The procedure we follow is similar to the one we did for connecting Raspberry PI to Laptop.

Link here

First step is to enable SHARING of your existing internet.In my case , Laptop is connected to Router

over WIFI.

Open Control Panel –> Network & Internet –> Network & Sharing Center

Click on the existing internet connection

Image 1

On the next screen click PROPERTIES &  then SHARING

Image 2

Tick mark to ENABLE SHARING of Internet connection

Image 3


Now plug in the USB cable to Arduino & then connect the RJ45 Straight cable from shield to the RJ45

Port of LAPTOP.


As soon as you connect the RJ45 cable you can see an UNIDENTIFIED NETWORK


Image 4


Click on that new Network , select PROPERTIES.

On the next screen double click on Internet Protocol version 4 (TCP/IPV4)

Image 5

You can see an IP address like

Note that this is the new Gateway IP of the new network formed by Ethernet shield.If you do not see any IP , just select the “ Use the following IP “ &  feed in manually the IP.


Image 6


to verify the IP.

Under Ethernet adapter the Gateway IP of new network is displayed.

Note that this is the GATEWAY IP & Ethernet shield will be allotted IP in this range  .


Image 7

Let us try some built in example codes.

Under Examples  –> Ethernet –> select  DhcpAddressPrinter

This will print the IP allotted to the Shield.


Upload the code & open up the Serial monitor.

The IP allotted to the shield here is  which is in range of new Gateway .

Image 9


Next example is WEBSERVER

Image 10


Open the WEBSERVER code .

You need to change the IP Address as




Here change it to where the SERVER will be started. Note the usage of comma instead of dot between each byte.

Image 12


Upload the code & open the serial monitor to verify that SERVER is started.

Image 13

You can use your Browser as CLIENT.

Type in the IP to access the server.

On the Serial monitor “Client connected “ information will apper.

Image 14

On the browser you can see the values of ANALOG Pins of Arduino.

As nothing is connected to the Analog pins , you get random values.

Image 17


Next example is the TELNETCLIENT

Image 2


Open the code.

Here Ethernet shield is used  as CLIENT & you need to change the IP of client in range with the new Gateway

Next is the IP of the SERVER . This may be another PC or Android phone connected to the same Network .

Here the SERVER is started on PC with IP

Note that this IP is in the range of Gateway of Router

Image 3

Scroll down further & note the PORT number on which the SERVER will LISTEN.

Here it is 10002.

Upload the code on to Arduino.

Image 4

To test the setup , you need to start a SERVER on another PC on the same network with IP

For this we use HERCULES software. DOWNLOAD HERE

Click on TCP Server tab on Hercules , feed in the port number 10002 & click LISTEN.

The server is started on PC with IP , so , no need to enter the IP

Image 5

Now open the Serial Monitor of Arduino where SHIELD is declared as CLIENT.

You can see the “Connected..”  feed back from the Server.

Type in some characters on Arduino side , as well as Hercules side to verify 2 way communication.

Image 6

Instead of PC & HERCULES you can use your Android mobile ( to be connected over WIFI to the same Network).

On your mobile install TCP TOOLS



The IP of Android device is shown with default port 8080.Click on LISTEN

In the TELNET CLIENT code you need to change the SERVER IP t from 1,1,1,1

to & then change the port of server to 8080 & then upload to Arduino


mobile 2

Once code is uploaded open the Serial monitor.

On mobile you see the IP of CLIENT connected


Test 2 way communication by typing in characters.





Next we shall test the code which sends LM35 Data to THINGSPEAK SERVER.

You can check my previous post for details

Upload the same code without any change in IP.


Image 7

Open the Serial Monitor to see the data being uploaded to THINGSPEAK.

Image 8


cooltext753793315   cooltext753790696

Ethernet shield acts as wired Gateway between your Arduino & Internet.

This post demonstrates how to upload  temperature data from LM35 sensor to the server on THINGSPEAK.Before starting you should know how to connect the shield to Network.

There are 2 options by which your shield is connected to the Network.

First is the direct connection to your Router .You’ve an available RJ-45 port on your Router & you directly use a straight RJ45 cable to plug Ethernet shield to Router .Your PC/Laptop is also connected to the same Router either by wire or through WIfi (if your Router is WIFI capable).

Second is the indirect connection.Your shield is connected to your Laptop’s RJ45 with wire.Your Laptop is connected to Router through WIFI.In this case you need to bridge the connections or use the shield as unidentified second network with a different IP.

In this post we use the first Direct connection to Router method.

Check this connection image where my Ethernet shield is connected directly to  Router.My PC is also connected to the same Router by WIFI . Router is provided Internet access by the Internet Service Provider ACT.






To start with let us fix the IP of Ethernet shield STATIC , so that it is always the same on every boot up of Router.

From your PC  RUN –> CMD

Type in  ipconfig /all

The Default Gateway here is which is the IP of the Router.

All clients connected to this Router will be assigned IP in this range  where the last byte is from 2 to 255 (allotted on first come basis)

Image 1

In the above screenshot you can see (ipV4 address), my PC is assigned IP

IP is assigned automatically by Router , only when the DHCP is enabled in Router setting.

Type in your browser , the gateway IP & feed in your Router’s username & password  (generally both are “admin”)

Under DHCP settings ensure that DHCP is Enabled.

Image 2


Now click on the DHCP CLIENT LIST to know the devices connected to the Router.

In my case 2 devices connected.One is my PC which is allotted IP

& the second device is Ethernet shield which is allotted

But in our code we use IP .

Let us change the IP to & make it STATIC.



& then click ADD NEW



Feed in the MAC address of the Ethernet shield & the reserved IP as

The MAC address is the one you used in the code.This may be random unless you use more than one shield in the same network.


Click on SAVE & then REBOOT your Router to enable the changes made.


Now under DHCP Client list you can see your shield allotted & permanent (means STATIC IP)




Connect the 1st pin of LM35 to 5v of Ethernet shield , 3rd pin to GND. 2nd pin is connected to A0

Analog pin.

Connect the USB cable from ARDUINO to PC & note the PORT allotted.The RJ45 STRAIGHT CABLE is connected from Ethernet shield to Router directly.

Upload the following code on to Arduino.You need not change the MAC address.

You need to change the Gateway IP as per your Router & also change the IP of shield in this range.

Also you need to change the THINGSPEAK API according to your CHANNEL setting

Download Arduino CODE Here


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

int pin = 0; // analog pin
int tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;

// Local Network Settings
byte mac[]     = { 0xD4, 0xA8, 0xE2, 0xFE, 0xA0, 0xA1 }; // Must be unique on local network
byte ip[]      = { 192,168,0,150 };                // Must be unique on local network
byte gateway[] = { 192,168,0,1};
byte subnet[]  = { 255, 255, 255, 0 };

// ThingSpeak Settings
char thingSpeakAddress[] = “”;
String writeAPIKey = “QGBA1G3872XSHBAC”;    // Write API Key for a ThingSpeak Channel
const int updateInterval = 10000;        // Time interval in milliseconds to update ThingSpeak

// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;

// Initialize Arduino Ethernet Client
EthernetClient client;

void setup()

Ethernet.begin(mac, ip, gateway, subnet);
Serial.print(“ETHERNET SHIELD ip  is     : “);
// Start Ethernet on Arduino

void loop()

tempc = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;

String analogPin0 = String(tempc);

// Print Update Response to Serial Monitor
if (client.available())
char c =;

// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)


// Update ThingSpeak
if(!client.connected() && (millis() – lastConnectionTime > updateInterval))

lastConnected = client.connected();

void updateThingSpeak(String tsData)
if (client.connect(thingSpeakAddress, 80))
client.print(“POST /update HTTP/1.1\n”);
client.print(“Connection: close\n”);
client.print(“X-THINGSPEAKAPIKEY: “+writeAPIKey+”\n”);
client.print(“Content-Type: application/x-www-form-urlencoded\n”);
client.print(“Content-Length: “);


lastConnectionTime = millis();

if (client.connected())
Serial.println(“Connecting to ThingSpeak…”);

failedCounter = 0;

Serial.println(“Connection to ThingSpeak failed (“+String(failedCounter, DEC)+”)”);


Serial.println(“Connection to ThingSpeak Failed (“+String(failedCounter, DEC)+”)”);

lastConnectionTime = millis();

void startEthernet()


Serial.println(“Connecting Arduino to network…”);


// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
Serial.println(“DHCP Failed, reset Arduino to try again”);
else {
Serial.println(“Arduino connected to network using DHCP”);
Serial.println(“Data being uploaded to THINGSPEAK Server…….”);





You need to sign up with  to upload your data to the server.

Open your account on THINGSPEAK & select MYCHANNELS under CHANNELS




Feed in Name & Description of your channel & under FIELD1 enter name of field like TEMPERATURE

Scroll down & Enable PUBLIC VIEW.


Save the CHANNEL & then click on API KEY tag


Note down the WRITE API KEY


Replace this code with yours inside the Arduino code.


Upload the code.

Please ensure that you’ve changed following settings in your code before uploading:

1. Gate way IP of your Router.

2. IP address of your Shield in range with gateway IP.

3. Thingspeak  API WRITE KEY from your Channel


Once uploaded you can open the Serial Monitor of Arduino , to see data being uploaded to the Server


On your THINGSPEAK Channel click on Public View to see the Graphical representation of the LM35 data being uploaded.


If you get Arduino Failed to connect to Network,  then you need to check the IP address credentials again.


HTTP POST Method to write data on to server


In the Arduino code data is converted to STRING type & uploaded to Thingspeak. Thingspeak server accepts only String type data.,

The HTTPS method used in code is POST method .Other HTTPS methods are  GET ( to read data), PUT ( to update data), DELETE ( to delete data).

Understand the basics of this method which we will be using in upcoming posts of ESP8266 & other IOT related projects.

We use POST to submit data to THINGSPEAK Server.

POST request is a bunch of STRINGs.

Each request line is separated & ends with a newline.


client.print(“POST /update HTTP/1.1\n”);
client.print(“Connection: close\n”);
client.print(“X-THINGSPEAKAPIKEY: “+writeAPIKey+”\n”);
client.print(“Content-Type: application/x-www-form-urlencoded\n”);
client.print(“Content-Length: “);


The first string is the Message STARTLINE which has 3 elements separated by SPACE

POST /update HTTP/1.1\n

First element is the URI –Uniform Resource Identifier ( not URL) which is nothing but the method POST all in capital letters. Next element is the protocol /update & the 3rd element is the version  HTTP/1.1 . At the end  \n is used for new line , or you can use println instead of print.

Once we send the message start line string, then we need to  send different header fields. The HEADSER FIELDS are  predefined fields that give the Thingspeak server , information about our POST request. Apart from standard fields , there’s some non-standard fields.

If it’s a non-standard field, the header name is usually preceded by an x. Each header field that we send is going to be its own string, separated by a newline.

We’re going to send following different Headers :

1.Host header field,

2.Connection header field,

3.The x ThingSpeak API key header field,

4.Content type header field,

5.  Content length header field.

1} For ThingSpeak, the host is going to be —–>

2) For the connection header, we specify close, and that’s because after we make our request and after we get our response, we want to close the connection with the server. There’s no need to keep that connection open between sending information, so we close it.

3) The X-ThingSpeak API key header is a non-standard header, and that is going to be set to our Write API key that we can find out  from our ThingSpeak channel.

4) The content type header is going to indicate the kind of media that we planned on sending in the header body, In HTTP there are two ways to POST data:




We use the first one as we update string data.

For application/x-www-form-urlencoded, the body of the HTTP message sent to the server is essentially one  query string — name/value pairs are separated by the ampersand (&), and names are separated from values by the equals symbol (=).

5) The content length header specifies the size of the media that we’re going to be sending in bytes.


Once we’ve set the header fields, the last thing we do is send the message body.

The message body is the actual data that we want to update & post to the server. Just like the message start line, and just like the header fields, the message body is going to be a string of text. The message body is  separated from the header fields by two newlines.

client.print(“\n\n”);     // 2 new lines


Those two newlines are what let the server know that  we’re done with the header fields & we’re moving on to the message body.

Our message body is simply listing the field that we want to update with an equals sign followed by the value that we want to update it as.


If we want to do multiple fields, we separate them with the “and” sign. There’s no spaces in this message body

We’ve got the message start line. We’re identifying the method, the URI, the resource we want to use, and the protocol type. Then we specify the header fields. This is giving information to the server about the request that we’re making.

Finally, we have the actual message that we’re sending.

That makes up a basic HTTP POST  request



cooltext753793315   cooltext753790696


In the previous post we’ve seen how to program ESP8266 using Arduino IDE by installing the Boards Manager.

This post is on using the powerful ESP8266 WiFi Library which is automatically installed while using the Boards Manager.When you proceed with the  board package for the ESP8266,as explained in previous post, the ESP8266 WiFi library is automatically installed for you.

Now, any time you want to use the classes and the functions from that ESP8266 WiFi library,  use the Include statement at the top of the program first, followed by the header name

#include <ESP8266WiFi.h>

at the starting of Arduino code & start using the Classes associated with this library.

ESP8266 WiFi library is designed after the the standard Arduino WiFi library but has even more functionality than the standard Arduino library .The standard Arduino WiFi library is used for the WiFi shield or with the Arduino boards like YUN with inbuilt WiFi.

With the introduction of ESP8266 , the WiFi functionality has become much cheaper & easy to use.

The WiFi library has many classes that you can use. Each class has functions in it that are specific to that class. There’s the WiFi class, the IP address class, the server class, the client class and the UDP class.




In this post we’re going to explore the WiFi class & its functions.

The WiFi class allows to establish a connection with an access point.

What’s cool about the WiFi class is that we don’t  have to create an instance of this class. We can  go ahead and start using it. It’s like the serial library of Arduino. We don’t need to create an instance of the serial library.



First Function of the library is WiFi.begin().

The usage of this function is similar to our Serial.begin().

Just like Serial.begin() , we use WiFi.begin() .WiFi.begin() requires 2 strings as arguments. You need to pass the SSID and the password of the Access point you wish to connect.You need to pass the arguments as character arrays or strings with a lower case s.


The possible return values are

WL_CONNECTED      after successful connection is established with the Access Point

WL_IDLE_STATUS       when Wi-Fi is in process of changing between statuses

WL_NO_SSID_AVAIL     in case configured SSID cannot be reached

WL_CONNECT_FAILED  if password is incorrect

WL_DISCONNECTED        if module is not configured in station mode


The status function in the WiFi class, doesn’t take any arguments but it returns stuff depending on the status of the network that you’re connected to.

Usually, first, you call WiFi.begin, you pass the SSID and the password because you’re trying to establish a connection with the network. Then, what you do is you wait in a loop until WiFi.status returns the value WL_CONNECTED.



while (WiFi.status() != WL_CONNECTED)








WiFi.SSID doesn’t take any arguments but it returns the name of the SSID that you’re connected to.



Returns the current signal strength in  dB



Returns the number of discovered networks.It will not list the network names , but returns the number of networks.


Returns the MAC address of the ESP device

There is a specific function available to print out key Wi-Fi diagnostic information:


Here is a sample sketch to demonstrate the WiFi library.


#include <ESP8266WiFi.h>

void setup()

//disconnect any previous connections

//scan for number of nearby networks & print SSIDs

Serial.print(“Nearby networks found  :”);

Serial.println(“List of surrounding Network SSIDs…:”);
int n = WiFi.scanNetworks();
for (int i = 0; i < n; i++)

//connect to preferred SSID

WiFi.begin(“SARAVANA-ACT”, “mypass123”);

while (WiFi.status() != WL_CONNECTED)

// print SSID name,local IP allotted ,MAC address & signal strength

Serial.print(“Connected to SSID          : “);

Serial.print(“IP address allotted to ESP : “);

Serial.print(“MAC Address of ESP         : “);

Serial.print(“Signal strength is         : “);


void loop()


The screenshot shows the result in the serial monitor of Arduino IDE



The Client & Server classes & their methods are shown in screen shots below :





Here is the complete tutorial link for the WiFi library :

cooltext753793315   cooltext753790696

The ESP8266 by itself hosts a 32 bit Microcontroller on it & you can now program your ESP using Arduino IDE. Best part is that NO Arduino board is required.You can upload your code from Arduino IDE , as if you were upgrading the Firmware on ESP.

You can pretty much write any code  for an Arduino and run it on the ESP8266. Of course there is a limit to the I/O on some of the modules, but the Flash on the ESP-12E (Black) module is 4MB and the RAM is 80kB! Add to that the 80MHz 32-bit processor and you have a pretty impressive little cute Arduino.

A sample Blink example program on the ESP8266 turns out to be around 225kB, but that includes the core code.So it’s advisable to use an ESP8266 with more FLASH Memory.Generally the BLACK ones are with higher memory than the Blue ones.The new ESP12E has a Flash of whooping 4MB !!  The Arduino UNO has just 32k Flash & Mega 256k.





Program uploading is done at 115,200 Baud, the default for the module. But It still takes a while to upload a sketch to the module , unlike a regular Arduino.

To begin, you must install the ESP8266 board files in the Arduino IDE.

That is easy enough to do. Make sure that your Arduino IDE is latest

Open the Arduino preferences from File  —> Preferences

Image 1


Add the following URL to the “Additional Boards Manager URLs” seen at the bottom of Preferences Window

Image 2


Click OK to close the Preferences Window.


Image 4

When the Boards Manager opens, scroll to the bottom. You should see the esp8266 entry.

Select the latest version & then click on INSTALL button.


It takes a while to download & install .


Image 6

Once installation is over , close the IDE & start again,

Under Tools –> Boards you can now see a new list of ESP8266 Modules.

Image 7

Its time to test some example code.

While using the ESP module make sure that

Power source is 3.3v DC

CH_PD & RESET pins pulled HIGH through resistor.

You can use a development board available at


An LED is connected to GPIO4 through a resistor.

Image 22

An USB-TTL board is used to connect ESP with USB port of PC.

Rx of USB-TTL board goes to Tx of ESP board

Tx of USB-TTL goes to Rx (3.3v level) of ESP board

GND is made common.

5v of USB-TTL is connected to Vcc of ESP board.As the ESP board has a built in 3.3v regulator we can connect to 5v safely.

Connect the GPIO0 pin to GND.



Open the Arduino IDE & select the COM port allotted to the USB-TTL board.

Other settings are done under Tools tab as seen in screenshot below :


From File —> Examples —> ESP8266 select the BLINK sketch.

As we’ve connected an LED at GPIO4 pin , change the pinMode & digitalWrite pin to 4.

Ensure that GPIO0 is connected to GND & click on UPLOAD button.

It takes a while to compile & then uploading starts.


Once the Uploading is done the LED connected at pin 4 , starts blinking.

Remember to upload another sketch, you need to ground GPIO0 and push the reset switch. The ESP8266 will be put in UPLOAD mode.

When the upload is done, the sketch will start running. If you reset with GPIO0 still grounded, the sketch will not start running because the ESP8266 will be in PROGRAMMING mode. To exit programming mode, remove the ground from GPIO0.




In the next post we shall see how to use the built in WIFI library in your code.

cooltext753793315   cooltext753790696

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.





Image 5

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

So I’m assigning the IP of Ethernet shield by changing the last byte of the address , say,

Image 1


Here is the sketch used in this demo :


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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 150 }; // IP address in LAN – need to change according to your Network address
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString;
int ledPin = 2;

void setup(){

    pinMode(ledPin, OUTPUT); //pin selected to control
    // Test LED
    digitalWrite(ledPin, HIGH); // set pin high
    digitalWrite(ledPin, LOW); // set pin low
    //start Ethernet
    Ethernet.begin(mac, ip, gateway, subnet);

void loop(){
    // Create a client connection
    EthernetClient client = server.available();
    if (client) {
        while (client.connected()) {
            if (client.available()) {
                char c =;

                //read char by char HTTP request
                if (readString.length() < 100) {

                    //store characters to string
                    readString += c;

                //if HTTP request has ended– 0x0D is Carriage Return \n ASCII
                if (c == 0x0D) {
                    client.println("HTTP/1.1 200 OK"); //send new page
                    client.println("Content-Type: text/html");

                    client.println("<TITLE> ARDUINO ETHERNET SHIELD</TITLE>");
                    client.println("<H1 style=\"color:green;\">ARDUINO ETHERNET SHIELD — LED ON/OFF FROM WEBPAGE</H1>");

                    client.println("<H2><a href=\"/?LEDON\"\">Turn On LED</a><br></H2>");
                    client.println("<H2><a href=\"/?LEDOFF\"\">Turn Off LED</a><br></H2>");


                    //stopping client

                    // control arduino pin
                    if(readString.indexOf("?LEDON") > -1) //checks for LEDON
                        digitalWrite(ledPin, HIGH); // set pin high
                        if(readString.indexOf("?LEDOFF") > -1) //checks for LEDOFF
                            digitalWrite(ledPin, LOW); // set pin low
                    //clearing string for next read



  The Arduino talks to Ethernet shield over SPI Serial Peripheral Interface. So to work with the shield you need to include both the Ethernet & SPI libraries in the top of the sketch.

#include <SPI.h>

#include <Ethernet.h>


The next piece of information is the MAC address of the shield , usually expressed as 6 bytes.

If your Shield has the address printed , use that MAC address.Otherwise you can settle for a random 6 bytes , as it is unlikely that another device of same address exists in the same network.

The MAC address is typically included in the Arduino sketch as global array of bytes.

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

The server is assigned on  HTTP port 80

EthernetServer server(80);

PIN 2 is assigned to LED & a string variable readString is assigned to store the request.

Under void SETUP

The method begin() in the Ethernet class attempts to connect to the Network using the details passed into its arguments.

Here we pass an IP address & the Ethernet shield makes a Network connection using a STATIC IP address.

Ethernet.begin(mac, ip, gateway, subnet);


starts listening on the HTTP port 80

To check the IP connection press WIN Logo key +R & then type in CMD

Ping the IP address of the Shield.

If you get back result , then you’re ready to connect the client.

Image 6

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

The following CLIENT REQUEST & SERVER RESPONSE happens in the background.

Client Request :

When you surf to the IP address of the Arduino server, the web browser (client) will send a request, such as the one shown below, to the server.

GET / HTTP/1.1\r\n


The information in the request will differ, depending on the browser and operating system that the request is sent from.

The \r\n characters that you see at the end of every line of text in the request are non-visible characters (non-printable characters). \r is the carriage return character and \n is the linefeed character (or newline character).

The last line of the request is simply \r\n without and preceding text. This is the blank line that the Arduino sketch checks for before sending a response to the client web browser.

In other words, the sketch reads every character from the above request and knows when the end of the request has been reached because it finds the blank line.

Server Response :

After receiving the request for a web page from the client, the server first sends a standard HTTP response and then the web page itself.

The response sent from the Arduino is as follows:

HTTP/1.1 200 OK\r\n

Content-Type: text/html\r\n

Connection: close\r\n


Again the non-visible characters \r\n are shown in the above response.

The println() function in the the sketch automatically adds the \r\n characters to the end of each line. The empty println() function at the end of the HTTP response simply sends the \r\n with no text in front of it.

The above request and response are part of HTTP

Web Page

After the server has sent the HTTP response, it sends the actual web page which is then displayed in the browser.

The web page consists of text with HTML tags. You do not see the tags in the browser as these tags are interpreted by the browser.

The actual HTML markup tags are shown below.











<h2><a href="/?LEDON" "="">Turn On LED</a><br></h2>

<h2><a href="/?LEDOFF" "="">Turn Off LED</a><br></h2>



In the Arduino sketch you can see these HTML tags sent using

client.println command

Now the browser displays the WEB PAGE sent as response from the Server.

Click on

Turn On LED   -  to see the LED going ON

Turn Off LED   – to make the LED OFF

indexOf String function is used to search for the string LEDON or LEDOFF.

The indexOf function returns a –1 if it doesn’t find the wanted string.This function is used to make the LED ON or OFF accordingly.

0Image 2


Image 3


Image 4


Instead 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.



This post is on retrieving particular Data from a web page using SIM900A & Arduino.

For e.g we shall retrieve the Blog Status hits of my blog in which you’re reading this.

We’ve to create an API link for this data so that data can be retrieved using SIM900A.

To create API link we use the website.

First let us read the XPATH details of the data wanted as below :

The procedure is related to Google Chrome WebBrowser


Image 1


Right click on the data to be retrieved & click on INSPECT .




A highlighted code will be displayed on which Right click & then select COPY  –> COPY XPATH



The copied XPATH detail has to be used in THINSPEAK account to create the API link.

Open your thingspeak account & click on APPS –> THINGHTTP



Click on NEW THINGSPEAK to create a new “thing”.



You can provide a suitable Name for the App & under URL provide the website link from where you want the data from.

Method is GET & version is 1.1



Scroll down to bottom & under the PARSE STRING field paste the XPATH copied from the website.


Click on SAVE & you see the API LINK generated.



You can use this API link in your browser to confirm the data retrieved.

Image 15

Now let us see the practical application using SIN900A GSM & ARDUINO.

The connections between Arduino & GSM are :

Rx of GSM —> pin 8 (Tx) of Arduino   (since we use the SoftSerial in Arduino code , we declare pins 7 & 8 for Serial communication)

Tx of GSM –> pin 7 (Rx) of Arduino


A separate power source is required for the GSM.

Following are the AT commands used


DOWNLOAD Arduino code HERE


#include <SoftwareSerial.h>
SoftwareSerial myGsm(7,8);

void setup()


myGsm.println(“AT+SAPBR=3,1,\”CONTYPE\”,\”GPRS\””);//setting the SAPBR,connection type is GPRS

myGsm.println(“AT+SAPBR=3,1,\”APN\”,\”\””);//setting the APN,2nd parameter empty works for all networks


myGsm.println(“AT+HTTPINIT”); //init the HTTP request

myGsm.println(“AT+HTTPPARA=\”URL\”,\”\””);// setting the httppara,
//the second parameter is the website from where you want to access data

myGsm.println(“AT+HTTPACTION=0”);//submit the GET request
delay(8000);//the delay is important if the return datas are very large, the time required longer.
myGsm.println(“AT+HTTPREAD=0,20”);// read the data from the website you access

myGsm.println(“AT+HTTPTERM”);// terminate HTTP service


void loop()

void printSerialData()



AT+SAPBR is used to declare the Connection Type as GPRS

& Then the APN –Access Point Name of the mobile service provider is given.

An empty string also will work.Or you can slide the SIM into your Android mobile

under Settings –. More –> Cellular Networks  –> Access Point Names

you get the APN details

AT+SAPBR=1,1  enables the GPRS & APN settings & then HTTP is initialized with AT+HTTPINIT

HTTP parameters are then provided as “URL” & the API link we created earlier.

Note to use HTTP ( not HTTPS) in the link, as we use AT commands for HTTP only here.

AT+HTTPACTION=0 enables GET action

The GSM respons with


Here 0 means GET action & 200 means OK , 12 bytes are retrieved.

If you get 600 instaed of 200 ,then it means a Network Error.

AT+HTTPREAD command is used to read the Data.


Image 11

cooltext753793315   cooltext753790696

Serial LCD I2C Module–PCF8574


A regular LCD requires a lot of wires (parallel interface) to be connected with a Microcontroller.The Serial LCD  backpack built on PCF8574 IC uses the I2C bus to convert  the parallel interface to a serial one.This needs only 2 wires SDA & SCL , apart from the power connections.

The I2C backpack can be soldered on to the LCD .It can be used for 16 x 2 , 16 x 4  &  20 x 4 LCDs that have HD44780 IC .




The blue preset is to adjust the contrast of the LCD. The black jumper on the left is to enable the Backlight of LCD. The I2C device has a HEX address by which a microcontroller can communicate with it.This is set by the 3 bits A0,A1 ,A2 .If no jumper is present , it is HIGH &  a jumper means LOW. By default all the 3 jumpers are open . ie., A0,A1 A2 all are 1s.

By setting this address lines you can connect upto 8 devices to the same I2C bus.

Eight programmable slave addresses possible using these three address pins.



The I2C bus has 2 bidirectional active wires SDA & SCL .They are joined to positive supply through a pull up resistor of 4k7.When the bus is  idle both lines are pulled high.

The expanders can be configured to have a unique 7 bit address. The first 4 bits are factory configured to

0100 for PCF8574/PCF8574T

0111 for PCF8574A

The lower 3 bits are settings on device pins A2,A1,A0.

The eighth bit specifies whether the following data is a Read  or Write operation.

Following table describes how the address is arrived.By default the factory setting is A2,A1,A0 all open leading to all 111.

First 4 bits are factory set to 0100 for PCF8574T/PCF8574 .If the port expander IC is PCF8574A , the first 4 bits will be 0111.

For calculating the address a 0 is added at the MSB (R/W bit not taken into account for calculation)

Hence the default I2C address of the module is HEX 0x27 .






Now let us see how to use this backpack with Arduino UNO.

To start with download the latest Library from this link :

NewliquidCrystal_1.3.4 is the latest file at the time of writing this blog


Unzip the downloaded file & copy the folder NewliquidCrystal.

Paste this folder into your Arduino libraries folder.

Generally the path is C:\ProgramFiles\Arduino\libraries





Now open the Arduino IDE (make sure your Arduino IDE is the latest version).

Under File –> Examples , you can see the NewliquidCrystal



To know the I2C address of the device there is a scan code in Arduino forum.

Before starting the test , make sure that the I2C back pack is soldered properly on to the LCD.Here we make use of a 16 x 2 LCD.

Connections between Arduino & I2C LCD  are done as below :



Upload the scanner code on to the Arduino. Open the Serial monitor & set the baud rate to 115200.

The code scans for the I2C devices & lists the address in HEX format.

In our test we’ve connected a backpack I2C with no jumpers on A2,A1,A0 , which results in 0x27

This is the Slave address of the device.



The LCD Library & some sample code can be downloaded from :


Once the connections are made, open the Arduino IDE .Make sure that you use the IDE later than 1.6.0 version.

The Hello world sketch includes 2 header files – wire.h &  LiquidCrystal_I2C.h

A new object named lcd is instantiated using the constructor LiquidCrystal_I2C which takes parameters 0x27,2,1,0,4,5,6,7

Here 0x27 is the slave address of I2C backpack.



The next parameter 2 represents P2 pin of PCF8574 which is connected to EN of the LCD.

The parameter 1 is the P1 pin connected to R/W of LCD.

The parameter 0 is the P0 pin connected to RS of LCD.

4,5,6,7 are the 4 data pins connected to D4,D5,D6,D7 of LCD.

Inside setup , lcd.begin(16,2) ;   initializes the 16 x 2 LCD .Then the lcd.setBacklightPin(3,POSITIVE);

makes the P3 pin makes the P3 pin to control the backlight of LCD.

lcd.setBacklightPin(HIGH);  makes the P3 pin go High, which turns on the NPN transistor.This provides GND to the LED pin of LCD As the other LED pin is already connected to Vcc through the jumper , the LCD backlight glows.

lcd.home(); takes the cursor to 1st column , 1st Row of LCD.

lcd.print() prints the message.

lcd.setCursor(0,1); takes the cursor to 1st Column , 2nd Row. Make note that the counting starts from 0.

The following is the connection diagram between PCF8574 IC & the LCD .Once you solder the backpack on to LCD, these connections come into effect.


Image 2



Image 3


The next sketch is lcd_serialprint.

This code waits for you to type in message in the serial monitor of Arduino & then displays it on the LCD.




Next code shows the capability of connecting more than 1 device to the same I2C bus.

2 LCDs are connected to the same I2C bus A4,A5 of Arduino.External power source is used as Arduino can’t source power to both LCDds.

The backpack connected to 16 x2 LCD has no jumpers soldered to A0,A1,A2 .Hence the address is the default 0x 27.


The backpack connected to 20 x 4 LCD has A0 pin soldered, which makes the address 0x26.

By initiating the LCDs with their slave address, messages can be displayed on to the correct slave LCD.








cooltext753793315   cooltext753790696



Watch this support Video :


The Arduino board can be connected to the Internet using this Ethernet Shield which is based on the

WIZNET W5100 Ethernet chip . The Wiznet W5100 provides a network (IP) stack capable of both TCP and UDP.

WIZNET W5100 is the classic one , widely used by Arduino.CC .

WIZNET W5500 is used by Arduino.ORG & is referred as Ethernet shield 2.

We shall use the classic Ethernet shield W5100 in this post.

The shield has long pin headers to plug on the Arduino (UNO or MEGA). Other shields can be stacked on top of this board.There is an onboard micro-SD card slot, which can be used to store larger files.

The Ethernet Library is used to write sketches which connect to the internet using the shield. You need not download the library , as it is inbuilt in Arduino IDE.

The on-board micro SD card reader is accessible through the SD Library. Both the SD card reader & Ethernet board work on SPI bus .

The shield also includes a reset controller, to ensure that the W5100 Ethernet module is properly reset on power-up.

This board is different from the economy version using ENC28J60 device.The library for this ENC is different , ETHERSHIELD library hosted by NANODE project.Libraries are different for WIZNET board & ENC board.

Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega.

On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card. These pins cannot be used for general I/O. On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won’t work.

As the W5100 and SD card share the SPI bus, only one can be active at a time. If you’re not using one of the peripherals in your program, however, you’ll need to explicitly deselect it. To do this with the SD card, set pin 4 as an output and write a high to it. For the W5100, set digital pin 10 as a high output.

The shield provides a standard RJ45 Ethernet jack.A straight RJ45 cable is used to connect the shield to the Router.

A RESET  button is on the shield which resets both the W5100 and the Arduino board.

The shield contains a number of informational LEDs:

  • PWR: indicates that the board and shield are powered
  • LINK: indicates the presence of a network link and flashes when the shield transmits or receives data
  • FULLD: indicates that the network connection is full duplex
  • 100M: indicates the presence of a 100 Mb/s network connection (as opposed to 10 Mb/s)
  • RX: flashes when the shield receives data
  • TX: flashes when the shield sends data
  • COLL: flashes when network collisions are detected

Apart from these LED s , there are 2 more LEDs seen below the RJ45 jack.When Ethernet cable is inserted from a working Router , you can see these LEDs glowing below the RJ45 jack, one glows steadily & the other blinks as per data flow.

The examples in this section will all make use of the Arduino Ethernet Library.This library comes with Arduino, so no downloading or installing required

You can see the examples under File –> Examples –> ETHERNET



The Ethernet library allows the Arduino to turn into one of two Ethernet devices: a client or a server. Turning your Arduino into client allows you to connect to and request data from servers.

Another  example included with Arduino’s Ethernet library is WebServer.  This sketch sets up the Arduino as a server device, and hosts up a webpage whenever a client connects to it. The webpage is simple – it shows the status of the analog pins.

Open the WEBSERVER sketch

Webserver is a simple sketch which will display on a web browser, the data gathered from the analogue inputs. However don’t upload it yet, it needs a slight modification.

You need to specify the IP Address of the Ethernet shield – which is done inside the sketch. This is simple, go to the line:

IPAddress ip(192,168,1,177);



You can alter it to match your own setup. For example, in my home the router’s IP address is, the pc is assigned , the tablet is assigned  , .. As the IP address is in the range , I just leave this to

You also have the opportunity to change your MAC address.As we use only one shield , we can leave this as it is.

To know the IP address , go to Control panel –> Network & Internet –> Network & Sharing Center

Click on your Internet connection .On the next window click Details to see the IPV4 address of your PC.






You can also use a IP SCANNER tool to know all the IP address allotted by your Router



Now upload the sketch to your Arduino.

Open your web bowser & type in the IP address , the port address 80 is default for HTTP.Hence you need to type just the address in the URL bar ,skipping the :80 part.

The web browser will query the ethernet shield, which will return the values from the analogue ports on the Arduino board.As such we’ve not connected anything to the Analog pins of Arduino, you get random values refreshed every second.




Remember , this is from a local browser & not from outside world.If you like to see the webserver from anywhere in the world , you need to PORT FORWARD your Static IP address to this local IP address .This is set inside the Router’s configuration.

If your IP is not Static (mostly Dynamic which changes on every reboot) , you need to register with a service like

For more details of port forwarding , consider reading this post & video


A simple sketch to print out the Gateway IP, IP of your Ethernet board, DNS is given below :


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

byte mac[] = { 0x00, 0xC3, 0xA2, 0xE6, 0x3D, 0x57 };

void setup() {

while (!Serial);
Serial.print(“Establishing network connection… “);

if (Ethernet.begin(mac) == 0) {
else {

Serial.print(“IP Address: “);

Serial.print(“Default Gateway: “);

Serial.print(“Subnet Mask: “);

Serial.print(“DNS Server: “);

void loop() {



Upload the sketch & open the Serial monitor to see the result.



Example Sketch 2 : Display a web page from Arduino



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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177); // change IP address according to your network
EthernetServer server(80);  // create a server at port 80
void setup()
Ethernet.begin(mac, ip);  // initialize Ethernet device
server.begin();           // start to listen for clients

void loop()
EthernetClient client = server.available();  // try to get client

if (client) {        // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {   // client data available to read
char c =; // read 1 byte (character) from client
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == ‘\n’ && currentLineIsBlank) {
// send a standard http response header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connection: close”);
// send web page
client.println(“<!DOCTYPE html>”);
client.println(“<title>Arduino Web Page</title>”);
client.println(“<h1>Hello from Arduino!</h1>”);
client.println(“<p>A web page from the Arduino server</p>”);
// every line of text received from the client ends with \r\n
if (c == ‘\n’) {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
else if (c != ‘\r’) {
// a text character was received from client
currentLineIsBlank = false;
} // end if (client.available())
} // end while (client.connected())
delay(1);      // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)