remote temperature monitor (dht11)

23
Remote Temperature Monitor Prepared by : Parshwadeep Lahane

Upload: parshwadeep-lahane

Post on 16-Apr-2017

1.531 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Remote temperature monitor (DHT11)

Remote Temperature Monitor

Prepared by : Parshwadeep Lahane

Page 2: Remote temperature monitor (DHT11)

Summary• The project uses DHT11 and ESP8266 to monitor temperature at any point

of time • The monitoring aspect has 2 objectives:

• To check temperature at any given point (achieved with the help of cloud connectivity through Thingspeak)

• To send an alert message when temperature exceeds a predefined value(achieved with the help of Notify My Android app)

Page 3: Remote temperature monitor (DHT11)

Things needed

6Pin USB 2.0 to TTL UART Module Serial Converter

HARDWARE

ESP8266 - 01

DHT11

Multi Power Supply(5V and 3.3V)

Jumper wires Male to Male

Jumper wires Female to Female

Jumper wires Male to Female

12V adaptor (1Amp)

Bread Board

Laptop

Breadboard Adapters (optional)

WiFi connection

Any android mobile

Page 4: Remote temperature monitor (DHT11)

Things neededSOFTWARE

NodeMCU firmware (free)

Scripting language (free)

Account on Thingspeak (free)

Account on NMA (free)Premium one at $5

Windows (any other also would do)

Page 5: Remote temperature monitor (DHT11)

Costing• ESP8266 Rs300• UART Rs180• DHT11 Rs180• Multipower supplyRs140• 12V adapter Rs100• Jumper wires(15) Rs50• Bread board Rs120• Premium NMA membership Rs350 TOTAL COST ~Rs 1500 or ~US $23

Note: The price quoted is as per what I got on SP road in Bangalore,India. It may be cheaper online/offline at other places so cost can come down further.

Assumptions:1. WiFi connection already exists2. Laptop with windows is available3. Android Mobile phone available

Page 6: Remote temperature monitor (DHT11)

1.ESP8266 microcontroller from Chinese manufacturer Espressif that includes Wi-Fi capabilityCadence Tensilica LX106 microcontroller

• Operates at 3.3V • Firmware upgrade is needed as first step after purchase

• GPIO 0 should be grounded for firmware upgrade mode• RST and GPIO2 to be left open• Connect RX of ESP8266 to TX of FT232RL• Connect TX of ESP8266 to RX of FT232RL• Supply external voltage of 3.3V to VCC and CH_PD• GND to be connected to ground (FT232RL and ESP8266 ground should be

common)Once the connections are done. RED LED on ESP8266 should be on. BLUE LED will flash momentarily.

PIN PIN DescriptionVCC 3.3VRST Reset (low active)CH_PD Chip Power down (low active)TXD Transmit data (3.3V level)RXD Receive data (3.3V level)GPIO 0 General Purpose Input / Output GPIO 2 General Purpose Input / Output GND Ground

Steps for firmware upgrade: http://www.whatimade.today/loading-the-nodemcu-firmware-on-the-esp8266-windows-guide/

Page 7: Remote temperature monitor (DHT11)

2. Luapowerful, fast, lightweight, embeddable scripting language

What is Lua?Lua is a powerful, fast, lightweight, embeddable scripting language.Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.

Where does Lua come from?Lua is designed, implemented, and maintained by a team at PUC-Rio, the Pontifical Catholic University of Rio de Janeiro in Brazil. Lua was born and raised in Tecgraf, formerly the Computer Graphics Technology Group of PUC-Rio in 1993. Lua is now housed at LabLua, a laboratory of the Department of Computer Science of PUC-Rio.

What's in a name?"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua".

Page 8: Remote temperature monitor (DHT11)

3. NodeMCU firmware upgrade Lua based firmware for wifi-soc esp8266

• http://benlo.com/esp8266/esp8266QuickStart.html• Plug the USB to serial adapter into your PC. Most adapters are automatically recognized by

Windows 7 and 8. Users of XP or older versions of Windows may need a driver which should be supplied by the manufacturer of the USB adapter. The adapter will appear as a new COM port on your system. Check the Device Manager if necessary.

• Run ESP8266Flasher.exe• NodeMcuFlasher• If you only have one COM device, the port will appear automatically. If you have more than one,

select the correct one from the drop down menu.• The flasher program comes with default NodeMCU firmware in memory. This is unlikely to be

the latest version, but to get started quickly, use the default internal image. Later, you can download the latest firmware, then select the [Config] tab and choose the new .bin file. Select the 0x7C000 default and 0x7E000 blank sections. Uncheck the box for the 0x10000 IROM section.

• Click on Flash(E) to start the programming process.

• https://www.youtube.com/watch?v=Gh_pgqjfeQc

• https://github.com/nodemcu/nodemcu-firmware• https://bigdanzblog.wordpress.com/2015/04/14/installing-nodemcu-lua-firmware-on-esp8266-wifi-module/• http://www.roboremo.com/flashing-nodemcu-firmware-to-esp8266.html

Videos:

Page 9: Remote temperature monitor (DHT11)

If ESP8266 gets bricked what to do?(Blue LED starts flashing on continuous basis)• https://www.youtube.com/watch?v=VQ6-WrX54_s

http://www.xess.com/blog/esp8266-reflash/

Page 10: Remote temperature monitor (DHT11)

Sketch for ESP8266 firmware upgrade

ESP 8266-01FT232RL

TXD

TXD

RXD

RXD

GND GND

GPIO 0

GPIO 2

+3.3VMulti-Power

Supply

VCC CH_PD

GND

USB

conn

ectio

n to

Lap

top

3 pins used 7 pins used

Note: use a bread board to get connections in place.

A

Page 11: Remote temperature monitor (DHT11)

4.DHT11 Temperature and Humidity Sensor

GPIO 0 of ESP8266

along with ESP8266 and FT232 ground pins5V External power supply

Basic working :

Note: now NodeMCU has built in DHT function so same can be used directly, Arduino also has one built in function

Page 12: Remote temperature monitor (DHT11)

5. ThingSpeakThe open data cloud platform for the Internet of Things

ThingSpeak API Quick Start1. Sign Up for a ThingSpeak account2. Go to Channels, and click New Channel3. Complete the channel settings, and click Save Channel.4. Update your Channel via URL:5. https://api.thingspeak.com/update?

api_key=YOUR_CHANNEL_API_KEY&field1=76. View your Channel feed:7. https://api.thingspeak.com/channels/YOUR_CHANNEL_ID/

feeds.json

Video Link: https://www.youtube.com/watch?v=I_Jm6Q4z7ig

Page 13: Remote temperature monitor (DHT11)

6. Notify My Android(NMA)platform that allows you to deliver push notifications from virtually any application to your Android device

NMA API Quick guide1. Sign Up for a NMA account2. Go to Manage API Keys and Generate New Key3. Key details will appear in Key Description field.4. Update NMA alerts via URL:conn:send("GET /publicapi/notify?apikey=YOUR API KEY &application=ESP8266&event=XXXX&description=text1%20text2%20text3&priority=2\r\n HTTP/1.1\r\n")

Page 14: Remote temperature monitor (DHT11)

7. ESPlorerIntegrated Development Environment (IDE) for ESP8266 developers

• The essential multi-platforms tools for any ESP8266 developer from luatool author’s, including a LUA for NodeMCU and MicroPython.

• Download link : • https://github.com/4refr0nt/ESPlorer• http://esp8266.ru/esplorer/#download

Page 15: Remote temperature monitor (DHT11)

Code (init.lua)print("Setting up WIFI..")

wifi.setmode(wifi.STATION)

--modify according your wireless router settingswifi.sta.config("SSID","PASSWORD")

wifi.sta.connect()tmr.alarm(1, 1000, 1, function()

if wifi.sta.getip()== nil then

print("IP unavailable, Waiting...")

else tmr.stop(1)print("Config done, IP is "..wifi.sta.getip())

dofile("dht11.lua")end end)

Source: https://github.com/Parshwadeep/DHT11andESP8266andLuaandThingspeak/blob/master/init.lua

Change the RED part in your code

Page 16: Remote temperature monitor (DHT11)

--- Get temperature and humidity data and send data to thingspeak.comfunction sendData()getTemp()-- conection to thingspeak.comprint("Sending data to thingspeak.com")conn=net.createConnection(net.TCP, 0) conn:on("receive", function(conn, payload) print(payload) end)-- api.thingspeak.com 184.106.153.149conn:connect(80,'184.106.153.149') conn:send("GET /update?key=YOUR_KEY&field1="..temp.."&field2="..humi.." HTTP/1.1\r\n") conn:send("Host: api.thingspeak.com\r\n") conn:send("Accept: */*\r\n") conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")conn:send("\r\n")conn:on("sent",function(conn)print("Closing connection")conn:close()end)conn:on("disconnection", function(conn)print("Got disconnection...")end)end-- send data every X ms to thing speaktmr.alarm(2, 60000, 1, function() sendData() end )

Code (dht11.lua)pin=3m=0function getTemp()status,temp,humi,temp_decimial,humi_decimial = dht.read(pin)if( status == dht.OK ) then-- Float firmware using this exampleprint(string.format("DHT Temperature:%d.%02d;Humidity:%d.%02d\r\n",temp,temp_decimial,humi,humi_decimial))if (temp >25) thenprint ("ALERT: Temperature is out of range")if m == 1 thenconn=net.createConnection(net.TCP, 0) conn:on("receive", function(conn, payload) print(payload) end) conn:connect(80,"50.116.34.97") conn:send("GET /publicapi/notify?apikey=YOUR_KEY&application=ESP8266&event=TEMP_ALERT&description=Temperature%20is%20more%20than%2025&priority=2\r\n HTTP/1.1\r\n") conn:send("Host: notifymyandroid.com\r\n") conn:send("Accept: */*\r\n") conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n") conn:send("\r\n")m = 0else m = 1end end elseif( status == dht.ERROR_CHECKSUM ) thenprint( "DHT Checksum error." );elseif( status == dht.ERROR_TIMEOUT ) thenprint( "DHT Time out." );endend

Source: https://github.com/Parshwadeep/DHT11andESP8266andLuaandThingspeak/blob/master/dht11.lua

Change the RED part in your code

Page 17: Remote temperature monitor (DHT11)

Sketch for SW update and working model

ESP 8266-01FT232RL DHT11

TXD

TXD

RXD

RXD

GND GND GND

GPIO 0 Signal

+5V+3.3VMulti-Power

Supply

VCC CH_PDVCC

GND

USB

conn

ectio

n to

Lap

top

3 pins used 7 pins used 3 pins used

Note: use a bread board to get connections in place.

B

Page 18: Remote temperature monitor (DHT11)

Important for software upload on ESP8266• FIRST UPLOAD dht11.lua on ESP8266 by

clicking on Save to ESP in ESplorer.

• NEXT UPLOAD init.lua on ESP8266 by clicking on Save to ESP in ESplorer.

• Wait for 1-2 min after upload. The setup should work and updated data points available on Thingspeak channel and alerts on Notify My Android as per distance monitored.

Page 19: Remote temperature monitor (DHT11)

Sketch for post software update on ESP8266

ESP 8266-01 DHT11

GND GND

GPIO 0 Signal(S)

+5V+3.3VMulti-Power

Supply

VCC CH_PDVCC

GND

4 pins used 3 pins used

C

Page 20: Remote temperature monitor (DHT11)

Tracking sensor data on ThingSpeak

Alerts on mobile with NMA app

Page 21: Remote temperature monitor (DHT11)

In a Nutshell• Get ESP8266 upgraded with NodeMCU firmware with help of UART (Sketch A)• Open accounts on Thingspeak and Notify My Android App and get the API keys to be used

in code• Connect DHT11 to ESP8266 and upload the code on ESP8266 using ESPlorer (Sketch B)• Check the working of init.lua on serial monitor:

• Check Charts on Thingspeak• Check condition of Mobile Alert when temperature is above a predefined value.

• Remove UART connections and check standalone working of ESP8266 and DHT11 (Sketch C)

Page 22: Remote temperature monitor (DHT11)

Next Steps• Get the things working on circuit board with minimal size• Implement it in real server room/other environment

Page 23: Remote temperature monitor (DHT11)

END