Firmware 1m for esp 01. ESP8266 microcontroller: connection and configuration. USB-to-TTL converter using DTR connector

In the process of studying and designing increasingly complex projects, the time comes when the need and desire arises to learn how to work with such a common type of communication as WiFi. Since this type of communication can allow you to comfortably create a single network for your smart home devices and manage them, for example, with mobile phone, tablet or computer, that is, in other words, create a real smart House, which will cost you tens of times cheaper than buying ready-made solutions in a store. The use of WiFi, of course, is not limited to this and there are so many examples of using this type of communication that there is no point in listing them, and if you have landed on this page, it means that you already need to use WiFi for some reason, you just need to figure out how to work with it correctly .

We will sort it out based on the cheapest and most popular WiFi module ESP8266-01. You can buy the ESP8266-01 WiFi module on our website.

One of the main advantages of such a module is the presence of memory and its own microcontroller on the board, which allows it to work independently by loading the sketch directly into the module itself.

There are actually quite a lot of modifications of the ESP8266 WiFi module and we will not list them here; once you learn how to work with one, you can easily start working with others. I would like to immediately note that working with WiFi may seem like a rather difficult task, and if you have few completed projects in your luggage, it is better to give up WiFi communication for now and use radio communications in your projects, working with which is much easier to understand. Entire communities and thematic forums are created for working with WiFi modules, which once again proves how difficult it is for most people to immediately understand this type of communication, and after re-reading all the information, most people simply give up. Most likely I won’t be able to do it all important information to fit within the framework of this article alone, and there is no point in this, otherwise it will turn out to be another confusion. I will try to follow the path of a strict sequence of the most important points, so that you can begin to understand the principle of operation of this type of communication and then simply develop your own skills in this direction.

So, let's get started and first look at the WiFi module pins ESP8266-01.

VCC- module power supply from 3V to 3.6V

GND- Earth.

RST- Reset output responsible for rebooting the module.

CH_PD- "chip power-down" when power is supplied to it, the module's operation is activated.

TX- data transfer (UART interface)

RX- data reception (UART interface)

GPIO0

GPIO2- general purpose I/O port

The GPIO0 and GPIO2 pins are exactly the same digital pins that we work with on Arduino boards to interface with various sensors, and they are used in the case of independent operation on the internal WiFi microcontroller of the ESP8266-01 module.

To reliably power the ESP8266-01 module, use an external stabilized 3.3V power supply and it is better not to try to take power from your Arduino board, since the module consumes current up to 215mA and this may end badly for your development board. Where to get a stabilized 3.3V power supply I hope is not a problem for you, otherwise it’s clearly too early for you to deal with this module. For example, I like to use this 3.3V and 5.0V YWRobot power module to quickly assemble circuits on breadboards, which allows you to quickly get a stabilized voltage of 3.3V or 5V on the corresponding power paths of the breadboard.

Connecting the plus (+) from our 3.3V power supply to pin VCC module ESP8266-01, and minus (-) bring the power supply to the output GND. In this state, the red LED on the module will turn on, signaling us that the power is connected correctly. In order for the module to be activated, it is also necessary to connect the plus (+) power supply with output CH_PD module ESP8266-01 and it is advisable to do this directly through a 10 kOhm resistor. Now, when we turn on the power, the red LED on the module should light up and the blue LED should blink quickly a couple of times. If this is what happens to you, then everything is fine, you have connected everything correctly and your module is working. Otherwise, check the connection again, or replace the module, as it is most likely not working.

Go ahead. To work with the ESP8266 WiFi module, we need a USB-UART adapter. There are different adapters, for example: FT232RL, CP2102, PL2303. But we will assume that you do not have such adapters, and we will use an Arduino board as a USB-UART adapter. I will use an Arduino NANO board for this, but you can use any other one at your disposal. The connection on any board is identical. We make the connection according to the following diagram.

Let's look at what we've done here. Please immediately note that we have connected the pins on the Arduino board with a jumper RST And GND. This manipulation disables the microcontroller and allows us to make a real USB-UART adapter out of our Arduino board.

Since we power the ESP8266-01 WiFi module from a separate external power supply, remember that we must always connect the ground of all power supplies in our projects. Therefore we connect the output GND Arduino boards with ground (-) our external 3.3V power supply designed to power the ESP8266-01 module.

Conclusion TX connect your Arduino board to the pin TX ESP8266-01 module. This line will transmit data from the WiFi module to the Arduino board. Anyone familiar with the UART interface may wonder: “But how can this be? Everywhere they taught that TX must connect to RX. TX transmits information, and RX receives.” And you will be right. That's right, TX is always connected to RX, but in the case when we make a UART adapter from Arduino, it is necessary to connect the devices directly. Consider this the exception to the rule.

Line RX We also connect your Arduino board directly to the line RX ESP8266-01 module. This line will transmit information from the Arduino board to WiFi card module. But we make this connection through a so-called voltage divider, consisting of two resistors with nominal values ​​of 1 kOhm and 2 kOhm. We need to reduce the voltage on this line using two resistors (voltage divider), since the Arduino board transmits a logical signal with a voltage of 5V, and the WiFi module operates with a voltage of 3.3V. To convert the logic signal, we could use a special logic level converter board, which would of course be more correct, but again, let’s assume that you don’t have one, and we had to take a simpler route and do it using a voltage divider.

We have now connected everything necessary for further work, but we still have 3 more pins not used ( GPIO0, GPIO2 And RST) on WiFi module ESP8266-01. For stable WiFi work module we need to pull these remaining unused terminals to positive (+) module power lines through 10 kOhm resistors.

This will save us from various interferences (interference) and make the module’s operation stable. It's better to do it right away. Otherwise, don’t be surprised that your module is constantly overloaded, produces incomprehensible information, or does not want to work at all. Using pull-up resistors on unused pins of a microcontroller should be a rule of thumb if you want stable operation in your projects.

And again we check the functionality of the ESP8266-01 WiFi module. Turn on the power and see that the red LED lights up and the blue LED blinks a couple of times. If everything happens like this, then great, let's move on. Otherwise, we check the correctness of the connections, as well as the quality of all contacts. It may just be a trivial situation when you double-checked everything ten times and made sure that everything was connected correctly, but when you turn on the module, you see that the blue LED does not behave adequately, is constantly on, constantly blinking, or does not respond to anything at all. This may be due to poor contact on some line. For example, when assembling a circuit on a breadboard, one of the resistors does not sit tightly in its place and this causes interference. Check the quality of connections. The module is very sensitive. Don't neglect this. This is a common reason for unstable operation.

In general, we are done with the connection. Now we need to prepare a program Arduino IDE for working with WiFi module ESP8266-01. To do this, we need to download and install in the Arduino IDE the necessary archive with libraries, examples and ESP boards, which will subsequently allow us to upload sketches directly to the microcontroller of the ESP8266-01 module, change the firmware, etc. For the purposes of this article, we most likely will not need these settings, but it seems to me that after we have figured out how to connect the module, the procedure will be correct if we immediately download everything necessary to work with the Arduino IDE. Everything here is simple in principle.

Launch the program Arduino IDE and go to the menu "File" - "Settings"

In the window that appears, in the top field we write “esp8266”. As a result, we will only have the required firmware in the window. When you click on the firmware, a button will appear "Installation". Click on the button "Installation" and wait until everything is installed. The archive is quite large, about 150 megabytes, so you'll have to wait.

After installation is complete. We reboot the Arduino IDE and see how new ESP boards have appeared in the “Tools” - “Boards” menu. That's all. WITH Arduino setup We're done with the IDE. We don’t need these settings for now, but in future work we won’t be able to do without them.

We have everything connected and prepared, now we can begin to understand the controls. In fact, now we will continue to check and configure the module using AT commands, and there is no way to do without it. WiFi modules are implemented in such a way that all communication with them occurs using so-called AT commands, which are hardwired into the module’s firmware. We will not list all AT commands here, there are quite a lot of them and if you want to study everything carefully, you can easily find them on the Internet. And now we will use only the most necessary to get started.

And so, we connect our Arduino board via USB cable to the computer. A external source food that nourishes WiFi module ESP8266-01 No need to turn it on yet. Let's launch Arduino program IDE, select our Arduino board from the “Tools” menu, in my case it is Arduino NANO, and you select yours. Also, do not forget to select the port to which our Arduino is connected. I hope you understand all this and know how to do it.

Open port monitoring "Tools" - "Port Monitor". Selecting the port speed 74880 (at this speed the module starts) and select “NL & CR” in the list on the left

Now we connect an external power source that powers our WiFi module. After which you should see approximately the following information in the port monitor.

Here we see some information on our WiFi module (speed, amount of memory on board, etc.). The information received may vary depending on the version WiFi firmware module. Let's not focus on this. Something else is important. Below we see a set of meaningless characters, this means that the port speed (74880 baud) that we set is only suitable for bootstrap module to see this information normally, but this speed is not suitable for normal communication with the WiFi module.

To select the correct port speed, we will simply change the port speed and send symbols to the port (the field at the top and the send button) AT until we get an answer OK. If you try to send characters right now AT to the port at a speed of 74880, you will receive another one or two meaningless characters in response.

Try immediately setting the speed to 115200 baud and sending the AT command. Most often, modules are flashed at this speed.

This is the picture you should see in your port monitor. If you still receive an incomprehensible set of characters in response, lower the speed and resend AT commands until the answer comes back OK. If you tried all the speeds and did not get the correct answer, then you are out of luck and the module is flashed with firmware at a non-standard speed. Then all that remains is to reflash the module with normal firmware, but this is a topic for a separate article.

I hope that everything is fine and you have selected the correct speed. By the way, if you try to turn off and turn on the WiFi module again after you have selected the correct speed, then instead of the same initial information that was correctly displayed at a speed of 74880 baud, you will, on the contrary, see a jumbled set of characters, but at the end you will see the word “ready” ". But we have the opportunity to view this initial information in normal form at the correct speed; to do this, we need to programmatically reboot the module using the AT command AT+RST.

To find out the firmware version of your ESP8266-01 WiFi module, you need to send a command to the port monitor AT+GMR and in response you will receive approximately the following information:

The ESP8266-01 WiFi module can operate in both access point and client modes. To allow the module to operate in all modes at once, send the command to the port monitor AT+CWMODE=3 and in response you should receive OK.

Team AT+CWLAP will allow you to see all WiFi access points that you see in this moment your module. My module, for example, currently sees only three WiFi access points in its coverage area. The answer should be something like this:

For example, we know the password for the third access point and to connect to it we execute the command AT+CWJAP="name","password", in my case this command looks like AT+CWJAP="dsl_unlim_512_home","11111111", to which we get a successful response:

The command parameters are written to the flash memory of the ESP8266-01 WiFi module, and if we turn off the module and turn it on again, it will automatically connect to this access point. Look, by chance, do not allow a space in the command, otherwise you will receive an answer ERROR. Please note that in the latest firmware versions it is recommended to use the command AT+CWJAP_CUR, that is, the command will look like AT+CWJAP_CUR="name","password". If suddenly we forgot which access point our module is connected to, we need to send a command AT+CWJAP? or AT+CWJAP_CUR? and in response we will receive the access point to which the WiFi module is currently connected.

With connection and initial setup WiFi module ESP8266-01 we figured it out. The module works and is ready for the implementation of your future projects. It is simply not possible to analyze all possible examples of working with this module within the framework of one article, and we will deal with this in the following articles. And for those who are not very familiar with programming, but really want to quickly start managing their projects using WiFi, I recommend introducing them to the RemoteXY WiFi project designer. This site will help you easily create a control interface for your mobile phone or tablet and use it to control your device to which you connect a WiFi module.

Moule esp-01
Scheme correct connection esp-01 module for programming and firmware.

The module is flashed by switching to programming mode; to do this, hold down the FLASH button, then without releasing it, briefly press the RESET button and release FLASH.
The module is switched to programming mode.
In the terminal at this moment you can see

ets Jan 8 2013,rst cause:2, boot mode:(1.6)
boot mode:(1,6) - reboot via RESET into programming mode
boot mode:(1,7) - power reboot into programming mode - which is not entirely correct.

For the firmware I will use the program NODEMCU FIRMWARE PROGRAMMER
(An archive with the program will be attached to the topic)
Unpack the archive and run in my case the 32-bit version of the program\Win32\Release\ESP8266Flasher.exe
We configure it for the module, in my case it is 1 Megabyte of flash memory or 8 Megabits.




The first step is to erase the memory with an empty 1 MB file.
This is an optional item. You can skip erasing and go to the firmware.
Those who have more or less memory need an empty file of the appropriate size.
Next, we determine what firmware is needed!
Can be used as ready firmware on NODEMCU and from the designer to assemble with the modules you need.
For example, one of the old proven NODEMCU

Constructor wifi-iot.com/
Constructor nodemcu-build.com/
or download the latest

Problems with firmware
If The esp8266 module is not flashing, check the pull-ups and the correct connection to GND GPIO0. And also whether RX TX are mixed up.
In the terminal you can check that boot mode:(1,6) or boot mode:(1,7) is displayed.

If after unsuccessful firmware the module does not work, try erasing the memory with an empty form file the size of your memory.

If The module does not work after successful firmware and sends endless garbage to the port (the data transmission LED may blink), this happens when flashing the latest Nodemcu builds, then you will additionally need to flash the file into the memory area, depending on the memory chip.
Information on memory was taken from the nodemcu website.
0x7c000 for 512 kB, modules such as ESP-01,03,07
0xfc000 for 1 MB, modules like ESP8285, PSF-A85 but also some varieties of esp-01,01s
0x1fc000 for 2 MB
0x3fc000 for 4 MB, module type ESP-12E, NodeMCU devkit 1.0, WeMos D1 mini etc.

If all else fails, write...

I will add the official group of the equipment manufacturer

Wi-Fi module ESP-01 is the most popular module of the ESP8266 series. Communication with a computer or microcontroller is carried out via UART using a set of AT commands. In addition, the module can be used as an independent device; to do this, you need to load your own firmware into it. You can program and download firmware through the Arduino IDE version above 1.6.5. To flash the module firmware you will need a UART-USB adapter. The ESP-01 module may be widely used in IoT (Internet of Things) devices.

Specificationsmodule

  • Wi-Fi 802.11 b/g/n
  • WiFi modes: client, access point
  • output power- 19.5 dB
  • Supply voltage - 1.8 -3.6 V
  • Current consumption - 220 mA
  • GPIO ports: 4
  • Clock frequency processor - 80 MHz
  • Code memory capacity
  • RAM- 96 KB
  • Dimensions - 13×21 mm

Connection

Let's consider the AT command mode. To do this, connect the module to the computer via a USB-UART adapter. Purpose of module pins (see Figure 1):
  • VCC - +3.3 V
  • GND - ground
  • RX, TX - UART pins
  • Output CH_PD - Chip enable
  • GPIO0, GPIO2 - digital contacts
The module requires external power supply 3.3 V.

Figure 1. ESP-01 module pin assignments

Connection diagram for communicating with the module in AT command mode (Figure 2):

Figure 2. Diagram of connecting the ESP-01 module to a computer via a serial port

Figure 3. Assembly circuit

To send AT commands in Mac OS X, you can use the CoolTerm program, in operating system Windows program Termite. You can only find out the speed of the COM port for connecting to the module experimentally; it can be different for different firmware. For my module the speed turned out to be 9600 baud. In addition, it was possible to establish exchange only after disconnecting and reconnecting the CH_PD pin to the power supply. After connecting, type AT in the terminal and should receive an OK response from the module. The AT+GMR command gives the module firmware version number, the AT+RST command reboots the module (see Fig. 4). A list of basic AT commands can be found in this document (ESP8266ATCommandsSet.pdf).

Figure 4. Sending AT commands to the module from Termite

If the AT command mode is not convenient for you, the board can be configured using the AppStack ESP8266 Config program, which can be downloaded from the link http://esp8266.ru/download/esp8266-utils/ESP8266_Config.zip. Appearance The program is presented in Figure 5. The module is configured using GUI, while the execution of commands can be seen in the program monitor (see Fig. 6). The monitor can also send AT commands from the command line.

Figure 5. AppStack ESP8266 Config program

Figure 6. Serial monitor of the AppStack ESP8266 Config program

There are two options for using this module:

  • in conjunction with a microcontroller (for example Arduino), which will control the module via UART;
  • writing your own firmware to use the ESP8266 as a standalone device.

Usage example

Let's look at an example of connecting a DHT11 humidity and temperature sensor to the ESP-01 module and sending data to cloud service ThingSpeak (https://thingspeak.com/). We will need the following parts:
  • module ESP-01
  • bread board
  • humidity and temperature sensor DHT11
  • resistor 10 kOhm
  • connecting wires
  • power supply 3 - 3.6V
First, let's connect the DS18B20 sensor to the ESP-01 module. DS18B20 is a digital temperature sensor operating via a single-wire 1-Wire interface. The connection diagram of the DS18B20 sensor to the module is shown in Fig. 7.

Figure 7. Connection diagram of the DHT11 sensor to the ESP-01 module.

Then you need to create a profile in the ThingSpeak service. The service has instructions for sending data to the service and receiving data from the service.

Figure 8. Complete circuit.

We will write the program in Arduino environment IDE for ESP8266. We will use the ESP8266WiFi.h (built-in) and OneWire.h libraries. Let's upload the sketch from Listing 1 to the Arduino board - receiving data from the temperature sensor and sending the data to the ThingSpeak service. You need to enter your data for the WiFi access point for the ESP-01 module:

  • const char *ssid;
  • const char *password;
as well as the privateKey parameter for your application in the ThingSpeak service. Listing 1 // website // Include the library to work with esp8266 #include // Include the DHT library to work with DHT11 #include // DATA pin connection pin #define DHTPIN 4 // DHT11 sensor #define DHTTYPE DHT11 // creating an instance of a DHT object DHT dht(DHTPIN, DHTTYPE); //ssid WiFi networks connections const char ssid = "********"; // WiFi password connection networks const char password = "******"; // ThingSpeak Server const char* host = "184.106.153.149"; // API KEY of your ThingSpeak application const char* privateKey = "****************"; // variables for storing temperature and humidity float temp; float humidity // variable for the measurement interval unsigned long millis_int1=0; void setup() ( // start the serial port Serial.begin(115200); delay(10); Serial.print("Connect to WiFi"); Serial.println(ssid); // Connect via WiFi WiFi.begin(ssid , password); while (WiFi.status() != WL_CONNECTED) ( delay(500); ) Serial.println("WiFi connected"); // start dht dht.begin(); ) void loop() ( // wait for an interval of 10 minutes if(milis()-millis_int1>=10*60000) ( Serial.print("connect to ThingSpeak"); Serial.println(host); // Use the WiFi client WiFiClient client; if (!client.connect (host, 80)) ( Serial.println("connection failed"); return; ) // get temperature data temp = get_data_temperature(); humidity = get_data_humidity(); // Create a URL with a request for the server String url = "/ update?key="; url += privateKey; url += "&temp="; url += temp; url += "&humidity="; url += humidity; // Send a request to the server client.print(String(" GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); delay(10); // ThingSpeak server response while(client.available())( String req = client.readStringUntil("\r"); Serial.print(req); ) ) ) Now in the ThingSpeak service we can view a graph of the readings of our DHT11 temperature sensor (Figure 9).

Figure 9. Graph of DS18B20 temperature sensor readings in the ThingSpeak service.

Frequently asked questions FAQ

1. The module does not respond toAT commands
  • Check that the module is connected correctly;
  • Check the correct connection of the Rx, Tx contacts to the UART-USB adapter;
  • Check the connection of the CH_PD pin to 3.3 V;
  • Experimentally select the communication speed on the serial port.
2. ESP-01 module does not receive temperature data from the sensorDHT11
  • Check that the DHT11 sensor is connected correctly to the module.
3. Data is not transferred to the ThingSpeak service
  • Check the module's connection to the WiFi access point;
  • Check the connection of the WiFi access point to the Internet;
  • Check that the request to the ThingSpeak service is correct.

... In general, this material is not limited to just one Arduino topic.

The topic of ESP8266 is quite a difficult one. But, if you work with these Wi-Fi modules in the Arduino IDE development environment, the entry threshold drops to a level acceptable for the average Arduino user. And not only the Arduino guy, but any person who has a desire to whip up something on the topic of IoT (Internet of Things), and without spending a lot of time reading the documentation for the chip and studying the API for these modules.

This video completely duplicates the material presented in the article below.

Well, we already know how to connect the ESP8266 and put it into programming mode, now let's move on to something more useful.

I’ll say right away that once we program the module in the Arduino development environment, we destroy the native firmware, and we will no longer be able to work with the module using AT commands. Personally, this doesn’t make me cold/hot, but if someone needs it, towards the end of the article I’ll show you how to flash the native firmware back into the module, or some kind of bootloader like NodeMcu.

To begin with, download from the official website latest version Arduino IDE, currently 1.6.7. Older versions like 1.0.5. won’t fit because they simply don’t have the necessary functionality, and dancing with a tambourine doesn’t interest us, right?

We launch the development environment and immediately go to File/Settings:

Http://arduino.esp8266.com/stable/package_esp8266com_index.json

Then go to Tools/Board:/Board Manager...:

A board manager window will appear in front of us, scroll through it to the very bottom, and if everything is done correctly we will see something like this:

Click the cursor on the inscription " esp8266 by ESP8266 Community"after that, we have an “Install” button, select the desired version, I take the latest one, today it is 2.1.0 and install it. The development environment will download the files it needs (about 150 megabytes) and opposite the inscription " esp8266 by ESP8266 Community""INSTALLED" will appear, that is, installed:

We scroll down the list of boards and see that we have many different ESPs in the list, take “Generic ESP8266 Module”:

Go to “Tools” and select the desired COM port (for me it’s COM32) Arduino or USB UART converter, then set Upload Speed: “115200”:

We set the speed to 74880 and “NL & CR” and again turn off and apply power and it will respond with some debugging information:

Note that 74880 is not the main speed of the ESP8266, it just sends debugging information at it. If the module does not send anything to the console, then something may be connected incorrectly.

By default, the speed should be 115200, but in some cases it can be 9600 and others... So try to find it.

After selecting the required speed, we send the “AT” module and it should respond that everything is “OK”. The "AT+GMR" command displays information about the firmware.

Before you start flashing the ESP8266 in the Arduino IDE, I advise you to read the article to the end.

Now let's try to flash the ESP8266 via Arduino IDE. We put the module into programming mode (I wrote how to do this in a previous article).

Let's add a standard LED to the flasher:

// By Mr. PodelkinTs youtube.com/RazniePodelki // special to geektimes.ru/post/271754/ #define TXD 1 // GPIO1/TXD01 void setup() ( pinMode(TXD, OUTPUT); ) void loop() ( digitalWrite( TXD, HIGH); delay(1000); digitalWrite(TXD, LOW); delay(1000); )

Flashed? So everything was done correctly. Where did I get that the LED is connected to the first pin? In the previous article there is a picture with pinouts of different modules, and there is a marking of the ports when using the Arduino bootloader (pins are marked in pink).

Blinking an LED is of course good, but we need to install some kind of web server or start controlling the LED at least using buttons in the browser, right? But I’ll tell you about this some other time.

And now how to flash back native firmware, and how to even flash a module with third-party bootloaders. For ESP8266 there is such a program as NodeMCU Flasher, which is originally intended for flashing the NodeMCU boot loader. But as it turned out, it perfectly flashes other firmware.

I will attach an archive with this program and firmware to the article for convenience, but you can always download new version NodeMCU Flasher.

In the “nodemcu-flasher-master” folder there are 2 folders Win64 and Win32 and depending on the bit depth of your OS, select the one you need. Next, in the Release folder, run “ESP8266Flasher.exe” and see the program interface:

Select the desired COM port and go to the “Config” tab, remove the cross next to “INTERNAL://NODEMCU” and put it one point lower, as in the screenshot:

(If you want to flash the NodeMCU bootloader, remove the cross where it was not, and put it where it was, that is, near “INTERNAL://NODEMCU”).

Then we click on the gear and select where our firmware is located, the firmware is usually in *.bin format (in the attached archive it is “v0.9.5.2 AT Firmware.bin” which is in the main folder), and also select “0x00000” as and higher.

We return again to the “Operation” tab, put the module into programming mode and click “Flash”:

That’s it, the module has started to be flashed, after flashing, don’t forget to reboot the module and voila, it’s flashed with the firmware we need.

We check with the AT command “AT+GMR” whether we did everything correctly:

As you can see, everything went smoothly.

How to use ESP-01 module to control LED via Internet, a module that allows you to control any electrical device.

In this ESP8266 tutorial, we use the ESP-01 module to control an LED over the Internet. The ESP8266 is a cheap but effective platform for communicating over the Internet.

It is also easy to use with Arduino. After completing this lesson, you will gain the basic knowledge of controlling any electrical device via the Internet from anywhere in the world!

Here we will use a USB-to-TTL converter to program the ESP8266 ESP-01. And we will use to develop a web server for remote control LED.

How it works

The ESP8266 can be controlled from a local Wi-Fi network or from the Internet (after port forwarding). The ESP-01 module has GPIO pins that can be programmed to turn an LED or relay on or off via the Internet. The module can be programmed using an Arduino USB-to-TTL converter via serial pins (RX, TX).

Connecting Hardware to Your ESP8266

We can use a USB-to-TTL converter or use Arduino to program the ESP8266. Here are three methods you can follow to load code into your ESP8266 - choose the one that suits you best. Refer to the diagrams for each option and configure your equipment accordingly.

1. USB-to-TTL converter using DTR connector

If you use a USB-to-TTL converter with DTR output, the download will go smoothly. Please keep in mind that the serial monitor will not work when doing this.

USB TTL → ESP8266 ESP-01
GND → GND
TX → RX
RX → TX
RTS → RST
DTR → GPIO0

2. USB to TTL converter without DTR output

To connect a USB to TTL converter without DTR pin, we must use manual transmission. For this we use two buttons - see the following diagram:

USB TTL → ESP8266 ESP-01
GND → GND
TX → RX
RX → TX
Reset Button → RST
Flash Button → GPIO0

When downloading the code, click the "Downloads" (Flash) button. Keep the button pressed while you press the Reset button once. You can now release the Flash button. The ESP8266 is now in a mode where you can upload a sketch.

3. Using Arduino Uno to Upload Code to ESP8266

You can use ESP8266 ESP-01 to run the code. When downloading the code, follow the same procedure as in the second point - keep the "Download" button pressed while you press reset once, and then release the Flash button.

ARDUINO → ESP8266 ESP-01
GND → GND
TX → TX
RX → RX
Reset button → RST
Flash button → GPIO0

ESP8266 code download

Use any of the above methods and open , then select the ESP8266 board from the menu:

Tools → Board → Generic ESP8266 Module
(Tools → Board → ESP8266 Module)

Note. If you have not installed and configured the ESP8266 Arduino board, please do so by following the steps above this tutorial. Then you can move on.

Now copy the below code into Arduino IDE and click on the download button. Change SSID to dot Wi-Fi access and change the password to yours Wi-Fi password and compile.

#include const char* ssid = "YOUR_SSID";//type your ssid const char* password = "YOUR_PASSWORD";//type your password int ledPin = 2; // GPIO2 of ESP8266 WiFiServer server(80);//Service Port void setup() ( Serial.begin(115200); delay(10); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); // Connect to WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED ) ( delay(500); 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) ( return; ) // Wait until the client sends some data Serial .println("new client"); while(!client.available())( delay(1); ) // Read the first line of the request String request = client.readStringUntil("\r"); Serial.println (request); client.flush(); // Match the request int value = LOW; if (request.indexOf("/LED=ON") != -1) ( digitalWrite(ledPin, HIGH); value = HIGH; ) if (request.indexOf("/LED=OFF") != -1)( digitalWrite(ledPin, LOW); value = LOW; ) //Set ledPin according to the request //digitalWrite(ledPin, value); // Return the response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); // do not forget this one client.println(""); client.println(" "); client.print("Led pin is now: "); if(value == HIGH) ( client.print("On"); ) else ( client.print("Off"); ) client.println( "

"); client.println("Click here turn the LED on pin 2 ON
"); client.println("Click here turn the LED on pin 2 OFF
"); client.println(""); delay(1); Serial.println("Client disconnected"); Serial.println(""); )

Open your serial monitor and open the URL shown on your serial monitor through your web browser. Connect GPIO 2 from the ESP8266 to the longer LED pin. Now you can control your LED remotely via the Internet!

Remove any wires that were needed to download the code. The LM1117 module is used to provide a regulated 3.3V output. This will allow you to make the ESP8266 or ESP-01 module standalone.

Connecting the ESP8266 to the Internet

Currently the ESP8266 module is only available through local network Wi-Fi. To manage devices from the Internet, you need to perform port forwarding on your router.

To do this, find your system's IP address either using the "ifconfig" command in your terminal or go to whatsmyip.org. Copy your IP address. Now open your router setting and go to 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

The IP address is the one you specified earlier. Leave the rest of the settings as default. Now go to your browser and enter the address: xxx.xxx.xx.xx:80. A page should open to control the LED.