Вы находитесь на странице: 1из 8

8/28/2017 ESP8266 Tutorial: How to Control Anything From the Internet!

| DIY Hacking

ESP8266 Tutorial: How to Control Anything From the


Internet!
By Robin Thomas

In this ESP8266 tutorial, we are using anESP-01 module to control an LED over the internet.The ESP8266 is a very cheap yet really e ective
platform for communicating over the internet. It is also easy to use with an Arduino. After going through this ESP8266 tutorial, you will
have the know-how to control any electrical device through the internet from anywhere in the world!

Here,we will be using an USB to TTL converter to program the Esp8266 ESP-01module.And well be using theArduino IDE to develop the
web server to control an LED remotely. If you just bought your module, you can also refer my previous ESP8266 tutorial to see how to get
started with the ESP-01 Wi-Fi module. It also shows how you can con gure it and verify that there is communication established between
the ESP8266 and another device without using a USB to TTL converter.

Bill of Materials
1. Arduino board or USB to TTL converter
2. LED
3. ESP8266
4. Breadboard
5. Female to male and male to male jumpers
6. Lm117 3.3 voltage regulator

How Does it Work?


The ESP8266 can be controlled from your local wi network or from the internet (after port forwarding). The ESP-01 module has GPIO pins
that can be programmed to turn an LED or a relay ON/OFF through the internet. The module can be programmed using an Arduino/USB to
TTL converter through the serial pins (RX,TX).

https://diyhacking.com/esp8266-tutorial/ 1/8
8/28/2017 ESP8266 Tutorial: How to Control Anything From the Internet! | DIY Hacking

Connecting the Hardware to Your ESP8266


We can either use a USB to TTL converter or use an Arduino to program the Esp8266. Here there are three methods you can follow to
upload the code to ESP8266, select the one which suits you best.Refer the following diagrams for each and set up the hardware
accordingly.

1.USB to TTL Converter Using DTR Pin


If youre using a USB to TTL converter which has a DTR pin, then uploading will go smoothly. Please be informed that Serial monitor will not
work anymore while doing this.

USB TTL > ESP8266 ESP-01


GND>GND
TX>RX
RX>TX
RTS->RST
DTR->GPIO0

2. USB to TTL Converter Without DTR Pin

https://diyhacking.com/esp8266-tutorial/ 2/8
8/28/2017 ESP8266 Tutorial: How to Control Anything From the Internet! | DIY Hacking

To connect the USB TO TTL converter without the DTR pin we have to use manual ashing. For this, we use two push buttons. Refer the
following diagram:

USB TTL -> ESP8266 ESP-01


GND->GND
TX->RX
RX->TX
Reset Button>RST
Flash Button>GPIO0

While uploading the code, press the ash button. Keep the ash button pressed while you click once on reset. You may now release the
ash button. The ESP8266 is now in ash mode! You will beable to upload the sketch now.

Using Arduino Uno to Flash the Code to the ESP8266


You can use the Arduino UNO to ash the code to ESP8266 ESP-01.While uploading the code, follow the same procedure to keep the ash
button pressed while you once click on reset and release the ash button.

https://diyhacking.com/esp8266-tutorial/ 3/8
8/28/2017 ESP8266 Tutorial: How to Control Anything From the Internet! | DIY Hacking

ARDUINO > ESP8266 ESP-01


GND->GND
TX>TX
RX>RX
Reset Button>RST
Flash Button>GPIO0

Uploading the ESP8266 Code


Use any one of the methods shown above and open the Arduino IDE, then select your ESP8266 board from Tools > Board > Generic
ESP8266 Module.

Note: If you havent installed the ESP8266 boardsetup for Arduino, do that by following STEP 2 of this tutorial. And then continue with this
ESP8266 tutorial.

https://diyhacking.com/esp8266-tutorial/ 4/8
8/28/2017 ESP8266 Tutorial: How to Control Anything From the Internet! | DIY Hacking

Now copy thecode given below to the Arduino IDE and press theupload button. Change SSIDinto your wi access point, and change the
passwordto your wi password and compile.

Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server


server.begin();
Serial.println("Server started");

// Print the IP address


Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}

void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {

Open the serial monitor and open the URL shown in your serial monitor through your web browser. Connect GPIO 2 of the ESP8266 to the
longer lead of the LED (+ve terminal). Now you can control the LED remotely throughthe internet!

https://diyhacking.com/esp8266-tutorial/ 5/8
8/28/2017 ESP8266 Tutorial: How to Control Anything From the Internet! | DIY Hacking

Click on the respective hyperlinks in your browser to toggle the LED ON and OFF.

Removing the Programmer


Remove all the wires which were required for uploading. Lm117 is used to provide regulated 3.3V output. This will let you make the
ESP8266 or ESP-01 module stand alone.

https://diyhacking.com/esp8266-tutorial/ 6/8
8/28/2017 ESP8266 Tutorial: How to Control Anything From the Internet! | DIY Hacking

Connecting the ESP8266 to the Internet


Currently, the ESP8266 module can only be accessed through the local wi network. In order to control your devices from the internet, you
have to do port forwarding on your router.

To do this, nd the IP address of your system either by using the ifcon g command on your terminal or go
to:http://www.whatsmyip.org/. Copy down your IP address. Now open your router setting and goto the Forwarding settings. Enter the
details for the Service Port and IP Address. The service port is the port number from your Arduino code (Service port: 80):

WiFiServer server(80);//Service Port

And the IP address is the one you noted down before. Leave the other settings as default. Now go to your browser and enter the address:
xxx.xxx.xx.xx:80. This should open up the page for controlling the LED. For a detailed tutorial on port forwarding, check this: tutorial.
Check out the demo video for this ESP8266 tutorial:

Esp8266 as Webserver

Thanks for reading this ESP8266 tutorial. Comments and Questions are welcome!

https://diyhacking.com/esp8266-tutorial/ 7/8
8/28/2017 ESP8266 Tutorial: How to Control Anything From the Internet! | DIY Hacking

https://diyhacking.com/esp8266-tutorial/ 8/8

Вам также может понравиться