Welcome to the exciting world of programming ESP8266 with Arduino core for ESP8266. This chapter introduces ESP8266 and a simple LED blink program using the Arduino core for the ESP8266 library.
In this chapter, you will learn the following topics:
- The basics of ESP8266 and the module family
- The original ESP8266 ESP-01
- Applying regulated power to ESP-01
- Connecting ESP-01 with computer through a USB to TTL serial console cable
- Preparing the development environment by installing the Arduino core for the ESP8266 library
- Writing a simple LED blink program using the Arduino core for ESP8266
- Using AT commands
- The overview of some robotics hardware and accessories
The ESP8266EX (Figure 1.1) is a single-chip microcontroller developed by Espressif (https://espressif.com/). It can be used to develop low-power, highly-integrated Wi-Fi solutions especially for mobile devices, wearable electronics, and the Internet of Things (IoT) applications. The main advantage of ESP8266EX is that it can give any microcontroller access to a Wi-Fi network. As an example, it can offload all Wi-Fi networking functions for Arduino just like the Arduino Wi-Fi shield:

Figure 1.1: ESP8266EX chip
The chip has the following great features:
- Small size (5 mm x 5 mm)
- Requires minimal external circuitry
- Wide temperature range (-40°C to + 125°C)
- All-in-one small package -SoC (integrates a 32-bit Tensilica MCU, standard digital peripheral interfaces, antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules)
- Low power consumption
ESP-01 is a small Wi-Fi module based on Espressif ESP8266EX that can give any microcontroller access to a Wi-Fi network. The ESP-01 module (Figure 1.2) is the basic and the most popular board of the ESP8266 module family. You should have an ESP8266 ESP-01 module to understand the basics of ESP8266 and build robotics projects.
This is a list of vendors that typically stock the ESP-01 modules:
- SparkFun Electronics: https://www.sparkfun.com/products/13678
- Adafruit Industries: https://www.adafruit.com/product/2282
- Electrodragon: http://www.electrodragon.com/product/esp8266-wi07c-wifi-module/

Figure 1.2: The original ESP8266 ESP-01. Image courtesy of SparkFun Electronics (https://www.sparkfun.com)
The original ESP8266 ESP-01 has the following features:
- Offloads all Wi-Fi networking functions from another application's processor
- Self-hosting of applications
- Only four pins interface, VCC-3V3, GND, TX, and RX
- 1 MB (8 MB) flash memory
- Pre-programmed AT command set firmware
- Supports APSD for VoIP applications and Bluetooth co-existence interfaces
Here is a list of all the ESP8266 boards of the ESP8266 module family at the time of writing:
- ESP-01
- ESP-02
- ESP-03
- ESP-04
- ESP-05
- ESP-06
- ESP-07
- ESP-08
- ESP-09
- ESP-10
- ESP-11
- ESP-12
- ESP-12F
- ESP-12-E/Q
- ESP-12S
- ESP-13
- ESP-14
The top of the ESP-01 board consist of the following things:
- An ESP8266EX chip—Offloading all Wi-Fi networking functions
- A Berg Micro BG25Q80A 1518 flash chip—Serial Peripheral Interface (SPI) flash memory
- A printed Wi-Fi antenna—Transmitting and receiving Wi-Fi signals

Figure 1.3: ESP-01 top view
The original ESP8266 ESP-01 board has eight pins and comes without headers. You can solder regular wires with pins, but if you want to use it with a breadboard, you should attach headers:

Figure 1.4: ESP-01 pinout
- GPIO0: Connects to pin 3 of the ESP8266
- GPIO2: Connects to pin 5 of the ESP8266
- TX: This is the transmitting line that connects to RX of another device
- RX: This is the receiving line that connects to TX of another device
- 3V: This accepts regulated 3.3V DC from a regulator to power the board
- GND: The ground pin
- CH_PD: Chip select
- RST: The reset pin
You can use one of the following things to connect ESP8266 with a breadboard:
- Using female/male extension jumper wires (https://www.adafruit.com/product/1954)
- Using a 10-pin IDC breakout helper (https://www.adafruit.com/product/2102)
The ESP8266 works only with regulated 3.3V. You can build a simple regulated power supply with an LD1117-3.3 linear voltage regulator. It can provide 3.3V at 800 mA. You can purchase a TO-220 package of the LD1117-3.3 for use with a breadboard. Figure 1.5 shows the circuit diagram for 3.3V output. You can supply 4-15V DC to Vin using one of the following sources:
- 7V LiPo battery
- 5V power bank
- 9V battery
- 5V "wall wart" power supply

Figure 1.5: 3.3V regulated power supply circuit diagram
Now, you can connect the power supply to ESP-01:
- Connect Vout to the Vcc pin of ESP-01.
- Connect GND to the GND pin of ESP-01.
ESP8266 ESP-01 doesn't have a built-in USB to serial conversion chip to directly connect to your computer through a USB cable for flashing programs. As a solution, you can use a USB to TTL serial console cable to connect ESP8266 to a computer. Figure 1.6 shows a USB TTL serial console cable from Adafruit (https://www.adafruit.com/product/954):

Figure 1.6: A USB to TTL serial console cable. Image courtesy of Adafruit Industries (https://www.adafruit.com)
The type A USB plug includes a USB to serial conversion chip and provides four wires to connect to your ESP8266ESP-01 board. Table 1.1 shows the functions of the four wires:
Color | Function |
Red | Power |
Black | Ground |
White | RX |
Green | TX |
Table 1.1: Color codes and functions of wires
You can use the following steps to connect the USB to TTL serial cable with your ESP8266:
- Connect the white RX wire of the cable to the TX pin of ESP8266
- Connect the green TX wire of the cable to the RX pin of ESP8266
- Connect the black ground wire of the cable to the GND pin of ESP8266
- Connect the CH_PD pin of ESP8266 to the Vcc wire of the power supply
The following steps will guide you how to use a serial terminal program to communicate and execute AT commands with ESP-01. In this example, you will use PuTTY, SSH, and a Telnet client for Windows to run AT commands through a serial port:
- First, download the latest PuTTY MSI installer or binary from the following sources:
- MSI (Windows installer):
- 32-bit:
putty-0.70-installer.msi
(https://the.earth.li/~sgtatham/putty/latest/w32/putty-0.70-installer.msi) - 64-bit:
putty-64bit-0.70-installer.msi
(https://the.earth.li/~sgtatham/putty/latest/w64/putty-64bit-0.70-installer.msi)
- 32-bit:
- Binary:
- 32-bit:
putty.exe
(https://the.earth.li/~sgtatham/putty/latest/w32/putty.exe) - 64-bit:
putty.exe
(https://the.earth.li/~sgtatham/putty/latest/w64/putty.exe)
- 32-bit:
- MSI (Windows installer):
- Open the
PuTTY Configuration
window by double clicking onputty.exe
or the putty shortcut. - In the
Serial line
text box, type the COM port that is assigned to your ESP8266 board (Figure 1.7). - In the
Speed
text box, type115200
as the baud rate.
- Click on the
Open
button to make a serial connection:

Figure 1.7: The PuTTY configuration window
- If you have provided the correct settings, the serial connection will establish between ESP8266 and your computer.
- You can use the serial terminal window to issue AT commands for ESP8266 from your computer.
Table 1.2 shows the complete set of AT commands that you can use with ESP8266:
AT command | Manual |
| Attention. |
| Resetting the unit. |
| Retrieving the firmware version ID. |
| Setting operation mode:
The access point functionality does not have a DHCP function and has only minimum functionalities. However, it will assign an IP address to the client and there is no way to do a manual IP, manual DNS, and other advanced IP functionalities. This unit only provides minimal functionalities. |
| Joining a network or just an access point. |
| Retrieving the list of the visible network. |
| Disconnecting from the current network connection. |
| Setting up access point SSID, password, RF channel, and security scheme. The following is the security scheme:
|
| Retrieving a list of assigned IP addresses. |
| Retrieving the current connection as socket client or socket server. |
| Connecting to socket server (TCP or UDP). |
| Sending by connection channel and by specific length. |
| Closing the socket connection. |
| Retrieving the assigned IP address when the unit is connecting to a network. |
| Setting a single connection ( |
| Starting at the specified port or stopping the server. The default port is
|
| Setting transparent mode (data from the socket client will be sent to the serial port as is) or connection channel specific mode ( Data sent from the socket client will be broken into multiple unsolicited (
|
| Setting the automatic socket client disconnection timeout from |
Packetized data from the unit | Unsolicited data packet ( |
Table 1.2: The ESP8266 AT command set (Source: SparkFun Electronics)
Every AT command starts with the letters AT
. Here's an example:
AT+GMR <CR>
Type the AT command AT+GMR
and press the Enter key. Don't type <CR>
. The CR indicates carriage return.
This will return the firmware version ID of the ESP8266 module, as shown in Figure 1.8:

Figure 1.8: Terminal output for the AT+GMR command
Likewise, you can run any AT command with the PuTTY terminal to execute on ESP8266 through the serial connection.
The Arduino IDE provides an easy way to write sketches for Arduino and other development boards. You can use ESP8266 with the Arduino IDE. First, install the ESP8266 board package on Arduino IDE.
The ESP8266 also supports the following development environments:
- Use a simple Notepad/GCC setup
- Fine-tune an Eclipse environment
- Use a virtual machine provided by Espressif
The Arduino core for ESP8266 includes a set of libraries to do the following things with your ESP8266 Wi-Fi module:
- Communicate over Wi-Fi using TCP and UDP protocols
- Set up HTTP, mDNS, SSDP, and DNS servers
- Perform OTA updates
- Use a filesystem in flash memory
- Work with SD cards, servos, SPI, and I2C peripherals
It also allows you to write sketches for ESP8266 with the core Arduino functions and libraries. You can run the sketches directly on ESP8266 without using an external microcontroller board:
- Open the Arduino IDE and on the menu bar select
File
|Preferences
.
- Type the URL
http://arduino.esp8266.com/stable/package_esp8266com_index.json
for the ESP8266 board manager package for Arduino in theAdditional Boards Manager URLs
text box and click onOK
to close the dialog box (Figure 1.9):

Figure 1.9: The Arduino IDE preferences
- Open the
Boards Manager
by selectingTools
|Board
|Boards Manager
. You should see a new entry in the list titledesp8266 by ESP8266 Community
(Figure 1.10):

Figure 1.10: The Arduino IDE Boards Manager
- At the time of this writing, the Arduino core for ESP8266 Wi-Fi chip supports the following boards:
- Generic ESP8266 Module
- Olimex MOD-WIFI-ESP8266(-DEV)
- NodeMCU 0.9 (ESP-12 Module)
- NodeMCU 1.0 (ESP-12E Module)
- Adafruit HUZZAH ESP8266 (ESP-12)
- ESPresso Lite 1.0
- ESPresso Lite 2.0
- Phoenix 1.0
- Phoenix 2.0
- SparkFun Thing
- SweetPea ESP-210
- WeMos D1
- WeMos D1 mini
- ESPino (ESP-12 Module)
- ESPino (WROOM-02 Module)
- WifInfo
- ESPDuino
- Click on the
Install
button to install it on your Arduino IDE. This will take a few minutes to install, depending on your internet speed. - Click on
Close
to close theBoards Manager
dialog box. - Select
Tools
|Board: "Generic ESP8266 Module"
|Generic ESP8266
for board type. - The upload speed should be 115200; however, you can increase it to a higher value by clicking on
Tools | Upload Speed
and selecting a value greater than 115200.
Now, you will write your first program (sketch) for ESP8266 with the Arduino IDE to blink a LED connected to PIN 2 of ESP8266.
You'll need the following things to build the circuit:
- One LED (any color)
- One 1 kilo ohm resistor
- 3V regulated power supply
Connect the components together, as shown in Figure 1.11:

Figure 1.11: The LED blink circuit hook up
Using your Arduino IDE, type the code as shown in the Listing 1-1:
#define ESP8266_LED 2void setup() { pinMode(ESP8266_LED, OUTPUT);}void loop() { digitalWrite(ESP8266_LED, HIGH);delay(500);digitalWrite(ESP8266_LED, LOW);delay(500);}
Then, verify the sketch by clicking on the Verify
button. Finally, upload the program by clicking on the Upload
button. This will take a few seconds to complete. After completing the flashing, the LED will start to blink.
Chassis kits provide everything to build robots with most microcontroller boards. You'll use the following chassis kits to build projects.
The 3-Layer Mini Round Robot chassis Kit (Figure 1.12) includes the following things you need to build the shell of a two-wheel drive mobile platform robot:
- Two drive motors
- Two wheels
- One plastic caster ball
- Anodized aluminum frames and all mounting hardware for assembly
You can purchase a kit from Adafruit Industries (https://www.adafruit.com/product/3244) to work with projects that will be discussed in Chapter 2, Building a Mini Round Robot with Original ESP8266, Chapter 3, Using Encoders, and Chapter 4, Building a Mini Round Robot with the Feather HUZZAH ESP8266:

Figure 1.12: A Mini Round Robot Chassis Kit. Image courtesy of Adafruit Industries (https://www.adafruit.com)
The Zumo chassis kit (Figure 1.13) allows you to build tracked robots that run on continuous tracks instead of wheels. Tracked vehicles can be used for:
- Construction vehicles
- Military armored vehicles
- Unmanned ground vehicles
The Zumo chassis kit includes the following things:
- Zumo chassis main body
- 1/16" black acrylic mounting plate
- Two drive sprockets
- Two idler sprockets
- Two 22-tooth silicone tracks
- Two shoulder bolts with washers and M3 nuts
- Four 1/4" #2-56 screws and nuts
- Battery terminals
You can purchase a kit from Pololu (https://www.pololu.com/product/1418) to work with the project that will be discussed in Chapter 5, Line-Following Zumo Robot:

Figure 1.13: A Zumo chassis kit. Image courtesy of Pololu (https://www.pololu.com)
The Romi chassis kit (Figure 1.14) includes the following things you need to build a two-wheel drive robot:
- One black Romi chassis base plate
- Two mini plastic gearmotors (120:1 HP with offset output and extended motor shaft)
- A pair of black Romi chassis motor clips
- A pair of white 70 × 8 mm Pololu Wheels
- One black Romi chassis ball caster kit
- One Romi chassis battery contact set
You can purchase a kit from Pololu (https://www.pololu.com/category/202/romi-chassis-and-accessories) to build the project that will be discussed in Chapter 6, Building an ESP8266 Robot Controller:

Figure 1.14: A Romi chassis kit - Black. Image courtesy of Pololu (https://www.pololu.com)
The mini robot rover chassis kit (Figure 1.15) includes the following things needed to build the shell of a two-wheel drive robot:
- Two wheels
- Two DC motors in MicroServo shape
- One support wheel
- One metal chassis
- One top metal plate with mounting hardware

Figure 1.15: A mini robot rover chassis kit. Image courtesy of Adafruit Industries (https://www.adafruit.com)
You can purchase a kit from Adafruit industries (https://www.adafruit.com/product/2939) to build the project that will be discussed in Chapter 7, Building a Gripper Robot.
The Rover 5 robot platform (Figure 1.16) allows you to build a four-wheel drive tracked robot. The kit includes the following things:
- Adjustable gearbox angles
- 4 independent DC motors
- 4 independent Hall-effect encoders
- Thick rubber tank treads
- 6 x AA battery holder
- 10 Kg/cm stall torque per motor

Figure 1.16: A Rover 5 robot platform. Image courtesy of Pololu (https://www.pololu.com)
You can purchase a kit from Pololu (https://www.pololu.com/product/1551) to build a project that will be discussed in Chapter 8, Photo Rover Robot.
The wheel encoder kit (Figure 1.17) allows you to measure the speed or distance that the chassis travels. You'll learn how to connect the wheel encoder kit to any wheeled robot in Chapter 3, Using Encoders:

Figure 1.17: A wheel encoder kit. Image courtesy of SparkFun Electronics (https://www.sparkfun.com)
A gripper can be connected to a robot to allow grip objects. Figure 1.18 shows a Parallel Gripper Kit assembled. You will need any standard size Hitec or Futaba servo to integrate with the gripper kit. You can purchase one from SparkFun Electronics (https://www.sparkfun.com/products/13178):

Figure 1.18: Parallel Gripper Kit A - Channel mount
In this chapter, you learned the basics of the ESP8266 microcontroller and the modules based on it. Then, you learned how to run AT commands on ESP8266 and used the Arduino core for ESP8266 to write sketches. Finally, you gained knowledge on various robot chassis kits and accessories that can be used to build robots.
Chapter 2, Building a Mini Round Robot with Original ESP8266, offers the fundamentals of robotic vehicles by building a mini round robot with ESP-01.