Meet The Arduino Killer - ESP8266 PDF
Meet The Arduino Killer - ESP8266 PDF
James Bruce
659 articles
18+ | BeGambleAware.org | Gambling can be
Wi-Fi is an essential bit of kit for any Internet of Things (IoT) DIY projects,
but our favorite Arduino doesn’t come with Wi-Fi, and adding in a Wi-Fi
shield can bring the total cost to around $40. What if I told you a there’s an
Arduino-compatible dev board with built-in Wi-Fi for less than $10? Well,
there is.
Meet the Arduino Killer: ESP8266. It was only a matter of time before the
crown was stolen from the shiny head of our dear Arduino development
board. Is it possible to fall in love with a circuit board?
In less than a year, the ESP8266 has rocketed in popularity, and is now so
well supported and developed that if you’re currently using Arduino, you
need to stand up and take note. Buy one now, then follow along with this
guide to get started programming your ESP8266 – all from within the
familiar Arduino IDE.
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 1/16
7/8/2019 Meet the Arduino Killer: ESP8266
VR Goes Mainstream:
PC & MOBILE LIFESTYLE HARDWARE Oculus Quest is The
Headset You’ve Been
Waiting For
You’re not limited to using the Arduino IDE of course – they’re compatible
with Lua too (which looks like a slimmed down Python to my novice eyes),
Is Your House Killing You?
but since we’re tackling this from the perspective of those us who have Airthings Wave Plus
learnt on Arduino, that’s what’ll we cover exclusively today. Smart Air Quality
Monitor Review!
Homeowner Eco
Heating Solution
New eco solutions: A great
solution to runaway fuel
bills?
Lifeguide Blog
There’s quite a few models of ESP8266 around now, but I’m going to go
ahead and recommend this one: ESP-12E (also known as NodeMCU 1.0, or Related Articles
it’s newest sibling NodeMCU 2.0).
PRODUCTIVITY
It’s a little more expensive than the others ($6.50 compared to $4!), but 4 Serious Health Issues
From Sitting Too Long
includes the serial driver needed to program the chip, and has a built-in
(And How to Avoid Them)
power regulator, as well as lots of IO pins. It’s widely supported and really
doesn’t need anything apart from a USB connection for programming or PROGRAMMING
power, so it’s the easiest to work with. If you buy any other kind of The 9 Best Coding Games
ESP8266 board, you may need a separate 3.3v power regulator, and a to Build Your
Programming Skills
suitable FTDI connection for programming.
First, install the serial drivers for this board. You may need to
disable KEXT signing if you’re running El Capitan due to new security
systems.
Next, we need to enable support for ESP8266 from the Arduino IDE’s
board manager. Open up Preferences, and enter the following URL where
it says Additional Board Manager URLs:
Latest Videos
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 2/16
7/8/2019 Meet the Arduino Killer: ESP8266
Hit Ok, then open the Boards Manager from Tools -> Board menu, search
for esp8266 and install the platform. You should now see a choice for
NodeMCU 1.0.
As a rst program, I’d suggest the simple Wi-Fi scanner – nd it from File -
> Examples -> ESP8266WiFi -> Wi Scan. Note that it’s quite slow to
upload, but eventually it’ll say “done uploading” and at that point (not
before, or you’ll break the upload process), you can open the Serial
monitor. You should see something similar to this:
Latest Deals
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 3/16
7/8/2019 Meet the Arduino Killer: ESP8266
#include
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
WiFiClient wifiClient;
void setup() {
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
void loop() {
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 4/16
7/8/2019 Meet the Arduino Killer: ESP8266
Before we carry on, here’s the pinout diagram – it might come in handy
later. Note that the pin numbers referred to in code are the GPIO numbers,
not the D0-16 probably written on your board PCB. If you absolutely,
positively cannot gure out why a sensor isn’t working, you’ve probably
mixed the pin numbers up.
READ MORE
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 5/16
7/8/2019 Meet the Arduino Killer: ESP8266
Download these MQTT and DHT libraries. Even if you already have them,
download these ones anyway, backup what you have, and overwrite with
these. The latest DHT11 library from Adafruit uses an automatic algorithm
for determining the speed at which data is read from the sensor, but it’s
buggy on ESP8266 and 90% of the time results in failed readings.
With the old version 1.0 of the library I’ve included in the download, you
can manually change the timing: 11 works best for these ESP2866 boards.
I also went through many copies of the MQTT library trying to nd one a
good callback function, nally landing on the one included. You’ll need to
restart the Arduino IDE after replacing these.
Here’s the complete code for the project. At the top are all the variables
you need to change, including Wi-Fi details, MQTT server (a URL can be
used instead if using a cloud server, though there’s no authentication in
place), and channels to publish data on.
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 6/16
7/8/2019 Meet the Arduino Killer: ESP8266
41 return result;
42 } PC & MOBILE LIFESTYLE HARDWARE
43
44 void setup() {
45 Serial.begin(115200);
46 dht.begin();
47 client.begin(server,wifiClient);
48 Serial.print("Connecting to ");
49 Serial.println(ssid);
50 WiFi.begin(ssid, password);
51 while (WiFi.status() != WL_CONNECTED) {
52 delay(500);
53 Serial.print(".");
54 }
55 Serial.println("");
56 Serial.println("WiFi connected");
57 Serial.println("IP address: ");
58 Serial.println(WiFi.localIP());
59
60 // Generate client name based on MAC address and last 8 bits of microsecon
61 uint8_t mac[6];
62 WiFi.macAddress(mac);
63 clientName += macToStr(mac);
64 clientName += "-";
65 clientName += String(micros() & 0xff, 16);
66
67 Serial.print("Connecting to ");
68 Serial.print(server);
69 Serial.print(" as ");
70 Serial.println(clientName);
71
72 if (client.connect((char*) clientName.c_str())) {
73 Serial.println("Connected to MQTT broker");
74 Serial.print("Subscribed to: ");
75 Serial.println(subscribeTopic);
76 client.subscribe(subscribeTopic);
77
78 }
79 else {
80 Serial.println("MQTT connect failed");
81 Serial.println("Will reset and try again...");
82 abort();
83 }
84
85 prevTime = 0;
86 }
87
88 void loop() {
89 static int counter = 0;
90
91 if(prevTime + interval < millis() || prevTime == 0){
92 prevTime = millis();
93 Serial.println("checking again");
94 Serial.println(prevTime);
95
96 h = dht.readHumidity();
97 t = dht.readTemperature();
98
99 h = h*1.23;
100 t = t*1.1;
101
102 // Check if any reads failed and exit early (to try again).
103 if (isnan(h) || isnan(t)) {
104 Serial.println("Failed to read from DHT sensor!");
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 7/16
7/8/2019 Meet the Arduino Killer: ESP8266
105 }
106 PC & MOBILE
else if(!client.connected()){ LIFESTYLE HARDWARE
107 Serial.println("Connection to broker lost; retrying");
108 }
109 else{
110 char* tPayload = f2s(t,0);
111 char* hPayload = f2s(h,0);
112
113 Serial.println(t);
114 Serial.println(h);
115
116 Serial.println(tPayload);
117 Serial.println(hPayload);
118
119 client.publish(tempTopic, tPayload);
120 client.publish(humidityTopic, hPayload);
121
122 Serial.println("published environmental data");
123 }
124
125 }
126
127 client.loop();
128
129 // reset after a day to avoid memory leaks
130 if(millis()>resetPeriod){
131 ESP.restart();
132 }
133 }
134
135
136 /* float to string
137 * f is the float to turn into a string
138 * p is the precision (number of decimals)
139 * return a string representation of the float.
140 */
141 char *f2s(float f, int p){
142 char * pBuff; // use to remember which part of the
143 const int iSize = 10; // number of buffers, one for each f
144 static char sBuff[iSize][20]; // space for 20 characters including
145 static int iCount = 0; // keep a tab of next place in sBuff
146 pBuff = sBuff[iCount]; // use this buffer
147 if(iCount >= iSize -1){ // check for wrap
148 iCount = 0; // if wrapping start again and reset
149 }
150 else{
151 iCount++; // advance the counter
152 }
153 return dtostrf(f, 0, p, pBuff); // call the library function
154 }
155
156 void messageReceived(String topic, String payload, char * bytes, unsigned in
157 Serial.print("incoming: ");
158 Serial.print(topic);
159 Serial.print(" - ");
160 Serial.print(payload);
161 Serial.println();
162 }
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 8/16
7/8/2019 Meet the Arduino Killer: ESP8266
First we connect to the Wi-Fi, then to the MQTT server, then begin
PC & MOBILE LIFESTYLE HARDWARE
the main loop().
In the loop, we poll the DHT sensor every 60 seconds and publish
readings to the relevant MQTT channels. Again, if you nd most of
the readings results in a failure message, you have the wrong version
of the DHT library – downgrade to v1.0.
After running these for a few days, I found they would randomly stop
working – I assume this is some kind of memory leak, but given I
don’t have the coding skill to deal with that and it might be with the
core libraries, I’ve opted for a simple soft reset every day. Exactly one
day after the sensors nodes are rst activated, they will restart
themselves.
When powering these cheap DHT11 modules from 3.3v, the humidity
values are far lower than they should be. I’ve solved this with a simple
multiplication, and calibrated against a commercial sensor. I’d advise
you to con rm against your own known source too, before relying on
the readings. Alternatively, power them with 5V – but you must place
a 5v-3.3v logic level shifter between the data pin and the
ESP8266, or you will damage it.
READ MORE
For a fun project, check out how to make a Wi-Fi button with the
ESP8266.
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 9/16
7/8/2019 Meet the Arduino Killer: ESP8266
How
PC & to Make Your
MOBILE Own Wi-Fi
LIFESTYLE Connected Button
HARDWARE
With ESP8266
In this tutorial, you'll learn how to create a Wi-Fi-enabled button
using NodeMCU and IFTTT.
READ MORE
But what will you make with ESP8266? Any projects using ESP8266
you’d like to see written up at MakeUseOf? Let us know in the
comments!
your@email.com Submit
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 10/16
7/8/2019 Meet the Arduino Killer: ESP8266
BUYING GUIDES , DIY
PC & MOBILE LIFESTYLE HARDWARE
Georgina Torbet
32 articles
To keep your processor temperatures down and the noise levels low, you’ll
want a third party cooler. Here’s our list of the very best coolers for your
PC.
Air Coolers
An air cooler consists of a heat sink to move heat away from the processor
and one or more fans to disperse that heat. It’s the same principle as a
stock cooler, but usually larger for better heat distribution.
The Hyper 212 Evo is infamous in the PC building community for its solid
performance and low price. It has four heat pipes to carry heat to the 4.6 x
2.0 x 6.3-inch heat sink. It is also compatible with many modern Intel and Latest Giveaways!
AMD processors. Eachine E511S Foldable
Drone: DJI Mavic Air on a
Budget
VR Goes Mainstream:
Oculus Quest is The
Headset You’ve Been
Waiting For
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 11/16
7/8/2019 Meet the Arduino Killer: ESP8266
Its reasonable size means it will easily t into most cases, with the
exception of very small compact cases for which it can be too wide. The
Hyper 12 Evo comes with one fan, which is suf cient for most users.
Though, there is an option to add a second 120mm fan if you need more
cooling.
BUYING GUIDES
The Noctua NH-D15 is ideal for those who want serious cooling
The 9 Best CPUs for
Gaming for All Budgets in
performance, particularly when overclocking. The beefy cooler has six 2019
heat pipes and two fans, one of which is sandwiched between the two sets
of ns. The fans are 140mm for maximum air ow and can be run at low
speeds for quieter operation.
Latest Videos
A neat feature of this cooler is the recessed lower ns. These create a cut-
out effect on the bottom side of the cooler. This means that even though
the cooler is very large, there’s still enough clearance for taller memory
sticks beneath it. The cooler supports most Intel and AMD chips and
comes with an easy-to-use mounting kit.
To meet cooling requirements with minimal noise, the cooler has six
copper heat pipes and specially contoured cooling ns. There’s also an
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 12/16
7/8/2019 Meet the Arduino Killer: ESP8266
option to add another 120mm fan to keep your processor even cooler. Like
PC & MOBILE LIFESTYLE HARDWARE
the others, it’s compatible with most Intel and AMD processors. The Dark
Rock 4’s medium size means it should t inside most full or mid-size cases.
Unlike a custom water cooling setup, all-in-one coolers are essentially plug
and play. They consist of a closed loop of liquid which circulates through a
block af xed to the processor and out to a radiator. The liquid carries heat
from the processor to the radiator, where fans disperse it.
4. Corsair H150i
Corsair H150i
BUY NOW ON AMAZON
$174.84
How to Set Up WhatsApp Web
From Any Web Browser
The Corsair H150i is a favorite for those who want solid performance with
no extra frills. The cooler comes in 240mm, 280mm, and 360mm sizes
which are equipped with one, two, or three low-noise fans respectively.
The fans deliver great air ow and don’t go beyond 20dB even at full
speed. There’s an option to turn fans off completely when temperatures
are low for even quieter operation.
Latest Deals
The O icial Lean $1200
The cooler’s performance can be customized through Corsair’s software.
Six Sigma $49
You can change the fan and pump speeds, and monitor both your CPU and Training &
coolant temperature. There’s also some RBG lighting options for the block
if you want to match your PC’s color scheme.
Surfshark VPN $430
The cooler is compatible with most modern Intel and AMD processors, Subscriptions $69
and the tubes are long enough to comfortably t the cooler into most mid-
tower and full-tower cases.
$139.99
The Ultimate $945
Microso Excel $34
May also be available from: B&H ($139.99). Certification
If you’re after performance and aesthetics, the NZXT Kraken X62 is the
most beautiful all-in-one cooler on the market. The CPU block has an
in nity mirror design which shows a mesmerizing swirling pattern in the
color of your choice. There are lots of lighting modes controllable through
NZXT’s Cam software, and you can customize the color of the NZXT logo
for perfect color matching.
The Kraken X62 isn’t all about looks though. It comes in a range of sizes,
with 120mm, 140mm, 240mm, 280mm, and 360mm variants available. It
has a quiet but powerful pump, and with the software, you can tune both
the pump and the fans. The tubing is reinforced to make it last, and the
fans run quietly too.
Compatible with most Intel and AMD chips, this is the ideal choice for
users who want an all-in-one that offers stunning aesthetics without
compromising on cooling.
6. Alphacool Eisbaer
Alphacool Eisbaer
BUY NOW ON AMAZON
$174.99
The radiator is pure copper, rather than the aluminum typically used in
other all-in-one radiators. This gives a better cooling performance and
means you don’t have to worry about mixing metals inside your loop. The
fans that come with the cooler are be quiet!’s popular Air Wings 2, which
move plenty of air to keep temperatures low. The integrated pump is the
Alphacool DC-LT Ceramic Ultra Low Noise, the performance of which can
be tweaked through software.
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 14/16
7/8/2019 Meet the Arduino Killer: ESP8266
Coolers
Upgrading your PC’s cooling system will help keep your processor
temperature down and reduce noise levels. If you’re looking for a simple
and affordable upgrade, get an air cooler for a boost in performance. Or if
you’re looking to seriously overclock your system, an all-in-one liquid
cooler gives you the bene ts of custom water cooling solutions, but
without the hassle.
READ MORE
your@email.com Submit
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 15/16
7/8/2019 Meet the Arduino Killer: ESP8266
https://www.makeuseof.com/tag/meet-arduino-killer-esp8266/ 16/16