IOT Reference: Internet of Things Technology
IOT Reference: Internet of Things Technology
Cocoy Pusung
Table of Contents
All About ESP8266 .......................................................................................... 1
Description .....................................................................................................2
Usage ..................................................................................................................4
Features ..............................................................................................................4
The ESP8266 Internet of Things Wifi Chip .................................................... 5
Powering the ESP8266 .................................................................................... 8
Connecting to the ESP8266 with an Arduino ................................................9
Pin Connections .............................................................................................9
Open a COM Terminal ...................................................................................9
Connecting to the ESP8266 without an Arduino .........................................11
Pin Connections ...........................................................................................11
Open a COM Terminal .................................................................................11
Connecting to a Network ............................................................................. 12
AT Commands .............................................................................................13
For Arduino IDE Users .................................................................................13
For PuTTY Users .........................................................................................14
Setting the ESP8266’s WiFi Mode ...............................................................14
List the Wifi Networks in Range ......................................................................... 15
Connecting to a Wireless Network ...............................................................16
List of AT Commands ......................................................................................... 18
What is this ESP8266 ......................................................................................... 18
Features ............................................................................................................ 19
What is this ESP8266 AT .................................................................................... 19
Flashing Custom Firmware ........................................................................... 20
Released Firmwares ....................................................................................20
Ai-thinker .......................................................................................................... 20
NodeMCU .......................................................................................................... 21
Official Espressif ................................................................................................ 21
MicroPython...................................................................................................... 21
ESP8266 Basic.................................................................................................... 22
Arduino IDE ....................................................................................................... 22
Flashing! .......................................................................................................22
Flashing Ai-thinker Firmware ............................................................................. 23
Flashing NodeMCU ............................................................................................ 24
Flashing the Official Espressif Firmware ............................................................ 26
Flashing MicroPython ........................................................................................ 26
Flashing ESP8266 BASIC ..................................................................................... 26
Flashing With the Arduino IDE ........................................................................... 27
Flash AT commands firmware in ESP8266 ESP-01 device .................................. 29
How to put ESP-01 module into flashing mode: ................................................ 30
How to flash firmware .................................................................................. 31
Flash tool for Windows: ..................................................................................... 31
Flash address ...............................................................................................31
ESP-01 - Upgrading the on-board flash from 512KB to 4MB ................... 33
ESP8266 module comparison ....................................................................... 36
Comparison of Raw Modules .......................................................................36
Comparison of Development Modules .........................................................37
ESP-01 ............................................................................................................... 37
ESP-05 ............................................................................................................... 38
ESP-12 ............................................................................................................... 38
ESP-201 ............................................................................................................. 39
Test Board ......................................................................................................... 39
NodeMCU module V0.9 (Outdated) .................................................................. 40
Summary ........................................................................................................... 42
Raw Modules................................................................................................43
Development Modules (with Serial Converter) ............................................43
Applications/ Development Kits ...................................................................44
Wemos D1 R32 ESP32 Boards ...................................................................... 46
ESPDUINO-32 board specifications: ................................................................... 46
How to Get Started with the ESP32 ............................................................. 48
Assemble the Toolchain..................................................................................... 48
Environment Variables, Part I ............................................................................ 49
Coding, Flashing, Hello World!........................................................................... 49
Environment Variables, Part II ........................................................................... 49
Menuconfig ....................................................................................................... 50
Flashing the Chip ............................................................................................... 51
Installing the ESP32 Board in Arduino IDE ................................................. 52
Installing the ESP32 Add-on on Arduino IDE ..............................................52
Installing the ESP32 Board ................................................................................. 52
Deleting the espressif folder .............................................................................. 54
Testing the Installation ...................................................................................... 55
Wrapping Up ................................................................................................57
Getting Started with the ESP32 Development Board ................................ 58
ESP32 DEVKIT DOIT............................................................................................ 58
Where to Buy?..............................................................................................59
Specifications ...............................................................................................59
Programming Environments.........................................................................59
Preparing the ESP32 Board in Arduino IDE ........................................................ 60
ESP32 Pinout ..................................................................................................... 60
Upload Code to the ESP32 using Arduino IDE .................................................... 61
Demonstration ..............................................................................................63
Wrapping up .................................................................................................64
ESP32 vs ESP8266 – Pros and Cons .............................................................. 64
Specifications: ESP32 vs ESP8266 .............................................................64
More GPIOs on the ESP32 ................................................................................. 66
Arduino IDE – ESP32 vs ESP8266 ....................................................................... 66
Wrapping Up ................................................................................................66
ESP32 Pinout Reference:............................................................................... 67
ESP32 Peripherals .............................................................................................. 68
Input only pins ................................................................................................... 69
SPI flash integrated on the ESP-WROOM-32...................................................... 70
Capacitive touch GPIOs...................................................................................... 70
Analog to Digital Converter (ADC) ..................................................................... 70
Digital to Analog Converter (DAC) ..................................................................... 71
RTC GPIOs.......................................................................................................... 72
PWM ................................................................................................................. 72
I2C ..................................................................................................................... 73
SPI ..................................................................................................................... 73
Interrupts .......................................................................................................... 73
Enable (EN) ........................................................................................................ 73
GPIO current drawn........................................................................................... 73
Wrapping Up ................................................................................................73
ESP32 Development Boards Review and Comparison ............................... 74
ESP32 Development Boards Comparison ...................................................75
ESP32 Features and Specifications ............................................................76
How to Select an ESP32 Development Board .............................................76
ESP32 DEVKIT DOIT............................................................................................ 77
Adafruit ESP32 Feather...................................................................................... 77
Sparkfun ESP32 Thing ........................................................................................ 77
ESP32 with Battery Holder................................................................................. 78
ESP32 with OLED ............................................................................................... 78
ESP32 SX1278 (LoRa) ......................................................................................... 78
Wrapping Up ................................................................................................78
ESP32 Web Server – Arduino IDE................................................................. 79
Project Overview ..........................................................................................79
Installing the ESP32 board in Arduino IDE ..................................................80
Schematic .......................................................................................................... 80
ESP32 Web Server Code .................................................................................... 80
Setting Your Network Credentials...................................................................... 83
Uploading the Code ........................................................................................... 84
Finding the ESP IP Address ................................................................................ 85
Accessing the Web Server ................................................................................. 85
Testing the Web Server ..................................................................................... 86
How the Code Works ......................................................................................... 86
setup() ............................................................................................................... 87
loop() ................................................................................................................. 88
Displaying the HTML web page.......................................................................... 90
Styling the Web Page ......................................................................................... 91
Setting the Web Page First Heading .................................................................. 91
Displaying the Buttons and Corresponding State ............................................... 91
Closing the Connection ...................................................................................... 92
Wrapping Up ................................................................................................92
All About ESP8266
As you may have heard, the ESP8266 Serial-to-WiFi chip created by Espressif has seen a
wide adoption as a cost-effective solution for IoT and WiFi-capable devices. This tiny-sized
System On a Chip (SoC) includes an 80 MHz microcontroller with a full WiFi front-end (both
as client and access point) as well as a full TCP/IP stack with DNS.
Because the ESP8266 comes only in a tiny surface-mount package (QFN-32), a few different
vendors have developed a series of modules named ESP-NN where NN are numbers ranging
from 01 to 13. The ESP8266 ESP-01 in this product listing is the 'OG' of this series of
modules, and provides a nice little breakout for some of the pins of the ESP8266 IC.
Different than rest of the ESP-NN modules, the ESP-01 comes with a 2x04 male pin header
(0.1in-pitch) to provide a quick and easy way to wire it to a 3.3V microcontroller or single-
board computer. All in all, this tiny board provides a convenient and inexpensive way to use
and program an ESP8266 IC!
Page | 1
Description
Hackers were pretty excited when this chipset first came out
from Espressif, as it had a great feature set for very little money,
and much effort has been put into supporting it, including
plug-ins for the Arduino development system. Now, the
ESP8266 is a well respected module useable on any hacker's
bench. You can flash it to fill different rolls, with the default
acting much like an old style AT-command set modem, and
another mode that let's it load and run Arduino code. Set it up
as a micro webserver/access point. Pretty impressive!
Although there are 14+ versions of the AI-Thinker series of wifi microcontrollers featuring
the ESP8266, the ESP-01 holds the distinction of being prized for it's great combination of
size, price, and functionality. The caveat to using such an inexpensive module is that there
are some limitiations to be aware of, like the weird 2x8 row of headers that make it
breadboard-unfriendly, the lack of any voltage regulation, and the inability to talk 5V I/O.
So what can you load onto it? There's a few versions of firmware that you can load onto
them, like:
Features:
• 2 GPIO (0 and 2)
• wifi b/g/n support
Page | 2
Specifications:
• 8Mbit external QSPI flash memory (1MByte)
• 32-bit Tensilica Xtensa LX106 CPU running 80MHz
• 3.3V supply (current can spike 300mA+, depending on mode)
• PCB-trace antenna
• 2 x 4 dual-in-line pinout
• 14.3 x 24.8mm
Programming:
There's so many ways to bend this SoC (System on a Chip), but the basics are:
• To program, you have to toggle the GPIO 0 "PRGM" pin to ground after a low signal
to the "RSET" pin, so both have to have their own momentary button connected to
ground.
• Hook it up to a FTDI (or similar UART as shown in the product images), making sure
it's configured for 3.3V.
• Program it through the Arduino IDE. After you click the "Program" button in
Arduino, it will start compiling your program. At this time:
o press and HOLD your "PRGM" button,
o tap the "RSET" button
o then RELEASE the "program" button when the Arduino IDE finishes the
compile, and start "programming..."
o Manually wiring it up can be a PAIN. Look into the very-convenient 29248
adapter that mates your USB-TTL to it easily.
Page | 3
Usage
Check out our step-by-step tutorial https://learn.acrobotic.com/tutorials/post/esp-01-
getting-started for getting started! Also, keep in mind there are a few things to consider
when working with the ESP-01 module:
• We must use 3.3V signals and power (VCC) when working with this module; 5V
will certainly damage it! We can use a Level Shifter for connecting it to 5V devices
• To program or interact with this module we need a microcontroller, single-board
computer, or USB-to-Serial board
• The default firmware allows us to connect the RX/TX pins to one of the devices listed
above, and send AT+Commands to 'tell' the ESP8266 what to do
• We can also use the Arduino IDE to load our own firmware on the ESP8266 (like an
Arduino board). Custom firmware can make use of most (if not all) the same
functions that can be called via AT+Commands
• We can load special firmware that will allow us to program the ESP8266 via a
wireless connection!
• The module is not intended for use on a breadboard (even though it fits), instead we
use female jumper wires for connecting it to other devices
• The ESP8266 pins broken out on the ESP-01 are: 2 GPIO, RX, TX, CH_PD (chip
enable), RST, VCC (3.3V power), and GND
Features
On this neat little module you'll find:
Page | 4
The ESP8266 Internet of Things Wifi Chip
Reference Image
This primer is meant to help you make an educated decision when purchasing an
ESP8266 module, and ensure you buy any necessary supporting hardware.
First of all, what is the ESP8266? Well, it’s a tiny, self-contained, low-power, low-cost, system
on a chip (SOC) with the ability to send and receive TCP/IP network data via an antenna
that’s etched on its circuit board (PCB). It also includes a number of pins that are capable of
sending or receiving signals. In essence, it’s the holy grail of the ‘Internet of Things’ age.
Being the holy grail of an entire movement doesn’t come without it’s downsides, though.
The chip at the heart of the ESP8266 is manufactured by Expressif Systems, a Chinese
company, and let’s just say that they’re not exactly Texas Instruments when it comes to
publishing comprehensive documentation.
This problems surrounding this lack of documentation are compounded by the fact that
these chips aren’t exactly sold as stand alone components – they’re always sold as SOCs,
and there are at least a dozen (mostly Chinese) manufacturers that produce their own SOC
versions! To combat this lack of documentation, people have flooded the internet with their
own hodge-podged tutorials, blog posts, articles, and forum questions, but there’s no truly
Page | 5
comprehensive guide for getting into the ESP8266. On top of all of these problems, these
SOCs being actively developed, expanded, and improved on a seemingly daily basis. This all
leads me to my first huge takeaway from this post:
1) There are multiple products out there labeled ESP8266, but there are at least a dozen
variants and quality documentation is tough to find.
Still interested? Good. You should be. As you read this, be sure to recognize that this
information is current as of September 2015. With as quickly as I mentioned the
ESP8266 chip is moving, it’s very likely that my information will only be complete for a
couple of months. If you’ve found this page prior to purchasing an ESP8266, good on
you for doing your research. I’d strongly encourage you to check out this post by Dani
Eichhorn where he sets out to compare a few of the different variants of the chip. If you
already have an ESP8266 in hand, be sure you know exactly which version of the chip
you have, because specifications change from chip to chip!
ESP8266 ESP-01
This was the original chip. It includes just two input/output pins, and
features an odd pin spacing that basically makes it difficult to work
with in a breadboarding environment.
ESP8266 ESP-05
Page | 6
ESP8266 ESP-12
Unlike the previous SOCs, the ESP-12 breaks out almost all of the
ESP8266’s pins, giving you access to 11 GPIO pins and an analog-to-
digital converter. Once again, the form factor is not conducive to
breadboarding, but there are quite a few adapter boards out there for
this particular variant.
ESP8266 ESP-12E
The ESP-12E is nearly identical to the ESP-12, as you might expect, but
it includes an additional 6 pinouts along the bottom of the board, and
a larger flash memory module (4MB).
ESP-201
NodeMCU
To date, two versions of the module exist – v0.9 and v1.0. The
differences between the two aren’t substantial, the differentiating
features between this module and the above modules is that this
module includes a built-in USB to serial converter, making flashing the
ESP8266 a simple endeavor.
Like the NodeMCU, the SparkFun Thing was created for more easily
facilitating a prototyping environment with an on-board USB to serial
converter, an external antenna connection, and on on-board LiPo
charger/power supply.
Page | 7
The astute reader will notice that the last two modules mentioned above, the NodeMCU
and SparkFun ESP8266 Thing, include USB to serial converters onboard whereas the other
modules do not. The reason for this leads me to my second major takeaway:
2) If you purchase an ESP8266 variant that doesn’t include a USB to serial converter,
you’ll need to purchase one to do anything with the chip.
When I say USB to serial converter, what I really mean is a module with a FTDI FT232RL
usb/serial chip. Just to give you an idea of what to google for, I personally have a OSEPP
FTDI Breakout Board I managed to pick up at Fry’s for $10, but there are other models out
there that accomplish the same thing.
With this primer now out of the way, we should be able to start digging into actually
working with the ESP8266. Be sure to stay tuned for follow-up posts!
I personally have a bench power supply that I use to provide 3.3V to my ESP8266, but any
source capable of delivering at least 250 mA at 3.3V should work just fine.
Page | 8
At this point, it makes sense to split up the rest of the post into two sections – for those of
you that have an Arduino, and those of you that don’t.
Pin Connections
All we’re looking to do here is power on the ESP8266 and make sure it’s working properly.
For that, we only need to connect a few pins. It’s counter-intuitive, but make sure that the
TX pins are connected to each other, as are the RX pins. Also, be sure to tie the CH_PD pin
to 3.3V. Before you connect the VCC and/or GND pins, we’ll first prepare the serial monitor
so that we can see the ESP8266’s boot message.
Page | 9
tough to open the wrong COM port, but you’ll want to make sure that you’re connecting to
the correct one. In this case, my Arduino is connected to COM8.
Once the VCC and/or GND pins are connected, you’ll immediately see the ESP8266 dump a
serial message to the monitor. If your baud rate isn’t set correctly, it will look like a bunch of
gibberish. Most chips will default to 9600, but 115200 is popular as well. You’ll want to make
sure ‘Both NL & CR’ is selected so that newline and carriage return characters are observed.
In this case, the firmware that came included on my chip printed:
ready[/code]
If you scroll all the way to the right and see a MEM CHECK FAIL!!! error, don’t worry too
much about. It’s one of those undocumented quirks of the ESP8266 that no one’s exactly
figured out yet.
Page | 10
Connecting to the ESP8266 without an Arduino
For those of you without an Arduino, you’ll need to have an FTDI USB-to-serial Converter,
as described in the primer.
Pin Connections
Not all FTDI USB-to-serial converters are going to be the same, but for the OSEPP FTDI
Breakout Board that I have, the pins connect as shown here.
Page | 11
There you go! You’ve confirmed that your ESP8266 works! In the next section, we’ll take
advantage of the chip’s wireless capabilities and connect to a local Wifi network.
Connecting to a Network
If you’ve been following along with the series, you’ve completed Part 1 and connected to
your ESP8266 (with either an Arduino or USB-to-serial converter) to your computer.
At this point, it’s important to understand that when we connected to the ESP8266 and
received the ‘ready’ serial response back from the chip as it booted up, that ‘ready’ response
was a routine programmed into the ESP8266’s stock firmware.
We’ll discuss the firmware implications in greater detail during the next post, but until then
keep in mind that the rest of this post pertains to the stock firmware only. If you flash the
firmware with your own brewed up code to make an LED flash, the AT commands that we’re
about to discuss will mean nothing to the ESP8266.
Page | 12
AT Commands
Finally! It’s time to actually interact with the ESP8266. When I say interact, I mean send the
ESP8266 an instruction, and have it respond accordingly. This is accomplished through the
use of AT commands. What are those, you ask? AT commands are essentially instructions
used to control modems. Here’s a reference guide for a cellular module that shows something
like 300 commands, but the number of AT commands recognized by the ESP8266 is limited
to about 30 function (+/- a couple depending on the firmware version). Just keep in mind
that they’re the same commands. The big-picture takeaway here is that the ESP8266 is a
wireless device, and it “speaks the same language” as gps modules and phones’ GSM
modems.
Let’s try out some commands! First, let’s figure out exactly what firmware version we’re
dealing with. To do that, we’ll use the following command:
[code]AT+GMR[/code]
Page | 13
For PuTTY Users
1. Enter the AT command on the input line, then hit Enter. This sends a special CR
(carriage return) character to the ESP8266.
2. The command you just typed will show up below the initial line (depending on your
PuTTY settings), and nothing will seem to happen! This is because the ESP8266 expects
to see two special characters (CR+LF) before it acknowledges the AT command! The
Arduino serial monitor does this by default, but PuTTY cannot be set up to accomplish
this automatically. The LF (line feed) character can be sent by hitting ctrl+J+Enter.
3. The ESP8266’s response will be displayed.
[code]
AT version:0.25.0.0(Jun 5 2015 16:27:16)
SDK version:1.1.1
Ai-Thinker Technology Co. Ltd.
Jun 23 2015 23:23:50
[/code]
There’s a very good chance your firmware version will differ from mine, but don’t worry
about that now. The core set of commands won’t change from firmware version to version,
so the next couple of steps will still be applicable.
Page | 14
ESP8266 can connect to an existing wireless network. When operating in both modes, the
ESP8266 can act like a network repeater.
By default, the ESP8266’s stock firmware is set to AP mode. If you’d like to confirm that this
is the case, send the following command:
[code]AT+CWMODE?[/code]
You should get this response: +CWMODE:2, where 2 corresponds to AP mode as seen in
the table below.
3 Both
Since we’re attempting to connect the ESP8266 to an existing network, we’ll need to change
ESP8266 to network device mode with the following command:
[code]AT+CWMODE=1[/code]
[code]AT+CWLAP[/code]
Page | 15
The ESP8266 will return a list of all the access points in range, with each line item consisting
of the security level of the access point, the network name, the signal strength, MAC address,
and wireless channel. As far as the security level goes, the table below can be used for
reference.
0 Open
2 WPA_PSK
3 WPA2_PSK
4 WPA_WPA2_PSK
[code]
WIFI CONNECTED
WIFI GOT IP
OK
[/code]
That second line WIFI GOT IP means that it’s been assigned an IP address, so let’s check
and see exactly what that address is.
[code]
AT+CIFSR
[/code]
Page | 17
Cool! Everything looks good! Everyone’s router interface is going to be different, but here’s
a screenshot of my router’s device list as it pertains to the ESP8266. You’ll notice that the IP
and MAC addresses match!
As of right now, the firmware that I have installed on the ESP8266 unfortunately doesn’t
allow you do set the name of the device as it will appear on the network – the name would
typically go where the blank box to the right of the IP address is shown, above. Mark my
words, though, that feature will be available on future firmware releases.
List of AT Commands
As I alluded to earlier, there are plenty more AT commands than the ones we used here to
connect to a WiFi network. These sorts of lists are all over the internet, and lots of them are
nowhere close to complete. Instead of making my own list here, and adding to the ESP8266
confusion that’s out there, I’ll link to the actual source that no one ever seems to cite!
https://github.com/espressif/esp8266_at/wiki
What is this ESP8266
Page | 18
Features
Page | 19
Flashing Custom Firmware
Now it’s time to have some fun with the ESP8266! In the last post, NOTES
we talked about AT commands and how they’re used to interact 1. I recommend using the
Arduino IDE for flashing
with the ESP8266; more specifically, how they’re used to interact custom firmware
with its stock firmware. But if you remember, AT commands are 2. The ESP8266 has to be
only used for wireless functionalities. To take advantage of the in bootloader mode
prior to flashing
chip’s really cool general purpose input/output (GPIO) pins, or
some of its more advanced networking capabilities, you’re going
to have to replace the stock firmware through a process known as flashing.
Here’s where things get a little murky, particularly for new developers. It’s probably easiest
for you to think about firmware in terms of it being a simple operating system. Firmware
are generally released for specific purposes. For example, the stock firmware was build
specifically to facilitate AT commands and completing simple wireless tasks. NodeMCU was
built to provide a framework that would run Lua scrips. Similarly, MicroPython allows you to
run a stripped-down version of Python. You can even write your own firmware as if the
ESP8266 were an Arduino! I don’t want to bury the lede too much here, but if you’d like to
skip the background information and get right to writing/uploading custom
firmware, jump down here.
Released Firmwares
As of September 2015, there are a handful of companies/individuals that have released
firmware to the public. This list isn’t exhaustive, but I’ll do my best here to summarize some
of the more popular releases.
Ai-thinker
If you take a close look at the cover on my ESP8266 ESP-
12, you’ll see that it’s branded as an Ai-thinker (under the
cover is the actual ESP8266 with the Espressif markings).
Page | 20
[code]
AT version:0.25.0.0(Jun 5 2015 16:27:16)
SDK version:1.1.1
Ai-Thinker Technology Co. Ltd.
Jun 23 2015 23:23:50
[/code]
NodeMCU
This is one of the popular firmwares out there for the ESP8266, likely because the
documentation is well written and there are plenty of examples. NodeMCU was written
specifically to run Lua scripts, and gives the developer access to all the ESP8226’s
microcontroller functionalities – PGIO/i2c/spi/etc in addition to more advanced networking
capabilities. It functions a little bit differently than the Ai-thinker firmware in that it includes
a filesystem. This allows you to upload Lua scripts that can be run, rather than flashing a new
firmware every time you want to change something.
Official Espressif
Don’t forget, the actual manufacturer of the ESP8266 is the Chinese company Espressif.
They’ve provided plenty of tools, including an SDK, for developing firmware for their
product. However, if you’re not a native Chinese speaker, you’re probably going to have a
difficult time using their tools efficiently. After a ton of searching, I finally found a “developer
zone” forum that they use to release new updates and provide documentation. You can
check that out here: http://bbs.espressif.com.
Fairly recently, Espressif made the decision to close their source code. The last open version
they released is v0.20_14_11_28 and can be downloaded on their forum. They’ve also
provided a flashing tool that’s relatively popular.
MicroPython
MicroPython is, broadly, a stripped-down implementation of Python 3 that’s been built for
embedded systems. As such, the vast majority of Python libraries aren’t compatible with
MicroPython, but the syntax is familiar to those that have used Python. Several months ago,
a group of MicroPython fans decided to port the framework so that it would run on an
ESP8266. The project is still very much in its beta phase, so many of the functionalities that
are built into MicroPython aren’t available on the ESP8266. For those of you keeping track,
that means very littlePython is actually part of MicroPython for the ESP8266. At this point, it
can basically just access GPIO pins and do some simple networking.
Page | 21
In my opinion, there isn’t much point in flashing MicroPython at this point given the
alternatives.
ESP8266 Basic
This is exactly what it sounds like. It’s a BASIC interpreter that’s really easy to flash. It runs
the ESP8266 in access point (AP) mode, and BASIC programs are uploaded to the device via
a simple in-browser interface. If I were a high school teacher, or someone trying to get kids
into electronics and programming, this is exactly the firmware I’d use!
Arduino IDE
For the vast majority of ESP8266 users, using the Arduino IDE to write custom firmware is
going to be their bread and butter. One of the coolest things about the ESP8266 is that it’s
100% compatible with the Arduino IDE! That means that code written for an Arduino is
100% compatible with an ESP8266! If you’re getting antsy after that hype-up, jump down
below to see how to go about writing custom firmware for your ESP8266 with the Arduino
IDE.
Flashing!
The first step to flashing any firmware is to first prepare the ESP8266 by placing it in
bootloader mode. Here’s the bad news if you’ve previously been using an Arduino as your
serial converter – Ardunios cannot be used to flash ESP8266 chips. You’re going to need
an FTDI USB-to-serial converter to do this. If you’ve already been using an FTDI converter,
the good news is that to put the ESP8266 in bootloader mode, all you need do to is tie
GPIO0 and GPIO15 (for the ESP-12 model; other versions will vary) to ground and reset
the chip.
Page | 22
One recommendation if you do go this
route is to go ahead and add in a
capacitor and resistor to tie the RESET
pin to GPIO16. This will come in handy
later as it allows the ESP8266 to reset
itself after entering low-power sleep
mode.
The strange thing about this particular firmware is that Ai-thinker hasn’t publicly released it.
Granted, it’s a bare-bones firmware, and there’s really no need for you to have it installed
on your chip given the other options available, but if you want to return your ESP8266 to
the “stock” firmware, this is the way to do it.
Unless you’re fluent in Chinese, the Ai-thinker forum is going to be impossible to navigate.
It’s entirely possible that they share firmware updates here, but there’s no way for me to
know. Fortunately, there are a pair of Google drives out there (I’m not sure who maintains
it, or how frequently they do so) that share the the Ai-thinker firmware and their flashing tool.
At the moment, the newest firmware version is 0.952 with support for SmartLink, and the
flashing program is ESP8266 Flash Downloader.
This flashing process is almost too simple share. After extracting both folders, it’s as easy as
running esp8266_flasher.exe, specifying the location of the firmware’s .bin file, and hitting
Page | 23
upload (after you’ve put the chip into bootloader mode, of course). It’ll take 30 seconds or
so to complete.
To confirm that the flash was successful, I fired up PuTTY and ran the previously
discussed AT+GMR command. You’ll notice that it’s an older version of what I had shipped to
me, and interestingly, it’s also void of the friendly Ai-thinker message. I’m purely speculating
here, but I’m guessing Ai-thinker just compiled Espressif’s release and added in their own
branding.
Flashing NodeMCU
If you remember from the Primer, NodeMCU actually sells development kits that are
basically just ESP8266 ESP-12E’s with convenient breakouts, buttons, connectors, etc. To
help sell their product, and altruistically help out the whole community, they’ve also released
a convenient flashing tool that works with both NodeMCU and custom-brewed firmware.
The NodeMCU git can be found here. It’s a well-written git that includes a helpful wiki. The
flasher can be downloaded from the appropriate 32-bit or 64-bit folders located here. Once
you have ESP8266Flasher.exe, you don’t even need to download an additional firmware file.
Simply run the .exe. If it doesn’t auto-detect the correct COM port, be sure to get that set
Page | 24
properly. You’ll also want to make sure to view the Advanced tab and ensure that the baud
rate corresponds to the rate the ESP8266 is communicating at prior to the flash. In my
case, it needed to be changed to 115200.
Additionally confirm that the flash size is appropriate, as the different ESP8266 variants will
feature differing storage sizes. After all that, go back to the Operationtab and hit the ‘Flash’
button.
On the other hand, if you don’t want to flash the firmware that’s built into the flashing
program and would rather flash a more recently released version, navigate to the Config tab,
‘X’ the firmware you’d like to flash, set its location, and make sure to place the memory offset
location at 0x00000. Then just flash normally.
Page | 25
To double check and make sure that NodeMCU flashed successfully, open up a serial
connection to your COM port at a 9600 baud rate, then restart your ESP8266. It will attempt
to run the Lua initialization script, but since that doesn’t exist, it stops right there.
Flashing MicroPython
Given its current level of development, flashing MicroPython is an involved process. First
you have to build the firmware from source (unless you find pre-compiled versions), then
flashing can be done either from the command line through the use of esptool.py, or via
the NodeMCU flasher discussed above. Adafruit actually has a really good tutorial for
flashing MicroPython, so instead of rehashing it here, I’ll refer you to Adafruit.
Page | 26
A command prompt will open, and after around 30 seconds (no longer than it takes any of
the other flash methods), the accompanying window will open and let you know of its
success.
Since ESP8266 BASIC puts the chip into AP mode, we’ll just need to double check and make
sure that the device is broadcasting. I fired up my laptop and searched for an SSID that
started with ESP. There it is! After connecting to the ESP8266, if you navigate your browser
to http://192.168.4.1, you’ll be greeted with the interface that will allow you to program
all kinds of BASIC scripts.
Page | 27
4. Scroll to the esp8266 line item, select it, then click Install at the bottom right hand
corner
5. Confirm the board’s setting for your specific ESP8266 variant as shown below
Note that the Programmer option at the bottom of the selector makes no difference as of an
update from ~April 2015
At this point you’ve essentially made your Arduino IDE an ESP8266 IDE! There are plenty
of how-to-write-firmware examples out around the web, so I’ll just mimic those efforts and
make the on-board LED blink. Below is a little piece of code (modified to work with the ESP-
12) that I found somewhere, and cannot for the life of me relocate it to get it properly cited
it. If anyone can fill me in, I’d appreciate it.
[code]
// Import required libraries
#include "ESP8266WiFi.h"
int ledPin = 2; //On the ESP-12, the onboard LED is connected to pin 2
// WiFi parameters
const char* ssid = "<redacted>";
const char* password = "<redacted>";
void setup(void)
{
// Start Serial
Serial.begin(115200);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Page | 28
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
void loop() {
digitalWrite(ledPin, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is acive low on the ESP-01)
delay(1000); // Wait for a second
digitalWrite(ledPin, HIGH); // Turn the LED
off by making the voltage HIGH
delay(2000); // Wait for two seconds (to
demonstrate the active low LED)
}
[/code]
But if we want to reflash Espressif's AT commands firmware again in the Wi-Fi module it is
very simple.
Do the following steps to download and Flash AT command firmware into the module:
Page | 29
1. Download Espressif's original ESP8266 Flasher.exe and ESP8266_AT_firmware.bin.
Please click here to download.
2. Unzip the zip file.
3. Open ESP8266 flasher and add binary.
4. Connect ESP8266 ESP-01 with USB to serial converter. Connect GPIO0 to ground to
put the module into flashing mode.
5. Click to flash the software.
6. Done!
Video: https://youtu.be/7en4QXoUQus
Page | 30
How to flash firmware
yichone edited this page on Dec 1, 2016 · 3 revisions
For ESP32:
Flash address
The images flash to the
address list below:
For ESP8266:
Page | 31
For ESP32:
• blank.bin --> 0xfe000
• boot.bin --> 0x00000
• drom0.bin --> 0x04000
• irom0_flash.bin --> 0x40000
Note: The baudrate to flash for Esp32 must be 230400, while the default baudrate for
Esp8266 is 115200, this can be changed.
Shenzhen Doctors of Intelligence & Technology Co. Ltd: wwww.doit.am, SZDOIT official online Shops: www.vvdoit.com,
and www.smartarduino.com
Page | 32
ESP-01 - Upgrading the on-board flash from 512KB to
4MB
This post is about how to upgrade the on-board flash memory of ESP-01 from 512KB
(W25Q40BV) to 4MB (W25Q32FVSSIG).
Page | 33
Step-3, Launch Arduino IDE, load the "CheckFlashConfig" sample sketch and configure the
IDE according to the below photo.
• Provide external +3.3V to ESP-01 (make sure the +3.3V is connected to VCC, and the
GND is connected to GND). Or, power ESP-01 with the 3V3 power output from CP-
2102.
• Plug the CP-2102 module to the USB port of the computer used for firmware upload;
• First close the flash switch then the reset switch so that both GPIO0 and RST of ESP-
01 are connected to GND;
• First open the reset switch then the flash switch so that both GPIO0 and RST are
floating;
• Click on the upload icon to compile and upload the sketch.
The result
Page | 34
Note,
In the event that the sketch cannot be uploaded to ESP-01 or the execution of the sketch fails after several
successful rounds, it's possible that the flash memory is not soldered properly. When this happens, carefully
re-heat each pin with solder iron and remove any excessive solder then try again.
References:
http://hackaday.com/2016/07/16/your-esp8266-needs-more-memory/
https://www.youtube.com/watch?v=xyc1gCjguRU
Page | 35
ESP8266 module comparison
In this post I will guide you through the jungle of available
modules based on the ESP8266. This is not a complete list of
available modules but a selection of the ones I could test and
review. If you think that I have been missing out on one
important module please let me know.Every module here as
some advantages and disadvantages, depending on the
targeted application. If you are planning to to use a module as Wifi shield for an Arduino
you might pick a different type than if you´re planning a standalone node. Other aspects are
breadboard compatibility, availability of pins, need for external components such as a serial-
to-usb adapter as well as size and costs.
The following tables summarise this post, if you are too much in a hurry to read the whole
article:
GPIO Pins 2 - 11 11 11
ADC - - 1 1 1
Antenna PCB PCB PCB External/PCB PCB
USB-To-Serial No No No No No
Breadboard Medium Good Bad Good Bad
friendly
Form factor Small Small Medium Big Very Big
Price ~$3 ~$3 ~$3 ~$3 ~$6.50
Application Simple Wifi Shield Standalone Standalone Prototyping
Standalone
mode
or wifi shield
for Arduino
Where to buy? Banggood Banggood Banggood Banggood Banggood
Detail Post Post - - Post Post
Page | 36
Comparison of Development Modules
LOLIN V3
NODEMCU WEMOS D1 WEMOS D1
NODEMCU V1.0 NODEMCU
V0.9 MINI R2
BOARD
ESP-01
This is probably one of the most popular modules, although it is by
far not the most convenient one. With its small form factor
(24.75mm x 14.5mm) it fits nicely into any enclosure. Two GPIO pins
are led out and can be used to control periphery. With proper
wiring and a serial-to-usb adapter you can also easily flash
alternatives firmwares on it. By default it comes with one of the
different versions of the AT firmware which allows you to use it in ESP8266 ESP-01
combination with an Arduino. One of the biggest problems of this module
module is the placement of the pin posts which makes it impossible
Page | 37
to plug it directly into a bread board for prototyping: the two rows of posts are so close to
each other that you would get a short-cirtcuit. However you can still use this module on a
breadboard: either build a bread-board adapter or use female-to-male dupont wires to wire
the module to your bread-board.
Update: There are now also versions of the ESP-01 available with 1MB Flash, compared to
the earlier 512MB
ESP-05
This module is very simple and has one purpose only: use it
as mini wifi shield together with your Arduino or similar micro
controller. There are different versions available: a four pin
version that only has 3.3V, GND, RX and TX. Over the later
ones you talk with your Arduino. Another version has an
additional reset pin which allows you to manually or ESP8266 ESP-05 module
programatically reset the module.
This module nicely fits into a breadboard since the module has only one row of pin posts.
But (and there is always a but) you are stuck with the delivered firmware unless you are
willing to do some lead cutting and soldering of some pins. According to the forums not all
boards come with the same AT firmware version.
ESP-12
This module allows you to access many features of the
ESP8266: 11 GPIO pins, one analog-to-digital
converter (ADC) with a 10 bit resolution. It also lets you
easily configure deep-sleep mode which (according to
this source) lets you run the module for 3 years on two
AA batteries. With one drawback: it is not breadboard
friendly at all. As for the modules previously described ESP8266 ESP-12 plus self made
here the antenna is a track on the PCB which delivers bread board adapter
good results for Wifi sensitivity. (thx to Andifor the picture)
But to use it for prototyping you´ll have to build
something around the module. You can order these
breadboard adapters or build one yourself, like my
colleague Andi did:
Page | 38
Thanks to its good availability and the rich access to the chip pins it is also widely used for
aggregated modules, such as the test board I describe later in this post or the first version
of the NodeMCU module. If you are planning to use the ESP8266 as a stand alone node the
chances are good you will end up with this module in one way or the other.
ESP-201
Originally named as ESP-12 this module has come to
popularity as ESP-201 after the name clash had been
discovered. In good old BASIC line adressing style the
creators apparently wanted to make sure that no
other name clash would occure and added a safety
distance to the numbering scheme;-)
Test Board
There are various test boards available. Check the links and view the picture below to see
what I´m describing here. This test board comes with a battery pack and various
preconfigured LEDs and one light dependent resistor connected to the ADC. It integrates
an ESP-12 as described earlier in this post and makes all the pins available to your
convenience. It also has a jumper which you can set when flashing a new firmware. The
board comes with a voltage regulator that steps down the 4.5 Volt from the battery pack to
Page | 39
the 3.3V that the ESP8266 needs. You can easily
replace the battery pack with the power lines of a USB
connector, as I described here.
I had high hopes on this module since in theory it should make development of applications
based on the ESP8266 much easier: less wiring is required compared to any of the other
modules, you need neither an external power supply nor a serial-to-usb adapter and two
switches allow for easy resetting the module and booting it into flash mode. And it nicely
fits into a bread board and lets you wire periphery with the fewest amount of wires
imaginable.
Reality looks currently a bit different: on my Mac I could not flash the module with the built
in serial-to-usb adapter even after installing the latest driver available. I then had to fall back
to an external serial-to-usb adapter. For me this was not a big issue since I don´t flash new
firmwares that often and I was already in possession of an external serial converter. After I
had flashed the latest version of the NodeMCU Lua firmware I could use the built-in
converter just fine. The second problem is that the current form factor of the module covers
all the pins on a bread board in the area of the module. To use the pins you will have to
insert bridges which lead from under the module to a visible part and insert the module
again. And you can only to this for a limited number of pins.
Page | 40
Due to the higher price of this module you will most likely use this module during
development time. Once you have completed the software and all the required external
components you might use one of the other modules or you will design a completely new
module which integrates all the required components
At the time of this writing only the first version of the NodeMCU module is available and
that is what I´m reporting here. In the next few days (or weeks) the team that created the
first module will publish an improved version which will fix the mentioned problems of the
first version. I´m looking forward to test the new version as soon as it becomes available.
Once these issues have been resolved this module certainly has all it takes to become an
interesting all-in-one alternative to an Arduino based internet-of-things node. UPDATE:
don’t order this version anymore, consider the NodeMCU V1.0 instead (see below)
All in all, this is the long awaited development board that you want to have and play with.
The price is slightly higher than with the other boards, starting from around $8 for a potential
clone, but it is totally worth it because you are saving all the additional hardware like serial-
to-usb converter.
Page | 41
New improved version of the NodeMCU V1.0.
Now fits very nicely on a breadboard and also the Serial-To-USB
converter works very well.
Summary
Which module suits you best depends on your application. If the price and small form factor
is important for you and you are looking for a stand alone module with just two GPIO pins,
the ESP-01 is your candidate. If you just want cheap Wifi connectivity for your Arduino you
might go for the ESP-05. The ESP-12 might be interesting if you have periphery based on
SPI or I2C bus or if you just many GPIO pins and you are not afraid of a bit of soldering. The
ESP-201 is good for solder-free prototyping on a bread board and allows you to access
almost all pins of the ESP8266 chip. But you´ll still need an external serial-to-usb converter
and a power supply. In case you want it even easier and the slightly higher price is not a
problem I would recommend the NodeMCU V1.0 module for you. The following table
summarises this post:
Page | 42
Raw Modules
ESP-01 ESP-05 ESP-12 ESP-201 TESTBOARD
GPIO Pins 2 - 11 11 11
ADC - - 1 1 1
Antenna PCB PCB PCB External/PCB PCB
USB-To-Serial No No No No No
Breadboard Medium Good Bad Good Bad
friendly
Form factor Small Small Medium Big Very Big
Price ~$3 ~$3 ~$3 ~$3 ~$6.50
Application Simple Wifi Shield Standalone Standalone Prototyping
Standalone
mode
or wifi shield
for Arduino
Where to buy? Banggood Banggood Banggood Banggood Banggood
Detail Post Post - - Post Post
Page | 43
Form factor Big Big Medium Very Big Big
Price ~$6.40 ~$6 ~$6 ~$6.50 ~6.50
Application Development Development Development Development Development
Beginner Beginner Advanced Form Beginner
(soldering compatibility
required) with
Arduino
Shields
Where to buy? Banggood Banggood Banggood Banggood Banggood
Detail Post Post
Page | 44
The components included in a WeatherStation Kit:
NodeMCU V1 with 4MB flash, 128×64 pixels OLED display,
USB cable and jumper wires. Available now in the shop:
ESP8266 WeatherStation
Page | 45
Wemos D1 R32 ESP32 Boards
Introduction
ESP32 is already integrated antenna and RF balun, power amplifier, low-noise amplifiers,
filters, and power management module. The entire solution takes up the least amount of
printed circuit board area.This board is used with 2.4 GHz dual-mode Wi-Fi and Bluetooth
chips by TSMC 40nm low power technology, power and RF properties best, which is safe,
reliable, and scalable to a variety of applications. Now, it can be gotten from DOIT company
from the link: http://www.smartarduino.com/view.php?id=95103. The ESP32 module is
originally from ESPressif, as shown in the following Figure. The Schematics for ESP32
development board can be seen at SchematicsForESP32Board
The compact ESP32 NodeMCU like board are great for many project, but in case you plan
to leverage your existing Arduino shield, it’s more convenient to have a compatible board.
We’ve previously seen Noduino Quantum board sold for 99 RMB on Taobao, and $25.90 on
AnalogLamb, but doit.am has designed a cheaper model called ESPDUINO-32 that supports
shields compatible with Arduino UNO, and sold for $13.73 on DealExtreme.
Page | 46
The board can be programmed with the Arduino IDE selecting ESP 32 Dev Moduleboard.
You’ll find links to documentation in Smartduino github account. Note that if you have
shields using the Analog input they may not work properly since there’s only one input
supporting up to 3.2V, as Arduino UNO board support 6 analog inputs up to 5V.
Page | 47
How to Get Started with the ESP32
ESP32 is the hottest new wireless chip out there, offering both WiFi and Bluetooth Low
Energy radios rolled up with a dual-core 32-bit processor and packed with peripherals of
every kind. We got some review sample dev boards, Adafruit and Seeed Studio had them in
stock for a while, and AI-Thinker — the company that makes the most popular ESP8266
modules — is starting up full-scale production on October 1st. This means that some of you have
the new hotness in your hands right now, and the rest of you aren’t going to have to wait
more than a few more weeks.
As we said in our first-look review of the new chip, many things are in a state of flux on the
software side, but the basic process of writing, compiling, and flashing code to the chip is
going to remain stable. It’s time to start up some tutorials!
Overview
The ESP32 module comes preloaded with a ROM image with an AT command set, just like
the ESP8266 did. If you want to waste 95% of this chip’s potential by using it as a glorified
serial-to-WiFi modem, you’re all set! But you all want to dig in, right? Right!
The toolchain for programming the ESP32 in C is pretty straight forward. You’ll need
Espressif’s software library (esp-idf), a cross-compiler and build tools that are specific to the
chip (xtensa-esp32-*), and a utility to flash the resulting binary file to the device. I’ll guide you
thought that and then we’ll get Espressif’s demo application compiled and flashed in, at
which point everything’s up and running.
Page | 48
git clone --recursive https://github.com/espressif/esp-idf.git
Note the recursive option which pulls down all submodules that the framework depends on:
in this case some binary blob libraries in components/esp32/lib and components/bt/lib as well as
the esptool.py program that will actually flash the chip for us.
If you just download the zip file from GitHub, it will be missing these essential
pieces. Because of the submodules, you’ll also need to do a two-step to keep everything
current. git pull works for the top level, and git submodule update --recursive updates all of the
submodules.
Now off to get the cross-compiler toolchain. There are instructions for your particular
operating system inside docs. For Linux, MacOS, and Windows alike the fastest way to get up
and running is to download the binary blob from the location listed in the setup file. This is
especially true of Windows, where the nice folks at Espressif have pre-packaged all of the
command-line tools that you’re going to need. Download the toolchain zip file, unzip, and
you’re almost there.
One of the really nice features of the IDF is the menu-driven configuration. The menu
options have changed while we’ve been reviewing the ESP32 chip, as more functionality
gets implemented, and we’re sure that it will continue to change. Nevertheless, here you
can control a lot of your platform-specific settings: which TTY or COM port you’re using,
what baud rate, what speed you’d like the ESP32’s cores to run at, etc. Pay attention to
“Serial flasher config” and browse through “Component config” at the very least.
Since this is a moving target, we can’t really give you much advice that will still be valid in a
week or two. You’re just going to want to go through each menu entry and make sure that
it matches your system. The results of this configuration, when you hit the “Save” option,
will be stored in an sdkconfig file. You can copy this between projects if you don’t want to go
through the menus all over again.
Page | 50
Flashing the Chip
With the configuration done, you’re ready to connect up the serial port and flash the
program. To put the chip in the bootloader mode, you need to hold the boot-mode
pin, GPIO0, grounded while grounding and releasing the enable pin, EN. If you do this with a
terminal application running, you’ll see “waiting for download” typed out. Close your
terminal program, type make flash, and then re-open the terminal program and you should
see lots of debugging info as it attempts to connect to your WiFi.
Now you’re in the loop of coding, flashing, and debugging. Sure, the demo application
doesn’t really do anything. The point is that if you’ve gotten this far, you can compile, flash,
and run code on the device. And that’s the first step!
Recap
Getting up and running is “easy”. Clone the repository with the esp-idf libraries, download and
unzip the binary toolchain, and clone the template app. There are two environment variables
you have to define: one for the path to the toolchain binaries, and another for the location
of the libraries. Run make menuconfig and make flash inside the template application, and you
should be off to the races.
If you’re on a Linux system, here is a setup script that does everything mentioned in this
tutorial. Create a directory where you’d like everything installed, copy this file in there, type .
getESP32.sh and watch it go. If you’ve installed things before, it pulls down the latest version
of everything from GitHub and re-defines the environment variables for you. Even if you
don’t want to use it or have an odd setup, reading through it is a handy checklist to make
sure that you’ve got everything accounted for. Let me know if it doesn’t work for you, and
we’ll fix it.
Note that although this sounds like a lot of work, it’s all a one-time setup cost. For your next
program, you’ll just copy the demo application folder, get into main/main.c and start coding.
Depending on how you’ve configured things, you may need to set those two environment
variables again (make a script/batch file!) but that’s it.
On the subject of coding, there is more than a little bit of black magic in getting a dual-core
microcontroller to play along with a real-time operating system. If you’ve never done so,
stepping up to the ESP32 is going to be a bit of a learning experience. We’ll cover FreeRTOS
and some of its programming conventions as they apply to the ESP32 next time. Stay tuned,
and let us know in the comments if you give this a try, or want to see anything else.
Page | 51
Installing the ESP32 Board in Arduino IDE
(Windows instructions)
There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the
Arduino IDE and its programming language. In this tutorial we’ll show you how to install the
ESP32 board in the Arduino IDE for Windows. If you’re using Mac Os or Linux follow these
instructions instead.
If you have any problems during the installation procedure, take a look at the ESP32
troubleshooting guide.
IMPORTANT NOTE:
1. If this is your first time installing the ESP32 on the Arduino IDE, simply follow the
installation procedure described below;
2. If you’ve already installed the ESP32 add-on using the old
method, you should remove the espressif folder first. Go to
the end of this post to learn how to remove
the espressif folder.
Page | 52
2) Enter https://dl.espressif.com/dl/package_esp32_index.json into the “Additional
Board Manager URLs” field as shown in the figure below. Then, click the “OK” button:
Note: if you already have the ESP8266 boards URL, you can separate the URLs with a comma
as follows:
https://dl.espressif.com/dl/package_esp32_index.json,
http://arduino.esp8266.com/stable/package_esp8266com_index.json
3) Open boards manager. Go
to Tools > Board > Boards Manager…
DOWNLOAD FREE GUIDE: ESP32 Web Server with
Arduino IDE
4) Search for ESP32 and press install button for the “ESP32 by Espressif Systems“:
Page | 53
5) That’s it. It should be installed after a few seconds.
Page | 54
Then, delete the espressif folder:
2) Select your Board in Tools > Board menu (in my case it’s the DOIT ESP32 DEVKIT V1)
3) Select the Port (if you don’t see the COM Port in
your Arduino IDE, you need to install the ESP32
CP210x USB to UART Bridge VCP Drivers):
4) Open the following example
under File > Examples > WiFi (ESP32) > WiFi Scan
Page | 55
6) Press the Upload button in the Arduino IDE. Wait a few seconds while the code compiles
and uploads to your board.
9) Press the ESP32 on-board Enable button and you should see the networks available near
your ESP32:
Page | 56
Wrapping Up
This is a very basic tutorial that illustrates how to prepare your Arduino IDE for the ESP32 on
a Windows PC. To install the Arduino IDE on Mac OS or Linux, follow these
instructions instead. If you encounter any issues during the installation procedure, take a look
at the ESP32 troubleshooting guide.
You might also like reading:
Page | 57
Getting Started with the ESP32 Development Board
This article is a getting started guide
for the ESP32 development board. If
you’re familiar with the ESP8266, the
ESP32 is its sucessor. The ESP32 is loaded
with lots of new features. The most
relevant: it combines WiFi and Bluetooth
wireless capabilities and it’s dual core.
Page | 58
Where to Buy?
Our ESP32 projects are build using mainly the ESP32 DEVKIT DOIT board and that’s the one
we recommend getting.
• ESP32 DEVKIT DOIT board
You can also read the following article that compares several ESP32 development
boards: ESP32 Development Boards.
Specifications
When it comes to the ESP32 chip specifications,
you’ll find that:
• The ESP32 is dual core, this means it has
2 processors.
• It has Wi-Fi and bluetooth built-in.
• It runs 32 bit programs.
• The clock frequency can go up to
240MHz and it has a 512 kB RAM.
• This particular board has 30 or 36 pins,
15 in each row.
• It also has wide variety of peripherals available, like: capacitive touch, ADCs, DACs,
UART, SPI, I2C and much more.
• It comes with built-in hall effect sensor and built-in temperature sensor.
To learn more about the ESP32 GPIOs, read our GPIO reference guide: ESP32 Pinout
Reference: Which GPIO pins should you use?
Programming Environments
The ESP32 can be programmed in different programming environments. You can use:
• Arduino IDE
• Espressif IDF (IoT Development Framework)
• Micropython
• JavaScript
DOWNLOAD FREE GUIDE: ESP32 Web Server with Arduino IDE
Page | 59
Preparing the ESP32 Board in Arduino IDE
There’s an add-on for the Arduino IDE allows you to program the ESP32 using the Arduino
IDE and its programming language. Follow one of the next tutorials to prepare your Arduino
IDE:
ESP32 Pinout
The ESP32 has more GPIOs with more functionalities compared with the ESP826.
With the ESP32 you can decide which pins are UART, I2C, or SPI – you just need to set that
on the code. This is possible due to the ESP32 chip’s multiplexing feature that allows to
assign multiple functions to the same pin. If you don’t set them on the code, the pins will
be used as default – as shown in the figure below (the pin location can change depending
on the manufacturer).
Page | 60
Version with 36 GPIOs
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin ledPin as an output.
pinMode(ledPin, OUTPUT);
}
Page | 61
In this code, we’re controlling an LED connected to GPIO 23.
const int ledPin = 23;
So, connect an LED to your ESP32 by following the next schematic diagram.
Important: always check the pinout for your specific board before building any circuit.
Page | 62
Note: If you get the following error when trying to upload code, it means that your ESP32 is
not in flashing/uploading mode.
Failed to connect to ESP32: Timed out… Connecting…
To upload code, you need to follow the next steps (make sure you have the right board
selected:
Demonstration
After uploading the code, the LED
connected to GPIO 23 should be blinking
every other second.
Page | 63
Wrapping up
We hope you’ve found this getting started guide useful. The blinking LED is just a simple
project to get you started with the ESP32. This is also a great way to learn the procedure
you need to do to upload code to your board.
If you like ESP32, we have more than 20 projects with the ESP32 you can find in our
repository of ESP32 projects:
• 20+ ESP32 Projects and Tutorials
The ESP32 and ESP8266 are cheap Wi-Fi modules perfectly suited for DIY projects in the
Internet of Things (IoT) field. These modules come with GPIOs, support for a variety of
protocols like SPI, I2C, UART, and more. The best part is that they come with wireless
networking included, which makes them apart from other microcontrollers like the
Arduino. This means that you can easily control and monitor devices remotely via Wi-Fi for
a very low price.
Page | 64
The following table shows the main differences between the ESP8266 and the ESP32
processors (table adapted from: AMICA_IO).
ESP8266 ESP32
MCU Xtensa Single-core 32-bit L106 Xtensa Dual-Core 32-bit LX6 with 600
DMIPS
802.11 b/g/n Wi-Fi
Bluetooth X Bluetooth 4.2 and BLE
Typical Frequency 80 MHz 160 MHz
SRAM X ✓
Flash X ✓
GPIO
Hardware /Software None / 8 channels None / 16 channels
PWM
SPI/I2C/I2S/UART 2/1/2/2 4/2/2/2
ADC 10-bit 12-bit
CAN X ✓
Ethernet MAC Interface X ✓
Touch Sensor X ✓
Temperature Sensor X ✓
Hall effect sensor X ✓
Working Temperature -40ºC to 125ºC -40ºC to 125ºC
Price $ (3$ - $6) $$ ($6 - $12)
Where to buy Best ESP8266 Wi-Fi Development ESP32 Development Boards Review and
Boards Comparison
Page | 65
More GPIOs on the ESP32
The ESP32 has more pins than the ESP8266, and you can decide which pins are UART, I2C,
or SPI – you just need to set that on the code. This is possible due to the ESP32 chip’s
multiplexing feature that allows to assign multiple functions to the same pin. If you don’t
set them on the code, they will be on the pins defined by default as shown in the following
figure (this is an example for the ESP32 DEVKIT V1 DOIT board – the pin location can change
depending on the manufacturer).
Recommended reading: ESP32 Pinout Reference: Which GPIO pins should you use?
You can set PWM signals in any GPIO with configurable frequencies and duty cycles set on
the code. When it comes to the analog pins, these are static, but the ESP32 supports
measurements on 18 channels (analog-enabled pins) versus one 10-bit ADC pin on the
ESP8266. The ESP32 also supports two 8-bit DAC channels.
Additionally, the ESP32 contains 10 capacitive sensing GPIOs, that detect touch and can be
used to trigger events, or wake-up the ESP32 from deep sleep, for example.
This is is a good thing, specially for those who are used to program
with the Arduino and are familiar with the Arduino programming
language. Learn how to install the ESP32 or ESP8266 in your Arduino IDE:
Although you can program both boards using Arduino IDE, they might not be compatible
with the same libraries. Some libraries are just compatible with one of the boards.
Wrapping Up
So, at this point you should be
asking: Should I get an ESP8266 or an
ESP32?
Page | 66
It really depends on what you want to do. There is space for both boards, and both have
pros and cons.
The ESP8266 is cheaper than the ESP32. Although it doesn’t have as much functionalities, it
works just fine for the majority of simple DIY IoT projects. Additionally, because it is “older”
it is much more supported in terms of software, and you might find help easier. However, it
has some limitations when it comes to the GPIO mapping, and it might not have enough
pins for what you intend to do. If that’s the case, you should get an ESP32.
The ESP32 is much more powerful than the ESP8266, contains more GPIOs with multiple
functions, faster Wi-Fi, and also supports Bluetooth. Many people think that the ESP32 is
more complicated to deal with than the ESP8266 because it is more complex. In our opinion,
it is as easy to program the ESP32 as the ESP8266, specially if you intend to program it using
the Arduino language.
However, the ESP32 has some cons too. First, it is more expensive than the ESP8266. So, if
you’re making a simple IoT project, the ESP8266 might do the trick for a lower price.
Additionally, because it is more recent than the ESP8266, not all software has been
developed to take the most out of the ESP32 functionalities, there is less support, and more
bugs. But on the long run these issues will be fixed, and there will be space for both boards.
The ESP32 chip comes with 48 pins with multiple functions. Not all pins are exposed in all
ESP32 development boards, and there are some pins that cannot be used. There are many
questions on how to use the ESP32 GPIOs. What pins should you use? What pins should you
avoid using in your projects? This post aims to be a simple and easy to follow reference
guide for the ESP32 GPIOs.
Note: Not all GPIOs are accessible in all development boards, but each specific GPIO works
in the same way regardless of the development board you’re using.
Page | 67
ESP32 Peripherals
The ESP32 peripherals include:
• 18 Analog-to-Digital Converter (ADC) channels
• 3 SPI interfaces
• 3 UART interfaces
• 2 I2C interfaces
• 16 PWM output channels
• 2 Digital-to-Analog Converters (DAC)
• 2 I2S interfaces
• 10 Capacitive sensing GPIOs
The ADC (analog to digital converter) and DAC (digital to analog converter) features are
assigned to specific static pins. However, you can decide which pins are UART, I2C, SPI, PWM,
etc – you just need to assign them in the code. This is possible due to the ESP32 chip’s
multiplexing feature.
Although you can define the pins properties on the software, there are pins assigned by
default as shown in the following figure (this is an example for the ESP32 DEVKIT V1 DOIT
board with 36 pins – the pin location can change depending on the manufacturer).
Page | 68
Additionally, there are pins with specific features that make them suitable or not for a
specific project. Continue reading to learn more about the ESP32 GPIOs.
The figure below illustrates the ESP-WROOM-32 pinout. You can use it as a reference if
you’re using a bare chip to build a custom board:
Page | 69
SPI flash integrated on the ESP-WROOM-32
GPIO 6 to GPIO 11 are exposed in some ESP32 development boards. However, these pins
are connected to the integrated SPI flash on the ESP-WROOM-32 chip and are not
recommended for other uses. So, don’t use these pins in your projects:
• GPIO 6 (SCK/CLK)
• GPIO 7 (SDO/SD0)
• GPIO 8 (SDI/SD1)
• GPIO 9 (SHD/SD2)
• GPIO 10 (SWP/SD3)
• GPIO 11 (CSC/CMD)
Page | 70
• ADC1_CH3 (GPIO 39)
• ADC1_CH4 (GPIO 32)
• ADC1_CH5 (GPIO 33)
• ADC1_CH6 (GPIO 34)
• ADC1_CH7 (GPIO 35)
• ADC2_CH0 (GPIO 4)
• ADC2_CH1 (GPIO 0)
• ADC2_CH2 (GPIO 2)
• ADC2_CH3 (GPIO 15)
• ADC2_CH4 (GPIO 13)
• ADC2_CH5 (GPIO 12)
• ADC2_CH6 (GPIO 14)
• ADC2_CH7 (GPIO 27)
• ADC2_CH8 (GPIO 25)
• ADC2_CH9 (GPIO 26)
The ADC input channels have a 12 bit resolution. This means that you can get analog
readings ranging from 0 to 4095, in which 0 corresponds to 0V and 4095 to 3.3V. You also
have the ability to set the resolution of your channels on the code, as well as the ADC range.
Page | 71
RTC GPIOs
There is RTC GPIO support on the ESP32. The GPIOs routed to the RTC low-power subsystem
can be used when the ESP32 is in deep sleep. These RTC GPIOs can be used to wake up the
ESP32 from deep sleep when the Ultra Low Power (ULP) co-processor is running. The
following GPIOs can be used as an external wake up source.
• RTC_GPIO0 (GPIO36)
• RTC_GPIO3 (GPIO39)
• RTC_GPIO4 (GPIO34)
• RTC_GPIO5 (GPIO35)
• RTC_GPIO6 (GPIO25)
• RTC_GPIO7 (GPIO26)
• RTC_GPIO8 (GPIO33)
• RTC_GPIO9 (GPIO32)
• RTC_GPIO10 (GPIO4)
• RTC_GPIO11 (GPIO0)
• RTC_GPIO12 (GPIO2)
• RTC_GPIO13 (GPIO15)
• RTC_GPIO14 (GPIO13)
• RTC_GPIO15 (GPIO12)
• RTC_GPIO16 (GPIO14)
• RTC_GPIO17 (GPIO27)
PWM
The ESP32 LED PWM controller has 16 independent channels that can be configured to
generate PWM signals with different properties. All pins that can act as outputs can be used
as PWM pins (GPIOs 34 to 39 can’t generate PWM).
To set a PWM signal, you need to define these parameters in the code:
• Signal’s frequency;
• Duty cycle;
• PWM channel;
• GPIO where you want to output the signal.
Page | 72
I2C
When using the ESP32 with the Arduino IDE, you should use the ESP32 I2C default pins
(supported by the Wire library):
• GPIO 21 (SDA)
• GPIO 22 (SCL)
SPI
By default, the pin mapping for SPI is:
Interrupts
All GPIOs can be configured as interrupts.
Enable (EN)
Enable (EN) is the 3.3V regulator’s enable pin. It’s pulled up, so connect to ground to disable
the 3.3V regulator. This means that you can use this pin connected to a pushbutton to restart
your ESP32, for example.
Wrapping Up
We hope you’ve found this reference guide for the ESP32 GPIOs useful. If you have more
tips about the ESP32 GPIOs, please share by writing a comment down below.
If you’re just getting started with the ESP32, we have some great content to get started:
Page | 73
ESP32 Development Boards Review and Comparison
In this post we’re going to compare several ESP32 development boards. The aim of this
article is to help you chose the best ESP32 development board for your project
requirements.
The ESP32 is the ESP8266 successor (read best ESP8266 development boards). The ESP32 is
loaded with lots of new features. It combines Wi-Fi and Bluetooth wireless capabilities, and
it’s dual core.
You can find the ESP32 as a standalone module or as a full-feature development board.
There are lots of ESP32 development boards available. In this review, we’ll just take a look
at the most popular ESP32 development boards.
Page | 74
ESP32 Development Boards Comparison
ON-BOARD
FIGURE NAME LINKS GPIOS PINOUT EXTRAS
BUTTONS
Amazon.co.uk
ESP32 LOLIN Banggood See here EN and BOOT 0.96'' OLED display
OLED
Page | 75
ESP32 Features and Specifications
Here’s a quick run down of some features and specifications of the ESP32 chip:
• Wireless connectivity
▪ WiFi: 150.0 Mbps data rate with HT40
▪ Bluetooth: BLE (Bluetooth Low Energy) and legacy Bluetooth.
• Processor: Tensilica Xtensa Dual-Core 32-bit LX6 microprocessor, running at 160 or
240 MHz
• ROM: 448 KB
• SRAM: 520 KB
• Low Power: ensures that you can still use ADC conversions, for example, during
deep sleep.
• Peripheral Input/Output: peripheral interface with DMA that includes capacitive
touch, ADCs (Analog-to-Digital Converter), DACs (Digital-to-Analog Converter), I²C
(Inter-Integrated Circuit), UART (Universal Asynchronous Receiver/Transmitter), SPI
(Serial Peripheral Interface), I²S (Integrated Interchip Sound), RMII (Reduced Media-
Independent Interface) and PWM (Pulse-Width Modulation).
• Security: hardware accelerators for AES and SSL/TLS
When looking for an ESP32 development board there are several aspects you need to take
into account:
• Pin configuration and number of pins. To properly use the ESP32 in your projects
you need to have access to the board pinout. Make sure you have access to the
board pinout you’re getting. Otherwise, you may end up using the ESP32 incorrectly.
• USB-to-UART interface and voltage regulator circuit. Most full-feature
development boards have these two features.
Page | 76
• BOOT and RESET buttons.
• Battery connector. If you want to power your ESP32 using batteries, there are
development boards that come with connectors for liPo batteries.
• Extra features. There are ESP32 development boards with extra features like an
OLED display, or a LoRa module.
Wrapping Up
In this article we’ve compared a selection of ESP32 development boards. The ESP32 DEVKIT
DOIT, the Adafruit ESP32 Feather, and the ESP32 thing are all very similar. These don’t come
with extra hardware, so they are easier to use and those are the ones we recommend for
beginners. We’ve been using the ESP32 DEVKIT DOIT boards and they work perfectly.
However, if you want something really high-quality, the ESP32 feather and the ESP32 Thing
are just great.
Page | 78
If you have a really specific project in mind, then maybe one of the other models is more
suitable for you. For example, if you intend to add an OLED display to your project, the
ESP32 with built-in OLED will provide all you need in a small footprint.
We hope you’ve found these selection and comparison of ESP32 development boards
useful.
Project Overview
Before going straight to the project, it is important to outline what our web server will do,
so that it is easier to follow the steps later on.
• The web server you’ll build controls two LEDs connected to the ESP32 GPIOs 26, and
27;
• You can access the ESP32 web server by typing the ESP32 IP address on a browser in
the local network;
• By clicking the buttons on your web server you can instantly change the state of
each LED.
This is just a simple example to illustrate how to build a web server that controls outputs,
the idea is to replace those LEDs with a relay, or any other electronic components you want.
Page | 79
Installing the ESP32 board in Arduino IDE
There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the
Arduino IDE and its programming language. Follow one of the following tutorials to prepare
your Arduino IDE:
Parts Required
Schematic
Start by building the circuit. Connect two
LEDs to the ESP32 as shown in the following
schematic diagram – one LED connected to
GPIO 26, and the other to GPIO 27.
Here we provide the code that creates the ESP32 web server. Copy the following code to
your Arduino IDE, but don’t upload it yet. You need to make some changes to make it work
for you.
Page | 80
/*********
Rui Santos
Complete project details at http://randomnerdtutorials.com
*********/
void setup() {
Serial.begin(115200);
void loop(){
WiFiClient client = server.available(); // Listen for incoming clients
Page | 83
Uploading the Code
Now, you can upload the code and and the web server will work straight away. Follow the
next steps to upload code to the ESP32:
4. Press the Upload button in the Arduino IDE and wait a few seconds while the code
compiles and uploads to your board.
Page | 84
Finding the ESP IP Address
After uploading the code, open the Serial Monitor at a baud rate of 115200.
Press the ESP32 EN button (reset). The ESP32 connects to Wi-Fi, and outputs the ESP IP
address on the Serial Monitor. Copy that IP address, because you need it to access the ESP32
web server.
Page | 85
You can also see other
information about the
HTTP request.
Page | 86
The first thing you need to do is to include the WiFi library. This is the same library used to
create a web server with the Arduino using the Ethernet shield.
#include <WiFi.h>
As mentioned previously, you need to insert your ssid and password in the following lines
inside the double quotes.
const char* ssid = "";
const char* password = "";
The following line creates a variable to store the header of the HTTP request:
String header;
Next, you create auxiliar variables to store the current state of your outputs. If you want to
add more outputs and save its state, you need to create more variables.
String output26State = "off";
String output27State = "off";
You also need to assign a GPIO to each of your outputs. Here we are using GPIO 26 and
GPIO 27. You can use any other suitable GPIOs.
const int output26 = 26;
const int output27 = 27;
setup()
Now, let’s go into the setup(). First, we start a serial communication at a baud rate of 115200
for debugging purposes.
Serial.begin(115200);
Page | 87
You also define your GPIOs as OUTPUTs and set them to LOW.
// Initialize the output variables as outputs
pinMode(output26, OUTPUT);
pinMode(output27, OUTPUT);
// Set outputs to LOW
digitalWrite(output26, LOW);
digitalWrite(output27, LOW);
The following lines begin the Wi-Fi connection with WiFi.begin(ssid, password), wait for a
successful connection and print the ESP IP address in the Serial Monitor.
// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
loop()
In the loop() we program what happens when a new client establishes a connection with the
web server.
The ESP32 is always listening for incoming clients with the following line:
WiFiClient client = server.available(); // Listen for incoming clients
Page | 88
When a request is received from a client, we’ll save the incoming data. The while loop that
follows will be running as long as the client stays connected. We don’t recommend changing
the following part of the code unless you know exactly what you are doing.
if (client) { // If a new client connects,
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
/ that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
Page | 89
The next section of if and else statements checks which button was pressed in your web
page, and controls the outputs accordingly. As we’ve seen previously, we make a request on
different URLs depending on the button pressed.
For example, if you’ve press the GPIO 26 ON button, the ESP32 receives a request on
the /26/ON URL (we can see that that information on the HTTP header on the Serial
Monitor). So, we can check if the header contains the expression GET /26/on. If it contains,
we change the output26state variable to ON, and the ESP32 turns the LED on.
This works similarly for the other buttons. So, if you want to add more outputs, you should
modify this part of the code to include them.
Page | 90
The web page is sent to the client using this expressing client.println(). You should enter
what you want to send to the client as an argument.
The first thing we should send is always the following line, that indicates that we are sending
HTML.
<!DOCTYPE HTML><html>
Then, the following line makes the web page responsive in any web browser.
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
And the following is used to prevent requests on the favicon. – You don’t need to worry
about this line.
client.println("<link rel=\"icon\" href=\"data:,\">");
We style our buttons with the #4CAF50 color, without border, text in white color, and with
this padding: 16px 40px. We also set the text-decoration to none, define the font size, the
margin, and the cursor to a pointer.
client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
We also define the style for a second button, with all the properties of the button we’ve
defined earlier, but with a different color. This will be the style for the off button.
client.println(".button2 {background-color: #555555;}</style></head>");
Page | 91
Then, we display the on or the off button, depending on the current state of the GPIO. If the
current state of the GPIO is off, we show the ON button, if not, we display the OFF button.
if (output26State=="off") {
client.println("<p><a href=\"/26/on\"><button class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/26/off\"><button class=\"button button2\">OFF</button></a></p>");
}
We use the same procedure for GPIO 27.
Wrapping Up
In this tutorial we’ve shown you how to build a web server with the ESP32. We’ve shown you
a simple example that controls two LEDs, but the idea is to replace those LEDs with a relay,
or any other output you want to control. For more projects with ESP32, check the following
tutorials:
Page | 92
ESP32 Troubleshooting Guide
The ESP32 has a few common
problems, specially when you are trying to upload
new sketches or install the ESP32 add-on on the
Arduino IDE.
IMPORTANT: MAKE SURE YOU HAVE THE LATEST ARDUINO IDE INSTALLED. USING A
DIFFERENT ARDUINO IDE VERSION MIGHT CAUSE OTHER UNEXPECTED PROBLEMS AND
ERRORS.
Page | 93
3. C:\\Users\\ User\\Documents \\Arduino\\ hardware\\ espressif\\ esp32/tools
/xtensa-esp32-elf /bin/ xtensa-esp32- elf-g++”: file does not exist
After installing the ESP32 add-on, if you open the Arduino IDE and it fails to compile code
to your ESP32 board, we recommend re-running the Arduino IDE ESP32 add-on intallation.
Note: Windows PCs often have multiple Arduino IDE versions installed (portable and local
installations). Make sure you are running the Arduino IDE where you installed the ESP32
add-on.
Having the right board name and COM por selected, follow these steps:
To be honest we’re not sure why that happens with the newer boards. We don’t have any
ESP32 board with that behavior. We think there might be something different with your
specific board or the Arduino IDE fails to send the right command sequence to put the
ESP32 automatically in flashing/uploading mode.
Page | 96
2. If you have the drivers installed, but you can’t see your device, double-check that you’re
using a USB cable with data wires.
USB cables from powerbanks often don’t have data wires (they are charge only). So, your
computer will never establish a serial communication with your ESP32. Using a a proper USB
cable should solve your problem.
Wrapping Up
We hope you’ve found this guide useful. If you encounter any other issues, please post them
in comments below and we’ll try to help you solve your problem.
Page | 97
Blynk
Intro
This guide will help you understand how to get started using Blynk and give a
comprehensive overview of all the features.
If you want to jump straight into playing with Blynk, check out Getting Started.
Features
• Similar API & UI for all supported
hardware & devices
• Connection to the cloud using:
• Bluetooth and BLE
• Ethernet
• USB (Serial)
• Set of easy-to-use Widgets
• Direct pin manipulation with no code writing
Page | 98
• Easy to integrate and add new functionality using virtual pins
• History data monitoring via SuperChart widget
• Device-to-Device communication using Bridge Widget
• Sending emails, tweets, push notifications, etc.
• … new features are constantly added!
You can find example sketches covering basic Blynk Features. They are included in the library.
All the sketches are designed to be easily combined with each other.
1. Hardware.
An Arduino, Raspberry Pi, or a similar development kit.
Blynk works over the Internet. This means that the hardware you choose should be able
to connect to the internet. Some of the boards, like Arduino Uno will need an Ethernet or
Wi-Fi Shield to communicate, others are already Internet-enabled: like the ESP8266,
Raspberri Pi with WiFi dongle, Particle Photon or SparkFun Blynk Board. But even if you don’t
have a shield, you can connect it over USB to your laptop or desktop (it’s a bit more
complicated for newbies, but we got you covered). What’s cool, is that the list of
hardware that works with Blynk is huge and will keep on growing.
2. A Smartphone.
The Blynk App is a well designed interface builder. It works
on both iOS and Android, so no holywars here, ok?
Getting Started
Let’s get you started in 5 minutes (reading doesn’t count!).
We will switch on an LED connected to your Arduino using
the Blynk App on your smartphone.
Connect an LED as shown here:
Page | 99
Getting Started With The Blynk App
1. Create a Blynk Account
You can always set up your own Private Blynk Server and have
full control.
4. Auth Token
5. Add a Widget
Drag-n-Drop - Tap and hold the Widget to drag it to the new position.
Widget Settings - Each Widget has it’s own settings. Tap on the widget
to get to them.
Page | 101
6. Run The Project
When you are done with the Settings - press the PLAYbutton.
This will switch you from EDIT mode to PLAY mode where you can
interact with the hardware. While in PLAY mode, you won’t be
able to drag or set up new widgets, press STOP and get back to
EDIT mode.
You will get a message saying “Arduino UNO is offline”. We’ll deal
with that in the next section.
Example sketches will help you get your hardware online quickly and major Blynk features.
Open the example sketch according to the hardware model or shield you are using.
Let’s take a look at the example sketch for an Arduino UNO + Ethernet shield
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
Page | 102
void setup()
{
Serial.begin(); // See the connection status in Serial Monitor
Blynk.begin(auth); // Here your Arduino connects to the Blynk Cloud.
}
void loop()
{
Blynk.run(); // All the Blynk Magic happens here...
}
Auth Token
Blynking
Go back to the Blynk App, push the button and turn the LED on
and off! It should be Blynking.
Page | 103
Feel free to experiment and combine different examples together to create your own
amazing projects.
For example, to attach an LED to a PWM-enabled Pin on your Arduino, set the slider widget
to control the brightness of an LED. Just use the same steps described above.
Hardware set-ups
Arduino over USB (no shield)
If you don’t have any shield and your hardware doesn’t have any connectivity, you can still
use Blynk – directly over USB :
1. Open Arduino Serial USB example and change Auth Token
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(, ); // RX, TX
void setup()
{
// Debug console
DebugSerial.begin();
Page | 104
void loop()
{
Blynk.run();
}
2. Run the script which is usually located in /scripts folder:
• Windows:My Documents\Arduino\libraries\Blynk\scripts
• Mac User$/Documents/Arduino/libraries/Blynk/scripts
On Windows:
Open cmd.exe
Run blynk-ser.bat file. For example : blynk-ser.bat -c COM4 (where COM4 is port with your Arduino)
Page | 105
2015/10/03 00:29:45 socat[30438.2046857984] N opening character device "/dev/tty.usbmodem1451"
for reading and writing
2015/10/03 00:29:45 socat[30438.2046857984] N opening connection to LEN=16 AF=2
45.55.195.102:9443
2015/10/03 00:29:45 socat[30438.2046857984] N successfully connected from local address LEN=16
AF=2 192.168.0.2:56821
2015/10/03 00:29:45 socat[30438.2046857984] N SSL connection using AES128-SHA
2015/10/03 00:29:45 socat[30438.2046857984] N starting data transfer loop with FDs [3,3] and [4,4]
NOTE: Arduino IDE may complain with “programmer is not responding”. You need to
terminate script before uploading new sketch.
Additional materials:
ESP8266 Standalone
You can run Blynk directly on the ESP8266!
Install the latest ESP8266 library for Arduino using this guide.
Example Sketch: ESP8266_Standalone
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example runs directly on ESP8266 chip.
Note: This requires ESP8266 support package:
https://github.com/esp8266/Arduino
Please be sure to select the right ESP8266 module
in the Tools -> Board menu!
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
Page | 106
*************************************************************/
NodeMCU
Please follow this detailed instruction. Or watch this Video tutorial.
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
Page | 107
This example runs directly on NodeMCU.
Note: This requires ESP8266 support package:
https://github.com/esp8266/Arduino
Please be sure to select the right NodeMCU module
in the Tools -> Board menu!
For advanced settings please follow ESP examples :
- ESP8266_Standalone_Manual_IP.ino
- ESP8266_Standalone_SmartConfig.ino
- ESP8266_Standalone_SSL.ino
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop()
{
Blynk.run();
}
Page | 108
Arduino + ESP8266 WiFi with AT commands
This connection type is not recommended for beginners.
If you would like to try it, please carefully read this help topic
Note: Some boards like Arduino UNO WiFi from Arduino.org, do not use AT commands (and
do not provide relevant libraries), so this renders them unusable with Blynk.
Anything you connect to your hardware will be able to talk to Blynk. With Virtual Pins you
can send something from the App, process it on microcontroller and then send it back to
the smartphone. You can trigger functions, read I2C devices, convert values, control servo
and DC motors etc.
Virtual Pins can be used to interface with external libraries (Servo, LCD and others) and
implement custom functionality.
Hardware may send data to the Widgets over the Virtual Pin like this:
Blynk.virtualWrite(pin, "abc");
Blynk.virtualWrite(pin, );
Blynk.virtualWrite(pin, );
Blynk.virtualWrite(pin, "hello", , );
For more information about virtual pins, read this
For example, code below shows how to get values from the Button Widget in the App
Page | 109
BLYNK_WRITE(V)
//Button Widget is writing to pin V
{
int pinData = param.asInt();
}
When you press a Button, Blynk App sends 1 On the second
click - it sends 0
Page | 110
Perform requests by Widget
• Using Blynk built-in reading frequency while App is
active by setting ‘Reading Frequency’ parameter to some
interval:
BLYNK_READ(V) // Widget in the app READs Virtal Pin V with
the certain frequency
{
// This command writes Arduino's uptime in seconds
to Virtual Pin V
Blynk.virtualWrite(, millis() / );
}
Sketch:PushDataOnRequest
void setup()
{
Serial.begin();
Blynk.begin(auth);
timer.setInterval(L, sendUptime); // Here you set interval (sec) and which function to call
}
Page | 111
void sendUptime()
{
// This function sends Arduino up time every second to Virtual Pin (V)
// In the app, Widget's reading frequency should be set to PUSH
// You can send anything with any interval using this construction
// Don't send more that values per second
Blynk.virtualWrite(V, millis() / );
}
void loop()
{
Blynk.run(); // all the Blynk magic happens here
timer.run(); // BlynkTimer is working...
}
Sketch: PushData
State syncing
For hardware
If your hardware looses Internet connection or resets, you can restore all the values from
Widgets in the Blynk app.
BLYNK_CONNECTED() {
Blynk.syncAll();
}
WARNING: if pin is empty and wasn’t initialized - hardware will not get any response for
those pin during sync.
You can also update a single Virtual Pin value by calling Blynk.syncVirtual(V0) or you can update
several pins with Blynk.syncVirtual(V0, V1, V2, ...).
Page | 112
You can also use server to store any value without widget. Just call Blynk.virtualWrite(V0, value).
Storing single value on server
Storing multiple values on server
For app
If you need to keep your hardware in sync with Widgets’ state even if
app is offline use Blynk.virtualWrite.
Imagine you have a LED Widget connected to the Virtual Pin V1 in the
app, and a physical button attached to your hardware. When you press
a physical button, you would expect to see updated state of the LED
Widget in the app. To achieve that you need to send Blynk.virtualWrite(V1,
255) when a physical button gets pressed.
Represent physical button state via LED widget with interrupts
Represent physical button state via LED widget with polling
Represent physical button state via Button widget with polling
Page | 113
Tags
Tags feature allows you to group multiple devices. Tags are very useful in case you want to
control few devices with 1 widget. For example, imagine a case when you have 3 smart bulbs
and you want to turn on all those bulbs with one single click. You need to assign 3 devices
to 1 tag and assign tag to button. That’s it.
Tag widgets also support state syncing. So you can get state of widget from your hardware.
However you can’t update state of such widgets from hardware.
That’s why Blynk uses HEARTBEAT mechanism. With this approach hardware periodically
sends ping command with predefined interval (10 seconds by
default, BLYNK_HEARTBEAT property). In case hardware don’t send anything within 10 seconds
server waits additional 5 seconds and after that connection assumed to be broken and
closed by server. So on UI you’ll see connection status update only after 15 seconds when
it is actually happened.
You can also change HEARTBEAT interval from hardware side via Blynk.config. In that
case newHeartbeatInterval * 2.3 formula will be applied. So in case you you decided to
set HEARTBEAT interval to 5 seconds. You’ll get notification regarding connection with 11 sec
delay in worst case.
Project Settings
Every project has it’s own settings:
• Theme - switch between the Light and Black Blynk Theme (Business accounts have
wider choice);
• Keep screen always on - allows you to use the Blynk app without going to the sleep
mode (usually all mobile devices do that);
Page | 114
• Send app connected command - with this option enabled the server will send “App
Connected” and “App Disconnected” commands to your hardware when your Blynk
app goes online/offline. Usage example;
• Do not show offline notifications - right now, for debugging purposes, every time
your hardware goes offline - the Blynk Server will notify you with popup in the app
about that. However, when debugging is not needed or the Blynk app is used only
via HTTP/S this notifications are meaningless. So this switch allows you to turn off
this popups. Also this switch turns off the Push notification “Notify when offline”
option.
NOTE : Changing these parameters work only for widgets attached to Virtual pins
(analog/digital pins won’t work).
Four widget properties are supported - color, label, min, max for all widgets :
label is string for label of all widgets.
color is string in HEX format (in the form: #RRGGBB, where RR (red), GG (green) and
BB (blue) are hexadecimal values between 00 and FF). For example :
#define BLYNK_GREEN "#23C48E"
#define BLYNK_BLUE "#04C0F8"
#define BLYNK_YELLOW "#ED9D00"
#define BLYNK_RED "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"
Page | 115
min, max - minimum and maximum values for the widget (for example range for the
Slider). This numbers may be float.
On firmware side, widget objects also support setLabel() and setColor() functions.
Button
onLabel / offLabel is string for ON/OFF label of button;
Styled Button
onLabel / offLabel is string for ON/OFF label of button;
onColor / offColor is string in HEX format for ON/OFF colors of the button;
onBackColor / offBackColor is string in HEX format for ON/OFF colors of the button
background.
Music Player
isOnPlay is boolean accepts true/false.
Data Mapping
In case you want to map incoming values to specific range you
may use mapping button:
Let’s say your sensor sends values from 0 to 1023. But you want to display values in a range
0 to 100 in the app. When Data Mapping enabled, incoming value 1023 will be mapped to
100.
Page | 117
SPLIT/MERGE
Some of the Widgets can send more than one value. And
with this switch you can control how to send them.
• SPLIT: Each of the parameters is sent directly to the
Pin on your hardware (e.g D7). You don’t need to
write any code.
Example: Add a zeRGBa Widget and set it to MERGE mode. Choose Virtual Pin V1
BLYNK_WRITE(V) // There is a Widget that WRITEs data to V
{
int r = param[].asInt(); // get a RED channel value
int g = param[].asInt(); // get a GREEN channel value
int b = param[].asInt(); // get a BLUE channel value
}
Decimals
Defines how many decimals you would like to see when moving a Slider. When “No Fraction”
is chosen, slider will only send integer values with no decimals. “1 digit” means that values
will look like 1.1, 1.2, …, 2.0, etc.
Send On Release
This option allows you to optimize data traffic on your hardware.
Page | 118
For example, when you move joystick widget, commands are streamed to the hardware,
during a single joystick move you can send dozens of commands. There are use-cases where
it’s needed, however creating such a load may lead to hardware overload and reset. Send
On Release is a recommended setting for majority of applications. This is also a default
setting.
Write interval
Similar to “Send on Release” option. However, it allows you to stream values to your
hardware within certain interval. For example, setting write interval to 100 ms means that
while you move the slider, only 1 value will be sent to hardware within 100 ms period. This
option is also used to optimize data traffic flow to your hardware.
Color gradient
When you choose gradient, it affects the color of widget elements based on invoming
values. For example: You set Gauge Widget with Min and Max parameters of 0-100, and
choose green-yellow-red gradient. When hardware sends: - 10, Gauge will change it’s color
to green color - 50 will change Gauge to yellow color - 80 will change Gauge to red color
There are 2 types of gradients you can choose from: - Warm: Green - Orange - Red; - Cold:
Green - Blue - Violet;
Controllers
Button
Works in push or switch modes. Allows to send ON and OFF
(LOW/HIGH) values. Button sends 1 (HIGH) on press and sends 0
(LOW) on release.
Sketch:BlynkBlink
Slider
Similar to potentiometer. Allows to send
values between in a given MIN/MAX range.
Sketch:BlynkBlink
Page | 119
Timer
Timer triggers actions at a specified time. Even if smartphone and
app is offline. Start time sends 1 (HIGH). Stop time sends 0 (LOW).
NOTE: The timer widget rely on the server time and not your phone time. Sometimes the
phone time may not match the server time.
Sketch:Timer
Joystick
Control servo movements in 4 directions
Settings:
• SPLIT/MERGE modes - read here
• Rotate on Tilt
When it’s ON, Joystck will automatically rotate if you use your smartphone in landscape
orientation
- Auto-Return - When it’s OFF, Joystick handle will not
return back to center position. It will stay where you left
it.
Sketch:JoystickTwoAxis
zeRGBa
zeRGBa is a usual RGB color picker + brightness picker
Settings:
• SPLIT: Each of the parameters is sent directly to the Pin on
your hardware (e.g D7). You don’t need to write any code.
Page | 120
NOTE: In this mode you send multiple commands from one widget, which can reduce
performance of your hardware.
Example: If you have a zeRGBa Widget and it’s set to D1, D2, D3 it will send 3 commands
over the Internet:
digitalWrite(, r);
digitalWrite(, g);
digitalWrite(, b);
• MERGE: When MERGE mode is selected, you send 1 message with an array of values
inside. You would need to parse the message on the hardware.
Example: Add a zeRGBa Widget and set it to MERGE mode. Choose Virtual Pin V1.
BLYNK_WRITE(V) // zeRGBa assigned to V
{
// get a RED channel value
int r = param[].asInt();
// get a GREEN channel value
int g = param[].asInt();
// get a BLUE channel value
int b = param[].asInt();
}
Step Control
Step Control is used to set granular values with a given step
2 buttons are assigned to 1 pin. One button increments the value, another one decrements
it.
Send Step option allows you to send step value to hardware instead of actual value of step
widget. Loop value option allows you to reset step widget to start value when maximum
value is reached.
Sketch: Basic Sketch
Page | 121
Displays
Value Display
Displays incoming data.
Sketch:BlynkBlink
Labeled Value
Displays incoming data in a formatted wayt. It is a
better version of ‘Value Display’ where you can add
suffixes and prefixes on the app side, with no coding
on the hardware.
Sketch: BlynkBlink
Formatting options
For example: your sensor sends vaule of 12.6789 to Blynk application.
Next formatting options are supported:
/pin/ - displays the value without formatting (12.6789)
/pin./ - displays the rounded value without decimal part (13)
/pin.#/ - displays the value with 1 decimal digit (12.7)
/pin.##/ - displays the value with two decimal places (12.68)
LED
A simple LED for indication. You need to send 0 in order to turn LED off. And
255 in order to turn LED on. Or just use Blynk API as described below:
WidgetLED led(V); //register to virtual pin
led.off();
led.on();
Page | 122
Gauge
Visual display of numeric values.
Sketch: BlynkBlink
Formatting options
For example: your sensor sends vaule of 12.6789 to Blynk
application. Next formatting options are supported:
/pin/ - displays the value without formatting (12.6789)
/pin./ - displays the rounded value without decimal part (13)
/pin.#/ - displays the value with 1 decimal digit (12.7)
/pin.##/ - displays the value with two decimal places (12.68)
LCD
This is a regular 16x2 LCD display made in our secret facility in
China.
lcd.clear();
Formatting options
For example: your sensor sends vaule of 12.6789 to Blynk
application. Next formatting options are supported:
/pin/ - displays the value without formatting (12.6789)
/pin./ - displays the rounded value without decimal part (13)
/pin.#/ - displays the value with 1 decimal digit (12.7)
/pin.##/ - displays the value with two decimal places (12.68)
Page | 123
SuperChart
SuperChart is used to visualise live and historical data.
You can use it for sensor data, for binary event logging
and more.
Interactions:
• Switch between time ranges and Live mode
Tap time ranges at the bottom of the widget to
change time ranges
• Tap Legend Elements to show or hide
datastreams
• Tap’n’hold to view timestamp and
corresponding values
Then you can then scroll data back and forward within the
given time range.
• Full Screen Mode
Press this button to open Full Screen view in
landscape orientation:
Page | 124
SuperChart Settings:
• Chart Title
• Title Font Size You have a choice of 3 font
sizes
• Title Alignment Choose chart title alignment.
This setting also affects Title and Legend
position on the Widget.
• Show x-axis (time) Select it if you want to
show the time label at the bottom of your
chart.
• Time ranges picker Allows you to select required periods (15m, 30m, 1h, 3h, …) and
resolution for your chart. Resolution defines how precise your data is. Right now
chart supports 2 types of resolution standard and high. Resolution also depends on the
selected period. For example, standard resolution for 1dmeans you’ll get 24 points per
day (1 per hour), with high resolution you’ll get for 1d 1440 points per day (1 per
minute).
• Datastreams - add datastreams (read below how to configure datastreams)
Datastream Settings
Widget supports up to 4 Datastreams. Press Datastream Settings Icon to open Datastream
Settings.
Page | 125
To use Tags:
• Add Tag to every device you want to aggregate data from.
• Push data to the same Virtual Pin on every device. (e.g. Blynk.virtualWrite (V0,
temperature);)
• Choose Tag as a source in SuperChart Widget and use the pin where the data is
coming to (e.g V0)
Functions available:
• SUM, will summarize all incoming values to the specified Virtual Pin across all
devices tagged with the chosen tag
• AVG, will plot average value
• MED, will find a median value
• MIN, will plot minimum value
• MAX will plot maximum value
1. Device Selector If you add Device Selector Widget to your project, you can use it as a
source for SuperChart. In this case, when you change the device in Device Selector,
chart will be updated accordingly
Y-Axis Settings
There are 4 modes of how to scale data along the Y axis
1. Auto
Data will be auto-scaled based on min and max
values of the given time period. This is nice
option to start with.
2. Values
When this mode is selected, Y scale will
be set to the values you choose. For
example, if your hardware sends data
with values varying from -100 to 100, you can set
the chart to this values and data will be rendered
correctly.
Page | 126
You may also want to visualize the data within some specific range. Let’s say incoming data
has values in the range of 0-55, but you would like to see only values in the range 30-50.
You can set it up and if values are out of Y scale you configured, chart will be cropped
1. % of Height
This option allows you to auto-scale incoming
data on the widget and position it the way
you want. In this mode, you set up the
percentage of widget height on the screen,
from 0% to 100%.
Height:
This setting is very valuable for Binary Chart or
for visualizing a few datastreams on the same
chart in a different way.
1. Delta
While data stays within the given Delta value, chart will be auto-scaled within this
range. If delta exceeds the range, chart will be auto-scaled to min/max values of the
given period.
Suffix:
Here you can specify a suffix that will be shown during the Tap’n’hold
Page | 127
Decimals
Defines the formatting of the graph value when you Tap’n’hold the graph. Possible options
are: #, #.#, #.##, etc.
You need to specify a FLIP point, which is the point where incoming data will be turned into
TRUE or FALSE state.
For example, you send the data in the range of 0 to 1023. If you set 512 as a FLIPpoint, then
everything above 512 (excluding 512) will be recorded as TRUE, any value below 512 (including
512) will be FALSE.
Another example, if you send 0 and 1 and set 0 as a FLIP point, then 1 will be TRUE, 0 will
be FALSE
Page | 128
State Labels:
Here you can specify how TRUE/FALSE should be shown in Tap’n’Hold mode.
For example, you can set to TRUE to “Equipment ON” label, FALSE to “Equipment OFF”.
This means that minimum chart update interval is 1 minute for 1h, 6h, 1d periods. 1 hour
for 1w, 1m and 3m periods. As Blynk Cloud is free to use we have a limit on how many data
you can store. At the moment Blynk Cloud accepts 1 message per minute per pin. In case
you send your data more frequently your values will be averaged. For example, in case you
send value 10 at 12:12:05 and than again 12 at 12:12:45 as result in chart you’ll see
value 11 for 12:12.
In order to see data in chart you need to use either widgets with “Frequency reading” interval
(in that case your app should be open and running) or you can use Blynk.virtualWrite on
hardware side. Every Blynk.virtualWrite command is stored on server automatically. In that case
you don’t need application to be up and running.
Terminal
Displays data from your hardware. Allows to send any string to your hardware. Terminal
always stores last 25 messages your hardware had send to Blynk Cloud. This limit may be
increased on Local Server with terminal.strings.pool.sizeproperty.
Page | 129
terminal.print(); // Print values, like Serial.print
terminal.println(); // Print values, like Serial.println()
terminal.write(); // Write a raw data buffer
terminal.flush(); // Ensure that data was sent out of device
terminal.clear(); // Erase all values in the terminal
Sketch:Terminal
Video Streaming
Simple widget that allows you to display any live stream. Widget
supports RTSP (RP, SDP), HTTP/S progressive streaming, HTTP/S
live streaming. For more info please follow official Android
documentation.
Every message that hardware sends to server is stored automatically on server. PUSH mode
doesn’t require application to be online or opened.
Sketch: Push Example
Notifications
Twitter
Twitter widget connects your Twitter account to Blynk and allows you to send
Tweets from your hardware.
Example code:
Blynk.tweet("Hey, Blynkers! My Arduino can tweet now!");
Page | 130
Limitations:
• you cant’ send 2 tweets with same message (it’s Twitter policy)
• only 1 tweet per 5 seconds is allowed
Sketch: Twitter
Email
Email widget allows you to send email from your hardware to any address.
Example code:
Blynk.email("[email protected]", "Subject", "Your message goes here");
It also contains to field. With this field you may define receiver of email in the app. You may
skip to field when you want to send email to your Blynk app login email:
Blynk.email("Subject", "Your message goes here");
You can send either text/html or text/plain (some clients don’t support text/html) email. You can
change this content type of email in the Mail widget settings.
Additionally you may use {DEVICE_NAME}, {DEVICE_OWNER_EMAIL} and {VENDOR_EMAIL}(for the local
server) placeholders in the mail for the to, subject and body fields:
Blynk.email("{DEVICE_OWNER_EMAIL}", "{DEVICE_NAME} : Alarm",
"Your {DEVICE_NAME} has critical error!");
Limitations:
• Maximum allowed email + subject + message length is 120 symbols. However you
can increase this limit if necessary by adding #define BLYNK_MAX_SENDBYTES XXX to
you sketch. Where XXX is desired max length of your email. For example for ESP you
can set this to 1200 max length #define BLYNK_MAX_SENDBYTES 1200. The #define
BLYNK_MAX_SENDBYTES 1200 must be included before any of the Blynk includes.
• Only 1 email per 5 seconds is allowed
• In case you are using gmail on the Local Server you are limited with 500 mails per
day (by google). Other providers may have similar limitations, so please be careful.
• User is limited with 100 messages per day in the Blynk Cloud;
Sketch: Email
Page | 131
Push Notifications
Push Notification widget allows you to send push notification from your hardware to your
device. Currently it also contains 2 additional options:
• Notify when hardware offline - you will get push notification in case your hardware
went offline.
• Offline Ignore Period - defines how long hardware could be offline (after it went
offline) before sending notification. In case period is exceeded - “hardware offline”
notification will be send. You will get no notification in case hardware
was reconnected within specified period.
• Priority high priority gives more chances that your message will be
delivered without any delays. See detailed explanation here.
WARNING: high priority contributes more to battery drain compared to
normal priority messages.
Example code:
Blynk.notify("Hey, Blynkers! My hardware can push now!");
You can also use placeholder for device name, that will be replaced on the server with your
device name:
Blynk.notify("Hey, Blynkers! My {DEVICE_NAME} can push now!");
Limitations:
• Maximum allowed body length is 120 symbols;
• Every device can send only 1 notification every 5 seconds;
Sketch: PushNotification
Page | 132
Interface
Tabs
The only purpose of Tabs widget is to extend your project space.
You can have up to 4 tabs. Also you can drag widgets between
tabs. Just drag widget on the label of required tab of tabs widget.
Menu
Menu widget allows you to send
command to your hardware based on
selection you made on UI. Menu sends
index of element you selected and not
label string. Sending index is starts
from 1. It works same way as usual
ComboBox element. You can also set
Menu items from hardware side.
Example code:
switch (param.asInt())
{
case 1: { // Item 1
Serial.println("Item 1 selected");
break;
}
case 2: { // Item 2
Serial.println("Item 2 selected");
break;
}
}
Sketch: Menu
Time Input
Time input widget allows you to select start/stop time, day of week, timezone, sunrise/sunset
formatted values and send them to your hardware. Supported formats for time now
are HH:MM and HH:MM AM/PM.
Page | 133
Hardware will get selected on UI time as seconds of day (3600 * hours + 60 * minutes) for start/stop
time. Time that widget sends to hardware is user local time. Selected days indexes:
Monday - 1
Tuesday - 2
...
Saturday - 6
Sundays - 7
You can also change state of widget on UI. See below sketches.
Sketch: Simple Time Input for start time
Sketch: Advanced Time Input
Sketch: Update Time Input State on UI
Map
Map widget allows you set points/pins on map from hardware side. This is very useful widget
in case you have multiple devices and you want track their values on map.
You can send a point to map with regular virtual wrtei command:
Blynk.virtualWrite(V, pointIndex, lat, lon, "value");
We also created wrapper for you to make suage of map simpler:
You can change button labels from hardware with:
WidgetMap myMap(V);
...
int index = ;
float lat = ;
float lon = ;
myMap.location(index, lat, lon, "value");
Using save index allows you to override existing point value.
Sketch: Basic Sketch
Table
Table widget comes handy when you need to structure similar data within 1 graphical
element. It works as a usual table.
You can add a row to the table with:
Blynk.virtualWrite(V1, "add", id, "Name", "Value");
You can update a row in the table with:
Page | 134
Blynk.virtualWrite(V1, "update", id, "UpdatedName", "UpdatedValue");
To highlight any item in a table by using it’s id in a table:
Blynk.virtualWrite(V1, "pick", 0);
To select/deselect (make icon green/grey) item in a table by using it’s row id in a table:
Blynk.virtualWrite(V1, "select", 0);
Blynk.virtualWrite(V1, "deselect", 0);
To clear the table at any time with:
Blynk.virtualWrite(V1, "clr");
You can also handle other actions coming from table. For example, use row as a switch
button.
BLYNK_WRITE(V1) {
String cmd = param[0].asStr();
if (cmd == "select") {
//row in table was selected.
int rowId = param[1].asInt();
}
if (cmd == "deselect") {
//row in table was deselected.
int rowId = param[1].asInt();
}
if (cmd == "order") {
//rows in table where reodered
int oldRowIndex = param[1].asInt();
int newRowIndex = param[2].asInt();
}
}
Note: Max number of rows in the table is 100. When you reach the limit, table will work as
FIFO (First In First Out) list. This limit can be changed by configuring table.rows.pool.size property
for Local Server.
Sketch: Simple Table usage
Sketch: Advanced Table usage
Page | 135
Device Selector
Device selector is a powerful widget which allows you to update widgets based on one active
device. This widget is particlularly helpful when you have a fleet of devices with similar
functionality.
Imagine you have 4 devices and every device has a Temperature & Humidity sensor
connected to it. To display the data for all 4 devices you would need to add 8 widgets.
With Device Selector, you can use only 2 Widgets which will display Temperature and
Humidity based on the active device chosen in Device Selector.
All you have to do is:
1. Add Device Selector Widget to the project
2. Add 2 widgets (for example Value Display Widget) to show Temperature and
Humidity
3. In Widgets Settings you will be able assign them to Device Selector (Source or
Target section)
4. Exit settings, Run the project.
Now you can change the active device in Device Selector and you will see that Temperature
and Humidity values are reflecting the data updates for the device you just picked.
NOTE: Webhook Widget will not work with Device Selector (yet).
Device Tiles
Device tiles is a powerful widget and very similar to the device selector widget, but with UI.
It allows you to display 1 pin per device per tile. This widget is particularly helpful when you
have a fleet of devices with similar functionality. So you can group similar devices within one
layout (template).
Sensors
Accelerometer
Accelerometer is kind of motion sensors that allows you to detect motion of your
smartphone. Useful for monitoring device movement, such as tilt, shake, rotation, or swing.
Conceptually, an acceleration sensor determines the acceleration that is applied to a device
by measuring the forces that are applied to the sensor. Measured in m/s^2 applied
to x, y, z axis.
Page | 136
In order to accept data from it you need to:
BLYNK_WRITE(V) {
//acceleration force applied to axis x
int x = param[].asFloat();
//acceleration force applied to axis y
int y = param[].asFloat();
//acceleration force applied to axis y
int z = param[].asFloat();
}
Accelerometer doesn’t work in background.
Barometer/pressure
Barometer/pressure is kind of environment sensors that allows you to measure the ambient
air pressure.
Gravity
Gravity is kind of motion sensors that allows you to detect motion of your smartphone. Useful
for monitoring device movement, such as tilt, shake, rotation, or swing.
The gravity sensor provides a three dimensional vector indicating the direction and
magnitude of gravity. Measured in m/s^2 of gravity force applied to x, y, z axis.
In oder to accept data from it you need to:
BLYNK_WRITE(V) {
//force of gravity applied to axis x
int x = param[].asFloat();
//force of gravity applied to axis y
int y = param[].asFloat();
//force of gravity applied to axis y
Page | 137
int z = param[].asFloat();
}
Gravity doesn’t work in background.
Humidity
Humidity is kind of environment sensors that allows you to measure ambient relative
humidity.
Measured in % - actual relative humidity in percent.
In oder to accept data from it you need to:
BLYNK_WRITE(V) {
// humidity in %
int humidity = param.asInt();
}
Humidity doesn’t work in background.
Light
Light is kind of environment sensors that allows you to measure level of light (measures the
ambient light level (illumination) in lx). In phones it is used to control screen brightness.
In order to accept data from it you need to:
BLYNK_WRITE(V) {
//light value
int lx = param.asInt();
}
Light doesn’t work in background.
Proximity
Proximity is kind of position sensors that allows you to determine how close the face of a
smartphone is to an object. Measured in cm - distance from phone face to object. However
most of this sensors returns only FAR / NEAR information. So return value will be 0/1. Where
0/LOW is FAR and 1/HIGH is NEAR.
Temperature
Temperature is kind of environment sensors that allows you to measure ambient air
temperature. Measured in °C - celcius.
GPS Trigger
GPS trigger widget allows easily trigger events when you arrive to or leave from some
destination. This widget will work in background and periodically will check your
coordinates. In case your location is within/out required radius (selected on widget map)
widget will send HIGH/LOW command to hardware. For example, let’s assume you have GPS
Trigger widget assigned to pin V1 and option Trigger When Enter. In that case when you’ll arrive
to destination point widget will trigger HIGHevent.
BLYNK_WRITE(V) {
int state = param.asInt();
if (state) {
//You enter destination
} else {
//You leave destination
}
}
More details on how GPS widget works you can read here.
GPS trigger widget works in background.
Page | 139
GPS Streaming
Useful for monitoring smartphone location data such as latitude, longitude, altitude and
speed (speed could be often 0 in case smartphone doesn’t support it).
Serial.println(gps.getAltitude(), );
Serial.println(gps.getSpeed(), );
}
GPS Streaming works in background.
Sketch: GPS Stream
Other
Bridge
Bridge can be used for Device-to-Device communication (no app. involved). You
can send digital/analog/virtual write commands from one device to another,
knowing it’s auth token. At the moment Bridge widget is not required on
application side (it is mostly used for indication that we have such feature).
Page | 140
Bridge widget takes a virtual pin, and turns it into a channel to control another device. It
means you can control any virtual, digital or analog pins of the target device. Be careful not
to use pins like A0, A1, A2 ... when communicating between different device types, as Arduino
Core may refer to wrong pins in such cases.
BLYNK_CONNECTED() {
bridge.setAuthToken("OtherAuthToken"); // Token of the hardware B
}
IMPORTANT: when performing virtualWrite() with Bridge Widget, Device B would need to
process the incoming data from Device A. For example, if you are sending value from Device
A to Device B using bridge.virtualWrite(V5) you would need to use this handler on Device B:
BLYNK_WRITE(V){
int pinData = param.asInt(); //pinData variable will store value that came via
Bridge
}
Keep in mind that bridge.virtualWrite doesn’t send any value to mobile app. You need to
call Blynk.virtualWrite for that.
Sketch: Bridge
Page | 141
Eventor
Eventor widget allows you to create simple behaviour rules or events. Let’s look at a typical
use case: read temperature from DHT sensor and send push notification when the
temperature is over a certain limit:
float t = dht.readTemperature();
if (isnan(t)) {
return;
}
if (t > ) {
Blynk.notify(String("Temperature is too high: ") + t);
}
With Eventor you don’t need to write this code. All you need is to
send the value from the sensor to the server:
float t = dht.readTemperature();
Blynk.virtualWrite(V, t);
Don’t forget that virtualWrite commands should be wrapped in the
timer and can’t be used in the main loop.
Eventor comes handy when you need to change conditions on the fly without re-uploading
new sketch on the hardware. You can create as many events as you need. Eventor also could
be triggered from the application side. You just need to assign the widget to the same pin
as your Event within Eventor. Eventor doesn’t constantly sends events. Let’s consider simple
event as above if (temperature > 40) send notification. When temperature goes beyond 40 threshold
- notification action is triggered. If temperature continues to stay above the 40 threshold no
actions will be triggered. But if temperature goes below threshold and then passes it again -
notification will be sent again (there is no 5 sec limit on Eventor notifications).
Eventor also supports Timer events. For example, you can set a pin V1 ON/HIGH at 21:00:00
every Friday. With Eventor Time Event you can assign multiple timers on same pin, send any
string/number, select days and timezone.
Page | 142
In order to remove created event please use swipe. You can also
swipe out last element in the Event itself.
NOTE: The timer widget rely on the server time and not your phone
time. Sometimes the phone time may not match the server
time. NOTE: Events are triggered only once when the condition is
met. That’s mean chaining of events is not possible (however, could
be enabled for commercials).
Sketch: Eventor
NOTE:: Events are triggered only once when the condition is met.
Exception: Let’s consider simple event as above if (temperature > 40) send
notification. When temperature goes beyond 40 threshold - notification
action is triggered. If temperature continues to stay above the 40
threshold no actions will be triggered. But if temperature goes below
threshold and then passes it again - notification will be sent again
(there is no 5 sec limit on Eventor notifications).
RTC
Real-time clock allows you to get time from server. You can preselect
any timezone on UI to get time on hardware in required locale. No
pin required for RTC widget.
Sketch: RTC
BLE
Widget to enable Bluetooth Low Energy support. At the moment BLE widget requires
internet connection in order to login and load your profile. However this will be fixed soon.
Also some Blynk widgets are not supported within the BLE connection.
Blynk currently supports a handful of different BLE modules. Please check sketches below.
Sketches: BLE
Bluetooth
Widget to enable Bluetooth support. At the moment Bluetooth widget is supported only on
Android and requires internet connection to login and to load your profile. This will be fixed
soon. Alsom some Blynk widgets do not work within the Bluetooth connection.
Blynk currently supports bunch of different modules. Please check sketches below.
Sketches: Bluetooth
Page | 143
Music Player
Simple UI element with 3 buttons with common music player controls. Every button sends
it’s own command to hardware: play, stop, prev, next.
You can change widget state within the app from hardware side with next commands:
Blynk.virtualWrite(Vx, “play”);
Blynk.virtualWrite(Vx, “stop”);
You can also change widget play/stop state with next code (equivalent to above commands):
Blynk.setProperty(V1, "isOnPlay", "false");
Sketch: Music Player
Webhook
Webhook is a widget designed to communicate with 3rd party services.
With Webhook widget you can send HTTP(S) requests to any 3rd party
service or device that has HTTP(S) API (e.g. Philips Hue bulb). You can
trigger 3-d party service with a single click of a button.
Any write operation from hardware side will trigger Webhook Widget.
You can also trigger webhook from Blynk app when a app widget is
assigned to the same pin as Webhook.
For example, when you need to send data from your hardware not only
to Blynk, but also to Thingspeak, you would need to write a long http
request code like this (this is just an example, not a full sketch):
WiFiClient client;
if (client.connect("api.thingspeak.com", 80)) {
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKeyThingspeak1 + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Page | 144
}
Instead, with Webhook widget you would only need to fill in these fields:
Use standard Blynk placeholders for Pin Value in the body or URL, for example:
https://api.thingspeak.com/update?api_key=xxxxxx&field1=/pin/
or for the body
["/pin/"]
When you need to send an array of values, you can refer to a specific index of the array
value. Blynk Pin can hold an array of max 10 values:
/pin[0]/,/pin[1]/, /pin[2]/
You can also make GET requests from Blynk Server and get responses directly to your
hardware.
For example, to get current weather from a 3rd party Weather service that uses an URL
similar to this: http://api.sunrise-sunset.org/json?lat=33.3823&lng=35.1856&date=2016-10-01, you would need
to put this URL in Webhook widget and assign it to V0 pin.
NOTE: Usually, 3rd party servers return long responses. You have to increase the maximum
allowed message size your hardware can process. Modify this line in your firmware code:
#define BLYNK_MAX_READBYTES 1024. Where 1024 - is maximum allowed message size.
Page | 145
NOTE: Blynk Cloud has limitation for Webhook Widget - you can only send 1 request per
second. This can be changed on a Local Server by changing webhooks.frequency.user.quota.limit. Be
careful with Webhooks, as many 3rd party services can’t handle 1 req/sec, and you can be
banned on some of them. For example, Thingspeak allows only 1 request per 15 seconds.
NOTE: To avoid spamming, Blynk Webhook feature has another limitation - if your
Webhook requests fail 10 times in a row, Webhook Widget will be stopped. To resume it,
you would need to open Widget Settings and re-save it. Failed request is a request that
doesn’t return 200 or 302.
NOTE: Webhook widget may affect Blynk.syncAll() function when a returned response is large.
Reports Widget
Function of Reports is to configure and customize data reports in CSV format. You can
choose between one-time or continuous scheduled reports.
Also, within the Reports you can clear all the data collected by your devices.
You need to configure initial inputs in Edit mode, and then, in Play mode you will be able to
customize reports.
If you don’t use Device Tiles you can still select a single device or a group of devices as a
source of data for reports.
You have to choose either Device Tiles or single / group of the devices for the report. You
can’t combine these 2 options.
Play mode.
After you added source devices and their Datastreams click Play button and click on the
Reports button.
Customizing Reports.
Every Report option supposes it’s own settings:
Report name - give your report a meaningful name.
Data source - select the Datastreams you would like to be included in reports.
Page | 146
- Defines how often reports will be sent. They can be one-time and
Report Frequency
scheduled. one-time - will instantly generate report and send it to the email addresses
specified. Click on the right icon to send it.
will set up a time of the day the report will be sent. Start/End specifies start and end
At Time
date the reports will continue to be sent.
For Weekly Report you can select a day of the week when report should be sent. For Monthly
report you can choose whether to send report on the first or last day of the month.
• Recipients - specify up to 5 email addresses.
• Data resolution defines granularity of your reports. Supported granularities
are: minute, hourly and daily. For example, when you generate daily report with 1 minute
granularity you’ll get 24 * 60 * 60 points in your daily report for every selected
Datastream.
• Group data in reports by - specify the output format of the CSV file(s).
• Datastream you will get 1 CSV file for each Datastream.
• Device you will get 1 CSV file per each device. Each file will contain all of the included
Datastreams.
• Report you will get 1 CSV file for all your devices and all your Datastreams.
• Timezone correction - specify the time zone adjustment if you need to get report date and
time adjusted to a specific time zone
• Date and time format - defines the format of the timestamp field of your data. You can
select 2018-06-21 20:16:48, 2018-06-21T20:16:48+03:00 or other supported formats.
There is one specific Timestamp format - which reflects the difference between the current time
and midnight, January 1, 1970 UTC measured in milliseconds.
After the report is set up - click on “OK” button at the right upper corner. Your report is
ready.
Once you configured the report you will see when is the Next report scheduled and also a
schedule for this report.
After the report was sent at least once, you can see when the Last report was sent.
Last label also contains the status regarding the report:
Page | 147
• OK: the report was generated and sent to the Recipients successfully;
• No Data: the report doesn’t contain any data for the configured period;
• Error: something went wrong. Please contact the Blynk Team support;
Reports will be generated even if your project is not in active (Play) mode. However, inactive
projects don’t generate any data.
NOTE: all reports are encoded in UTF-16. Please, make sure you selected UTF-16 as required
“Character set” for your csv reader.
Sharing
Blynk offers two types of sharing your projects with other people:
• Share access to your hardware. Think about giving
someone an App for your Project. They can’t modify, but can
control and see what’s there.
• Share your Project configuration. Others will get a clone of
your project by scanning a given QR link, but they won’t be
able to control your hardware. It’s great for tutorials,
instructables, etc.
How it works: - you send the QR code to your users (you can email,
print, post to social media, do whatever you want) - others download
Blynk app, scan the QR code and your app opens for them ready to
use. They don’t even need to login or create an account.
Page | 149
API description can be found here. Warning: Blynk HTTP API still has GEO DNS issue. This
means, for now you need to use direct server IP instead of hostname in order to make it
work with 3-d party services like IFTTT.
Supported Hardware
Blynk supports more than 400 boards already, including support for Arduino, Particle, ARM
mbed, TI Energia, MicroPython, Node.js, OpenWRT and many Single Board Computers. You
can add your own connection types easily (see these examples for Arduino)!
Platforms
• Arduino (https://github.com/blynkkk/blynk-library)
• Arduino MKR WiFi 1010
• Arduino MKR GSM 1400
• Arduino Uno, Duemilanove
• Arduino Nano, Mini, Pro Mini, Pro Micro, Due, Mega
• Arduino 101 (Intel Curie, with BLE)
• Arduino MKR1000
• Arduino Zero
• Arduino Yún (onboard WiFi and Ethernet, via Bridge)
• Arduino.org UNO WiFi
• Arduino MKR VIDOR 4000 (use the example for MKR WiFi 1010)
• Arduino UNO WiFi Rev.2 (use the example for MKR WiFi 1010)
• Arduino-like
• Blynk Board
• ESP8266 (Generic, NodeMCU, Witty Cloud, Huzzah, WeMos D1, Seeed Wio Link, etc.)
• ESP32 (WiFi, BLE)
• Nordic nRF51/nRF52 - based boards
• Teensy 3.2/3.1
• Blue Pill (STM32F103C)
• Realtek RTL8710 / Ameba via RTLduino
• BBC micro:bit
• LightBlue Bean , soon
• DFRobot Bluno
• RedBear Duo (WiFi, BLE)
• RedBearLab Blend Micro
• RedBearLab BLE Nano (v1 and v2)
• Seeed Tiny BLE
Page | 150
• Simblee BLE
• RFduino BLE
• The AirBoard (BLE-Link, RN-XV)
• Feather M0 WiFi
• Feather 32u4 BLE
• Intel Edison
• Intel Galileo
• Fishino Guppy, Uno, Mega
• TinyCircuits TinyDuino (CC3000)
• Microduino/mCookie Core, Core+, CoreUSB
• Wicked WildFire V2, V3, V4
• Digistump Oak
• chipKIT Uno32
• Alorium XLR8 (FPGA)
• LinkIt ONE (WiFi only)
• Energia
• Texas Instruments
• CC3220SF-LaunchXL
• CC3200-LaunchXL
• Tiva C Connected LaunchPad
• Stellaris LM4F120 LaunchPad
• MSP430F5529 + CC3100
• LaunchPad MSP432
• RedBearLab (CC3200, WiFi Mini)
• Particle https://github.com/vshymanskyy/blynk-library-spark)
• Photon
• Electron
• SparkFun RedBoard
• RedBear Duo (WiFi & BLE)
• ARM mbed (https://developer.mbed.org/users/vshymanskyy/code/Blynk/)
• Seeed Tiny BLE
• RedBearLab BLE Nano
• BBC micro:bit
• STM32 Nucleo + Wiznet 5100 , soon
• JavaScript (Node.js, Espruino, Browsers) (https://www.npmjs.com/package/blynk-library)
• Regular PC with Linux / Windows / OS X
• Raspberry Pi (Banana Pi, Orange Pi, …)
Page | 151
• BeagleBone Black
• Onion Omega
• Onion Omega 2
• Intel Galileo
• Intel Edison
• Intel Joule
• LeMaker Guitar
• LeMaker Banana Pro
• Samsung ARTIK 5
• PandaBoard, CubieBoard, pcDuino, Tessel 2
• VoCore, VoCore2 (OpenWRT + Espruino package)
• Espruino Pico
• Python (https://github.com/vshymanskyy/blynk-library-python)
• MicroPython
• Python 2
• Python 3
• Lua (https://github.com/blezek/blynk-esp)
• NodeMCU
Made by Community
• Marvell® EZ-Connect™ MW300/MW302
• WIZnet-W5500-EVB
• LabVIEW
• Node-RED (can be used as bridge to HTTP, TCP, UDP, MQTT, XMPP, IRC, OSC…)
Problematic Boards
These boards are not supported and do not work out of the box: - Arduino Tian
Here is a list of known library issues
Troubleshooting
Connection
If you experience connection problems, follow these steps:
1. Check that your hardware, wires, cables and power supply are good quality, not harmed
or damaged, etc.
Use high power USB cables and USB ports.
2. Check your wiring using the examples (TCP/HTTP Client or similar) provided with your
shield and hardware.
• Once you understand how to manage connection, it’s much easier to use Blynk.
3. Try running command telnet blynk-cloud.com 80 from your PC, connected to the same
network as your hardware. You should see something like: Connected to blynk-cloud.com..
4. Try running Blynk default examples for your platform without modificationsto see if it
is working.
Page | 153
• Double-check that you have selected the right example for your connection type
and hardware model.
• Our examples come with comments and explanations. Read them carefully.
• Check that your Auth Token is valid (copied from the App and doesn’t contain
spaces, etc.)
• If it doesn’t work, try looking into serial debug prints.
5. Done! Add your modifications and functionality. Enjoy Blynk!
Note: when you have multiple devices connected to your network, they should all have
different MAC and IP addresses. For example, when using 2 Arduino UNO with Ethernet
shields, flashing default example to both of them will cause connection problems. You
should use manual ethernet configuration example.
Delay
If you use long delay() or send your hardware to sleep inside of the loop() expect connection
drops and downgraded performance.
DON’T DO THAT:
void loop()
{
...
delay(); // this is long delay, that should be avoided
other_long_operation();
...
Blynk.run();
}
Note: This also applies to the BLYNK_READ & BLYNK_WRITE handlers!
Page | 154
SOLUTION: If you need to perform actions in time intervals - use timers, for
example BlynkTimer.
Flood Error
If your code frequently sends a lot of requests to our server, your hardware will be
disconnected. Blynk App may show “Your hardware is offline”
When Blynk.virtualWrite is in the void loop, it generates hundreds of “writes” per second
Here is an example of what may cause flood. DON’T DO THAT:
void loop()
{
Blynk.virtualWrite(, value); // This line sends hundreds of messages to Blynk
server
Blynk.run();
}
SOLUTION: If you need to perform actions in time intervals - use timers, for
example BlynkTimer.
Using delay() will not solve the problem either. It may cause another issue. Use timers!
If sending hundreds of requests is what you need for your product you may increase flood
limit on local server and within Blynk library. For local server you need to
change user.message.quota.limit property within server.properties file :
#100 Req/sec rate limit per user.
user.message.quota.limit=100
For library you need to change BLYNK_MSG_LIMIT property within BlynkConfig.h file :
//Limit the amount of outgoing commands.
#define BLYNK_MSG_LIMIT 20
Enable debug
To enable debug prints on the default Serial, add this on the top of your sketch (it should
be the first line in your sketch):
#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial
And enable serial in void setup():
Page | 155
Serial.begin();
You can also use spare Hardware serial ports or SoftwareSerial for debug output (you will
need an adapter to connect to it with your PC).
Note: enabling debug mode will slow down your hardware processing speed up to 10 times.
Reset password
On login screen click on “Forgot password?” label and than type your email and Send button.
You’ll get instruction on your email.
Security
Blynk server has 5 ports open for different security levels.
• 80 - plain TCP connection for the hardware (no security)
• 8080 - plain TCP connection for hardware on the Local Server (no security)
• 443 - SSL/TLS connection for the Mobile Apps and hardware with SSL
• 9443 - SSL/TLS connection for the Mobile Apps on the Local Server and hardware
with SSL
Hardware may select to connect to 443 (9443) or 80 (8080), depending on it’s capabilities.
Connection between the app and the server is always is done through SSL/TLS, so it is always
secured. Connection between the hardware and server depends on your hardware
Page | 156
capabilities. With the Local Blynk server connection type between the hardware and server
is not that important for the security as the Local server is usually placed within the local
network, so attacker can’t intercept traffic between hardware and the server.
In case of Local Blynk Server there is also no need to protect connection between your
hardware and Local Blynk Server. This is true for Ethernet connection and partially true for
Wi-Fi connection. In case of Wi-Fi you have to use at least WPA, WPA2 (Wi-Fi Protected
Access) Wi-Fi type in order to protect wireless traffic.
WPA and WPA2 offer a very robust encryption that is likely to protect all data travelling over
the air—given that a strong enough password is used. Even if your data is plain TCP/IP,
another user won’t be able to decipher captured packets. Still, make sure that your password
is strong enough, otherwise the only limiting factor for an attacker is time.
This will forward all hardware connections from 9443 port to the server via SSL gateway. You
can run this script on your Raspberry Pi, desktop computer, or even directly on your router!
Note: when using your own server, you should overwrite the bundled server.crt certificate,
or specify it to the script using --cert switch:
./blynk-ser.sh -f SSL -s <server ip> -p --cert=<certificate>.crt
Flag -f SSL is enabled by default for USB communication so you don’t have to explicit declare
it.
Page | 157
OTA
Blynk also supports over the air updates for - ESP8266, NodeMCU and SparkFun Blynk
boards. OTA supported only for the private servers and for the paid customers for now.
Page | 158
Trigger OTA for all devices
Update for all devices will be triggered only when they are connected to the cloud. You need
to remove the token part for that.
curl -v -F file=@Template_ESP8266.ino.nodemcu.bin --insecure -u
[email protected]:admin https://localhost:9443/admin/ota/start
In that case, OTA will be triggered right after device connected to the server. In case device
is online firmware update will be initiated only when device will be connected again.
NOTE: ESP8266 right now takes firmware only via HTTP. And not HTTPS.
Blynk server
Blynk Server is an Open Source Java server, responsible for forwarding messages between
Blynk mobile application and various microcontroller boards (i.e. Arduino, Raspberry Pi. etc).
Download latest server build:
Page | 159
Why do I need Local Blynk Server?
• Better security. You are the only one who knows about the server. You can setup
security policies tied to your specific needs (MAC, IPs, login names, etc). You can also
make it accessible only within your private network.
• Better stability. No need to rely on 3rd party Cloud solution. You have the full
control.
• Lower latency. Server is as close to you as it could be.
• Maximum privacy. All data is stored locally and is not shared with anyone.
Blynk Firmware
Configuration
Blynk.begin()
The easiest way to configure Blynk is to use Blynk.begin():
Blynk.begin(auth, ...);
It has multiple parameters for different hardware models and it also depends on the type of
connection. Follow the example sketches for your specific hardware model.
Blynk.config()
allows you to manage network connection. You can set up your connection type (WiFi,
config()
Ethernet, …) by yourself, and then call:
Blynk.config(auth, server, port);
or just
Blynk.config(auth);
NOTE: After Blynk.config(...) is called, your hardware is not yet connected to the server. It will
try to connect while until it hits first instance of Blynk.run() or Blynk.connect()routine.
Page | 160
To skip connecting to the server or to disconnect manually, call Blynk.disconnect()after
configuration.
Use connectWiFi to conveniently set up WiFi connection:
Blynk.connectWiFi(ssid, pass);
To connect to open WiFi networks, set pass to an empty string ("").
Connection management
There are several functions to help with connection management:
Blynk.connect()
This functions will continue trying to connect to Blynk server. Returns true when
connected, false if timeout have been reached. Default timeout is 30 seconds.
bool result = Blynk.connect();
bool result = Blynk.connect(timeout);
Blynk.disconnect()
Disconnects hardware from Blynk server:
Blynk.disconnect();
Blynk.connected()
Returns true when hardware is connected to Blynk Server, false if there is no active connection
to Blynk server.
bool result = Blynk.connected();
Blynk.run()
This function should be called frequently to process incoming commands and perform
housekeeping of Blynk connection. It is usually called in void loop() {}.
This command can be initiated it in other places of your code unless you run out of heap
memory (in the cascaded functions with local memory).
For example, it is not recommended to call Blynk.run() inside of
the BLYNK_READand BLYNK_WRITE functions on low-RAM devices.
Page | 161
Digital & Analog pins control
Blynk library can perform basic pin IO (input-output) operations out-of-the-box:
digitalRead
digitalWrite
analogRead
analogWrite (PWM or Analog signal depending on the platform)
No need to write code for simple things like LED, Relay control and analog sensors. Just
choose a corresponding Pin in Blynk app and control it directly with no additional code
Virtual Pins are commonly used to interface with other libraries (Servo, LCD and others) and
implement custom logic. The device can send data to the App using
Blynk.virtualWrite(pin, value) and receive data from the App using BLYNK_WRITE(vPIN).
Read below
However, there are certian limitations on the hardware side when dealing with numbers. For
example, the integer on Arduino is 16-bit, allowing range -32768 to 32767.
Page | 162
Blynk.virtualWrite(vPin, value)
NOTE: Use BlynkTimer when you use this command to send data. Otherwise your
hardware will be disconnected from the server
Send data in various formats to Virtual Pins.
// Send string
Blynk.virtualWrite(pin, "abc");
// Send integer
Blynk.virtualWrite(pin, );
// Send float
Blynk.virtualWrite(pin, );
Note: For virtual pins with numbers > 127, the V128 syntax is not available.
Please use plain virtual pin number, for example:
Blynk.virtualWrite(, "abc");
BlynkTimer
It’s important to send data in intervals and keep the void loop() as clean as possible.
BlynkTimer allows you to send data periodically with given intervals not interfering with Blynk
library routines Blynk Timer inherits SimpleTimer Library, a well known and widely used library
to time multiple events on hardware. BlynkTimer is included in Blynk library by default and
there is no need to install SimpleTimer separately or include SimpleTimer.h
• A single BlynkTimer object allows to schedule up to 16 timers
• Improved compatibility with boards like Arduino 101, Intel Galileo, etc.
• When a timer struggles to run multiple times (due to a blocked loop), it just skips all
the missed intervals, and calls your function only once. This differs from SimpleTimer,
which could call your function multiple times in this scenario.
Page | 163
For more information on timer usage, please
see: http://playground.arduino.cc/Code/SimpleTimer
Please also remember that a single BlynkTimer can schedule many timers, so most probably
you need only one instance of BlynkTimer in your sketch.
BLYNK_WRITE(vPIN)
BLYNK_WRITE is a function called every time device gets an update of Virtual Pin value from
the server (or app):
BLYNK_READ(vPIN)
BLYNK_READ is function called when device is requested to send it’s current value of Virtual Pin
to the server. Normally, this function should contain Blynk.virtualWritecall(s).
BLYNK_READ(V)
{
Blynk.virtualWrite(V, newValue);
}
Note: For virtual pins with numbers > 127, please use BLYNK_READ_DEFAULT() API
BLYNK_WRITE_DEFAULT()
Redefines the handler for all pins that are not covered by custom BLYNK_WRITEfunctions.
BLYNK_WRITE_DEFAULT()
Page | 164
{
int pin = request.pin; // Which exactly pin is handled?
int value = param.asInt(); // Use param as usual.
}
BLYNK_READ_DEFAULT()
Redefines the handler for all pins that are not covered by custom BLYNK_READfunctions.
BLYNK_READ_DEFAULT()
{
int pin = request.pin; // Which exactly pin is handled?
Blynk.virtualWrite(pin, newValue);
}
BLYNK_CONNECTED()
Use this function when you need to run certain routine when hardware connects to Blynk
Cloud or private server. It’s common to call sync functions inside of this function.
BLYNK_CONNECTED() {
// Your code here
}
BLYNK_APP_CONNECTED()
This function is called every time Blynk app client connects to Blynk
server.
BLYNK_APP_CONNECTED() {
// Your code goes here
}
Note: Ennable this feature in Project Settings first:
Example
BLYNK_APP_DISCONNECTED()
This function is called every time the Blynk app disconnects from Blynk Cloud or private
server.
BLYNK_APP_DISCONNECTED() {
// Your code here
}
Page | 165
Note: Enable this feature in Project Settings first:
Example
Blynk.syncAll()
Requests all stored on the server latest values for all widgets. All
analog/digital/virtual pin values and states will be set to the latest
stored value. Every virtual pin will generate BLYNK_WRITE() event.
BLYNK_CONNECTED() {
Blynk.syncAll();
}
Blynk.syncVirtual(vPin)
This command updates individual Virtual Pin to the latest stored value on the server. When
it’s used, a corresponding BLYNK_WRITE handler is called.
Blynk.syncVirtual(V);
To update multiple pins, use:
Blynk.syncVirtual(V0, V1, V6, V9, V16);
Blynk.setProperty(vPin, “property”, value)
This command allows changing widget properties
Debugging
#define BLYNK_PRINT
#define BLYNK_DEBUG
To enable debug prints on the default Serial port add on the top of your sketch
IMPORTANT: This should be the first line in your code:
#define BLYNK_PRINT Serial // Defines the object that is used for printing
#define BLYNK_DEBUG // Optional, this enables more detailed prints
Then enable Serial Output in setup():
Serial.begin(9600);
Open Serial Monitor and you’ll see the debug prints.
You can also use spare Hardware serial ports or SoftwareSerial for debug output (you will
need an adapter to connect to it with your PC).
Page | 166
WARNING: Enabling BLYNK_DEBUG will slowdown your hardware processing speed up to 10
times!
BLYNK_LOG()
When BLYNK_PRINT is defined, you can use BLYNK_LOG to print your logs. The usage is similar
to printf:
BLYNK_LOG("This is my value: %d", );
On some platforms (like Arduino 101) the BLYNK_LOG may be unavailable, or may just use too
much resources.
Page | 168