-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
403 lines (309 loc) · 19.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>ESP Thermometer by gabormay</title>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/github-light.css">
<meta name="viewport" content="width=device-width">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="wrapper">
<header>
<h1>ESP Thermometer</h1>
<p>Battery operated inexpensive internet enabled thermometer built with ESP-01 WiFi module, DS18S20 digital thermometer, Arduino IDE and Ubidots</p>
<p class="view"><a href="https://github.com/gabormay/esp-thermometer">View the Project on GitHub <small>gabormay/esp-thermometer</small></a></p>
<ul>
<li><a href="https://github.com/gabormay/esp-thermometer/zipball/master">Download <strong>ZIP File</strong></a></li>
<li><a href="https://github.com/gabormay/esp-thermometer/tarball/master">Download <strong>TAR Ball</strong></a></li>
<li><a href="https://github.com/gabormay/esp-thermometer">View On <strong>GitHub</strong></a></li>
</ul>
</header>
<section>
<p>The objective of this project is to create a really inexpensive internet enabled thermometer to be able to monitor a room's temperature remotely.</p>
<p><img src="img/final-1.jpg" alt="Completed project photo 1">
<img src="img/final-2.jpg" alt="Completed project photo 2"></p>
<h1>
<a id="main-components" class="anchor" href="#main-components" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Main components</h1>
<p>Here's what you're going to need:</p>
<ul>
<li>ESP-01, a ESP8266 chip based WiFi module (others may also work with some modifications)</li>
<li>DS18S20 digital thermometer chip (or compatible)</li>
<li>2xAA batteries or a 3V power adapter</li>
<li>FTDI or USB-to-Serial (3v3!) converter (for programming the ESP8266)</li>
<li>some cables, and a few discrete components (see the schematic)</li>
<li>lot of patience :)</li>
</ul>
<h1>
<a id="general-notes-and-caveats" class="anchor" href="#general-notes-and-caveats" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>General notes and caveats</h1>
<ul>
<li>ESP8266 works with 3.3V, the pins are <em>not</em> 5V tolerant!</li>
<li>Use an external power supply for reliable programming (not the 3.3V from the USB converter for example)</li>
<li>If you're stuck or have an issue with setting up the ESP8266, please try looking through the materials in the <a href="References%20and%20further%20reading">References</a> section and also try Google - chances are somebody else had that problem and you can find a solution quickly</li>
</ul>
<h1>
<a id="first-steps---programming-your-esp8266" class="anchor" href="#first-steps---programming-your-esp8266" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>First steps - programming your ESP8266</h1>
<p>Start with the installation steps from <a href="https://github.com/esp8266/Arduino#installing-with-boards-manager">https://github.com/esp8266/Arduino#installing-with-boards-manager</a>:</p>
<ul>
<li>Install the Arduino IDE </li>
<li>Install the ESP8266 core library and select the board called 'Generic ESP8266 Module'</li>
</ul>
<p>Wire up your ESP module on a breadboard as explained in <a href="https://github.com/esp8266/Arduino/blob/master/doc/boards.md#minimal-hardware-setup-for-bootloading-and-usage">https://github.com/esp8266/Arduino/blob/master/doc/boards.md#minimal-hardware-setup-for-bootloading-and-usage</a></p>
<ul>
<li>Use an external power source (do not use the USB-to-serial adapter's VCC)</li>
<li>GND, TX and RX should be connected to the serial adapter's GND, RX and TX, respectively</li>
<li>CH_PD (chip enable) should be connected the VCC (10k pull-up resistor recommended)</li>
<li>RST and GPIO0 should be pulled-up to VCC
<ul>
<li>For convenience, add a switch or push button to be able to pull each down to GND momentarily</li>
</ul>
</li>
<li>Leave GPIO2 unconnected</li>
</ul>
<p>Now load the Sketch from File/Examples/ESP8266/Blink</p>
<ul>
<li>Fill in your WiFi ssid and password</li>
<li>'Verify' should show no errors</li>
</ul>
<p>Now you're ready to flash you first program to the ESP8266! Make sure that you have the Board setting in Arduino IDE set correctly:</p>
<p><img src="img/Board%20settings.png" alt="Board settings in Arduino IDE"></p>
<p>Then put the ESP bootloader into programming mode:</p>
<ul>
<li>Open the Serial Monitor in Arduino IDE (Tools/Serial Monitor)
<ul>
<li>Choose the proper COM port</li>
<li>Choose 74880 baud (this is necessary in order to see bootloader messages properly)</li>
</ul>
</li>
<li>On the board, connect both <code>RST</code> and <code>GPIO0</code> to GND (push the buttons if you have added them)</li>
<li>Release RST (connect back to VCC), while <code>GPIO0</code> is still at GND</li>
<li>
<p>In the Serial Monitor you should see the following message from the bootloader:</p>
<pre><code> ets Jan 8 2013,rst cause:2, boot mode:(1,6)
</code></pre>
<p>This means that the module is now in serial programming mode and ready to receive the new firmware.</p>
</li>
<li>
<code>GPIO0</code> can now be released back to VCC</li>
<li>Select Sketch/Upload</li>
</ul>
<p>In a short while the upload should finish without errors. If everything went fine the blue LED on the board will start blinking. You can now reset the board by connecting <code>RST</code> to GND momentarily. Make sure that <code>GPIO0</code> is <em>not</em> connected to GND otherwise you will enter the programming mode again.</p>
<p>At this point I suggest you to play around with your ESP8266. Try changing the example or try other sketches. Look at the the list of functions in the <a href="https://github.com/esp8266/Arduino/blob/master/doc/libraries.md">included libraries</a> and try to use them in your program.</p>
<p>You can use the <code>Serial.print()</code> family of functions to print diagnostic messages that you can then read in the Serial Monitor. Set the baud rate to 74880 to make it consistent with the bootloader via <code>Serial.begin(74880)</code>.</p>
<p>Once you feel comfortable programming your ESP8266, come back here and read on.</p>
<h1>
<a id="building-the-thermometer" class="anchor" href="#building-the-thermometer" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Building the thermometer</h1>
<h2>
<a id="the-circuit" class="anchor" href="#the-circuit" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>The circuit</h2>
<p><img src="img/schematic.png" alt="Schematic"></p>
<p>Explanation:</p>
<ul>
<li>U1 is a 2x4 DIP header for connecting the ESP module</li>
<li>SERIAL is a 1x3 DIP header for connecting a serial interface
<ul>
<li>Connect GND, TX and RX to your USB-toSerial adapter's GND, RX and TX, respectively</li>
<li>Double-check that the adapter uses 3.3V signal levels (not 5v)</li>
</ul>
</li>
<li>RST and PRG are push buttons, activating RESET and Programming mode, respectively
<ul>
<li>to simply reset the board, push RST</li>
<li>to enter programming mode
<ul>
<li>push RST then PRG (keep both pushed)</li>
<li>Release RST then PRG</li>
</ul>
</li>
</ul>
</li>
<li>C2 is across the rails, try to put it close to the module power pins (increases stability of the board)</li>
<li>R1 and C1 is an RC delay circuit for reliable deep sleep operation
<ul>
<li>purpose is to keep CH_PD low for enough time for the board to properly reset upon waking from deep sleep</li>
<li>only applies if your GPIO16 is tied to CH_PD</li>
</ul>
</li>
<li>U2 is the digital thermometer chip (DS18S20)</li>
<li>R2 is a pull-up</li>
</ul>
<h2>
<a id="ubidots" class="anchor" href="#ubidots" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Ubidots</h2>
<ul>
<li>Sign up at <a href="https://ubidots.com/">Ubidots</a>
</li>
<li>Create a source with two variables:
<ul>
<li>Temperature (unit: C)</li>
<li>Battery voltage (unit: mV)</li>
</ul>
</li>
<li>Note your API token and the ID of these two variables</li>
</ul>
<h2>
<a id="the-software" class="anchor" href="#the-software" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>The software</h2>
<p>Prerequisites</p>
<ul>
<li>Install the <a href="http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library">DS1820 Arduino Library</a> </li>
<li>Install the <a href="https://github.com/PaulStoffregen/OneWire">OneWire Arduino Library</a>
</li>
</ul>
<p>Download and edit the <a href="src/ESPThermometer/ESPThermometer.ino">source</a></p>
<ul>
<li>Fill in you SSID and WiFi credentials</li>
<li>Fill in your Ubidots token and variable IDs (from above)</li>
</ul>
<p>Connect your circuit to the serial adapter. Make sure the serial interface is connected to the USB-to-serial adapter properly (see above) and the adapter is plugged in to a USB port on your computer</p>
<p>Connect the power rails to an external 3.3V power source (e.g. 2xAA battery or a stabilized wall adapter)</p>
<ul>
<li>In general anything between 2.7 - 3.3 V should work</li>
<li>Do <strong>not</strong> use the serial adapter's VCC, as it cannot provide the amount of current necessary for programming</li>
</ul>
<p>Once you have everything connected, you should download the program to the module</p>
<ul>
<li>Put the module into program mode (push RST, PRG and then release RST, PRG)</li>
<li>Verify that you get the correct bootloader prompt - see <a href="First%20steps%20-%20programming%20your%20ESP8266"></a>
</li>
<li>Load the program into the Arduino IDE and upload (make sure to use the same settings as in <a href="First%20steps%20-%20programming%20your%20ESP8266"></a>
</li>
<li>Reset the board for good measure (push and release RST)</li>
</ul>
<p>If everything went well you should see an output similar to this in the serial monitor:</p>
<pre><code> ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v3ffe8654
~ld
à
ESP Thermometer starting...
Chip ID: [<your chip ID here>]
VCC = 2581 mV
Requesting temperatures...DONE
TEMP = 26.6 C
Connecting and sending...
.......WiFi connected
IP address:
192.168.178.44
Posting your variables
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 31 Aug 2016 20:18:29 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: POST, OPTIONS
2c
[{"status_code": 201}, {"status_code": 201}]
0
Entering deep sleep [ 557s ] ...
ets Jan 8 2013,rst cause:1, boot mode:(3,6)
[... and so on ...]
</code></pre>
<h1>
<a id="running-from-a-battery" class="anchor" href="#running-from-a-battery" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Running from a battery</h1>
<p>I was able to run this project from 2 AA batteries for about 2-3 weeks - not great but not that bad either. Interestingly enough the thermometer chip proved to be more sensitive to loss of voltage. It stopped working and produced bogus measurements when the battery voltage fell below 2.4V or so. The ESP module worked fine until about 1.8V, which is pretty remarkable.</p>
<p>Anyway, let's dig a little bit into how this was made possible and what can you do to further improve battery life.</p>
<h2>
<a id="deep-sleep" class="anchor" href="#deep-sleep" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Deep sleep</h2>
<p>Deep sleep is a power saving feature of the ESP8266 chip. When put to deep sleep, only an internal RTC circutry is powered, drawing very tiny current (~20uA). The rest of the chip is powered down and is completely inactive (no program runs for example). Once the specified delay is over, the RTC puts out a signal on GPIO16 which can be used to wake up the chip. Normally you would want to connect GPIO16 to RST to get the most features. On some ESP boards it is tied to CH_PD (chip enable) which works too but some of the features, i.e. keeping some state between sleep cycles is not supported. See the Application Note <a href="http://www.espressif.com/sites/default/files/9b-esp8266-low_power_solutions_en_0.pdf">ESP Low Power Solutions</a> from Expressif for more info. </p>
<p>Note that, in any case, upon wake-up, your program (sketch) will run from the very beginning (starting with <code>setup()</code>), so you don't really need to put anything in <code>loop()</code> at all. See the Application Note mentioned above for options to save some variables between these sleep cycles.</p>
<h2>
<a id="modifications-to-the-board" class="anchor" href="#modifications-to-the-board" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Modifications to the board</h2>
<h3>
<a id="scrapping-the-power-led" class="anchor" href="#scrapping-the-power-led" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Scrapping the Power LED</h3>
<p>The onboard power LED draws quite a bit of current (few milliamps at least) all the time the board is powered, even during deep sleep. That is almost 1000 times the current the chip needs in deep sleep, for just a plain power indicator, which is not a critical feature at all. On the ESP-01 board you don't have any control over this, so your only option to get rid of this 'powet hog' is to scrape the LED physically from the board. Be gentle, but firm. See <a href="https://www.openhomeautomation.net/esp8266-battery/">Running ESP8266 from a battery</a> for details.</p>
<h3>
<a id="connecting-gpio-16" class="anchor" href="#connecting-gpio-16" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Connecting GPIO 16</h3>
<p>To be able to wake the chip up from deep sleep, GPIO need to be connected to CH_PD or RST. In case it is not connected on your board, you will have to do it yourself. See <a href="http://tim.jagenberg.info/2015/01/18/low-power-esp8266/">http://tim.jagenberg.info/2015/01/18/low-power-esp8266/</a></p>
<h2>
<a id="doing-even-better" class="anchor" href="#doing-even-better" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Doing even better</h2>
<p>Here are a few things you can do to increase the battery life of your project even further.</p>
<ul>
<li>Use higher capacity power supply
<ul>
<li>You can use higher capacity batteries (e.g. D or A)</li>
<li>You can also use higher voltage batteries e.g. 3 x AA (or A or D) and add a 3V power regulator</li>
</ul>
</li>
<li>Update less frequently (less often than every 10 minutes)
<ul>
<li>Currently the project set up to wake up and update every ten minutes. </li>
<li>You can change the length of the sleep cycle on line <a href="https://github.com/gabormay/esp-thermometer/blob/master/src/ESPThermometer/ESPThermometer.ino#L31">#31</a>
</li>
</ul>
</li>
<li>Proper deep sleep (GPIO16 to RST)
<ul>
<li>If you connect GPIO16 to RST then you can keep some state betweeen cycles. </li>
<li>In particular, you can set it up to do RF calibration less frequently</li>
<li>You can also collect multiple measurements (e.g. every minute) then transmit them together as a batch</li>
</ul>
</li>
</ul>
<h1>
<a id="whats-next" class="anchor" href="#whats-next" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>What's next?</h1>
<p>There are a lot of ways to further improve and extend this project. Here are a few ideas and pointers to get you started.</p>
<ul>
<li>Dynamic WiFi setup
Instead of hardcoding the SSID and password, provide a simple Web interface to connect to the WiFi initially. Note that this will only work with proper deep sleep (GPIO16 to RST) as you would want to save this information betweeen the sleep cycles.</li>
<li>Dynamic Ubidots variable setup based on Chip ID
You can create the variables on the fly, e.g. using the chip ID (first check if they exist, and create them if not)</li>
<li>Implement additional hardware functions:
<ul>
<li>connect a second sensor, e.g. for humidity or light (GPIO2 is still free)</li>
<li>add relay switch and control it through Ubidots (again, GPIO2 can be used)</li>
<li>replace Ubidots with some other (maybe custom) IoT platform of your choice</li>
</ul>
</li>
</ul>
<h1>
<a id="closing-words" class="anchor" href="#closing-words" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Closing words</h1>
<p>Hope you've found this useful. If you run into problems and could not find anything on the internet and in the referenced documents, let me know - I will try to help as much as my time allows. In any case, please feel free to use the information presented in this article in any way you wish (no warranty, though, please refer to the LICENSE). Good luck!</p>
<h1>
<a id="references-and-further-reading" class="anchor" href="#references-and-further-reading" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>References and further reading</h1>
<p>Reference</p>
<ul>
<li><a href="http://bbs.espressif.com/">Vendor docs</a></li>
<li><a href="http://www.esp8266.com/wiki/doku.php">Community ESP Wiki</a></li>
<li><a href="https://github.com/esp8266/Arduino">Arduino Core for ESP8266</a></li>
<li><a href="https://github.com/esp8266/esp8266-wiki/wiki">Some useful info here</a></li>
</ul>
<p>Tutorials/guides</p>
<ul>
<li><a href="http://blog.brianmoses.net/2015/07/figuring-out-the-esp8266.html">http://blog.brianmoses.net/2015/07/figuring-out-the-esp8266.html</a></li>
<li><a href="http://williamdurand.fr/2015/03/17/playing-with-a-esp8266-wifi-module/">http://williamdurand.fr/2015/03/17/playing-with-a-esp8266-wifi-module/</a></li>
<li><a href="http://rancidbacon.com/files/kiwicon8/ESP8266_WiFi_Module_Quick_Start_Guide_v_1.0.4.pdf">http://rancidbacon.com/files/kiwicon8/ESP8266_WiFi_Module_Quick_Start_Guide_v_1.0.4.pdf</a></li>
</ul>
<p>Deep sleep/battery operation</p>
<ul>
<li><a href="https://www.openhomeautomation.net/esp8266-battery/">Running ESP8266 from a battery</a></li>
<li><a href="http://bbs.espressif.com/viewtopic.php?t=646">"RC time-delay circuit is recommended for CH_EN"</a></li>
<li><a href="http://www.espressif.com/sites/default/files/9b-esp8266-low_power_solutions_en_0.pdf">ESP Low Power Solutions</a></li>
</ul>
<p>DS1820</p>
<ul>
<li><a href="http://www.produktinfo.conrad.com/datenblaetter/175000-199999/176168-da-01-en-TEMP_SENSOR_DS18S20_TO92_MAXIM_DALLAS_.pdf">DS1820 Data sheet</a></li>
<li>
<a href="http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library">DS1820 Arduino Library</a>
<ul>
<li><a href="https://github.com/milesburton/Arduino-Temperature-Control-Library">https://github.com/milesburton/Arduino-Temperature-Control-Library</a></li>
</ul>
</li>
<li><a href="https://github.com/PaulStoffregen/OneWire">OneWire Arduino Library</a></li>
</ul>
</section>
<footer>
<p>This project is maintained by <a href="https://github.com/gabormay">gabormay</a></p>
<p><small>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
</footer>
</div>
<script src="javascripts/scale.fix.js"></script>
</body>
</html>