ESP8266 WiFi Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor. Each ESP8266 module comes pre-programmed with an AT command set firmware, meaning, you can simply hook this up to your Arduino device and get about as much WiFi-ability as a WiFi Shield offers (and that's just out of the box)! The ESP8266 module is an extremely cost effective board with a huge, and ever growing, community.

This module has a powerful enough on-board processing and storage capability that allows it to be integrated with the sensors and other application specific devices through its GPIOs with minimal development up-front and minimal loading during runtime. Its high degree of on-chip integration allows for minimal external circuitry, including the front-end module, is designed to occupy minimal PCB area. The ESP8266 supports APSD for VoIP applications and Bluetooth co-existance interfaces, it contains a self-calibrated RF allowing it to work under all operating conditions, and requires no external RF parts.
ESP8266 PIN Diagram
 
Fig.1

Wire Diagram of ESP8266
 
Fig.2


Vcc ==> with 3.3V of  board.
GND ==> with GND of board.
Rx ==> with Tx of board.
Tx ==> with Rx of board.
CH_PD ==>  with 3.3V of  board.

Wire Diagram of Relay module 
 
Fig.3

Now connect your Arduino UNO board and ESP8266 module  and Relay Board as you seen in Fig.3 , After that open Arduino IDE and select the board “Arduino UNO” like Fig.4.
 
Fig.4

Now, put the below code in your sketch and save the sketch ,and compile the code and  upload  sketch on ArduinoUno board. 
                                                         

Fig.5

Arduino Code:

---------------------------------------------------------------------------------------------------------------------
volatile char MY_DATA1[60];
volatile unsigned char k1 = 0,CC1=0,RX1 = 0,D = 0;
void setup()
{
// relay out put pin control.//
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
digitalWrite(A0,HIGH);
digitalWrite(A1,HIGH);
digitalWrite(A2,HIGH);
digitalWrite(A3,HIGH);
// Initial setup //
Serial.begin(115200);
// Initial ESP8266 //
ESP8266_INIT();
}
void loop()
{
// receive data from ESP8266 //
if(Serial.available())
{
MY_DATA1[k1] = Serial.read(); // read receive data from wi-fi module.
CC1 = MY_DATA1[k1];
if(CC1 == ':')D = k1;// check weather data scan start or not.
k1++;
if(CC1 == '\n'){k1=0;RX1 = 1;} // chaeck new line character are receive or not.
}
// Processing  data which are receiving  from ESP8266 //
if(RX1 == 1)
{
if(MY_DATA1[D] == ':')
{
MY_DATA1[D] = '0';
if(MY_DATA1[D+1] == 'F')
{
MY_DATA1[D+1] = '0';

if(MY_DATA1[D+2] == 'A')//switch 1 on
{
MY_DATA1[D+2] = '0';
digitalWrite(A0,LOW);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'B')//switch 1 off
{
MY_DATA1[D+2] = '0';
digitalWrite(A0,HIGH);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'C')//switch 2 on
{
MY_DATA1[D+2] = '0';
digitalWrite(A1,LOW);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'D')//switch 1 off
{
MY_DATA1[D+2] = '0';
digitalWrite(A1,HIGH);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'E')//switch 3 on
{
MY_DATA1[D+2] = '0';
digitalWrite(A2,LOW);
RX1 = 0;
          }
else if(MY_DATA1[D+2] == 'F')//switch 1 off
{
MY_DATA1[D+2] = '0';
digitalWrite(A2,HIGH);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'G')//switch 1 on
{
MY_DATA1[D+2] = '0';
digitalWrite(A3,LOW);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'H')//switch 1 off
{
MY_DATA1[D+2] = '0';
digitalWrite(A3,HIGH);
RX1 = 0;
}
     }
}
RX1 = 0;
}
}
void ESP8266_INIT()// initializing wi-fi module.
{
Serial.println("AT");// check AT mode.
delay(1000);
Serial.println("AT+RST");//RESET module.
delay(3000);
Serial.println("AT+CWSAP=\"Home Automation\",\"4d_innovations\",3,2");//set the ssid and password.
 delay(1500);
Serial.println("AT+CWMODE=3");// set ESP8266 in MODE 3 (Both mode AP+station).
delay(1400);
Serial.println("AT+CIPMUX=1");// set ESP8266 in MUX 1 (allow multiple connection).
delay(1400);
Serial.println("AT+CIPSERVER=1,80");// start communication ESP8266 on PORT80.
delay(1500);
}

-------------------------------------------------------------------------------------------------------------------

After the uploading sketch on the Board you can see the blue blinkey LED on the ESP8266 board .after the same time open the WI-fi on your phone.before that you must be install the “socket control” widget from the google play store,for install this Application click on this link: 
When you click on this link you can find this page on you desktop or phone.
                                                          
Fig.6

Install this App and open this from your widget setting like Fig.7
 
Fig.7
 
Fig.8

When you click the socket control it will display on your home page, open this widget by clicking the name below the button , it’s look like the Fig.9
 
Fig.9
 
Fig.10
Add the IP address of your ESP8266 module, hear IP Address is :”192.168.4.1”,and Port Address of module, hear PORT address is: “80” and last one is DATA which you want to send, hear data is:”FA”. you can see in Fig.11
 
Fig.11
You can Add Identical 8 button on your home page ,hear also fill the same IP address and PORT address,but DATA will be difference, as per the code DATA list for 8 button is listed below.
Switch-1 ON ==> data is “FA”.
Switch-1 OFF ==> data is “FB”.
Switch-2 ON ==> data is “FC”.
Switch-2 OFF ==> data is “FD”.
Switch-3 ON  ==> data is “FE”.
Switch-3 OFF ==> data is “FF”.
Switch-4 ON  ==> data is “FG”.
Switch-4 OFF ==> data is “FH”.

Now open the WI-FI control setting on your phone and turn on the WI-FI .Scan the new near by WI-FI network around you. when the scan is completed you can see the “Home Automation” SSID in your scan list . Click on this SSID and connect this SSID using the “4d_innovations”  password.like Fig.12
 
Fig.12


Now you can easily control your home Application using the ESP8266 Wi-Fi module.if this tutorial helpful for you then like and subscribe to my youtube channel for more helpful tutorials thank you.