ThingSpeak, IFTTT, Temp and Humidity Sensor and Google Sheet

by Manish_Jugran in Circuits > Wireless

8132 Views, 2 Favorites, 0 Comments

ThingSpeak, IFTTT, Temp and Humidity Sensor and Google Sheet

uploads2ftmp2f8b3483c9-9f76-4b4c-b93c-a0150e0446c82fimage_OqtbVAnta8.jpg

In this project, we will measure temperature and humidity using NCD temperature and humidity sensor, ESP32, and ThingSpeak. We will also send different temperature and humidity readings to Google Sheet using ThingSpeak and IFTTT for analyzing the sensor data.

Hardware and Software Required

ESP32_1.png
temp.JPG

Hardware:

  • ESP-32: The ESP32 makes it easy to use the Arduino IDE and the Arduino Wire Language for IoT applications. This ESp32 IoT Module combines Wi-Fi, Bluetooth, and Bluetooth BLE for a variety of diverse applications. This module comes fully-equipped with 2 CPU cores that can be controlled and powered individually, and with an adjustable clock frequency of 80 MHz to 240 MHz. This ESP32 IoT WiFi BLE Module with Integrated USB is designed to fit in all ncd.io IoT products. Monitor sensors and control relays, FETs, PWM controllers, solenoids, valves, motors and much more from anywhere in the world using a web page or a dedicated server. We manufactured our own version of the ESP32 to fit into NCD IoT devices, offering more expansion options than any other device in the world! An integrated USB port allows easy programming of the ESP32. The ESP32 IoT WiFi BLE Module is an incredible platform for IoT application development. This ESP32 IoT WiFi BLE Module can be programmed using the Arduino IDE.
  • IoT Long Range Wireless Temperature And Humidity Sensor: Industrial Long Range Wireless Temperature Humidity Sensor. Grade with a Sensor Resolution of ±1.7%RH ±0.5°C. Up to 500, 000 Transmissions from 2 AA Batteries. Measures -40°C to 125°C with Batteries that Survive these Ratings.Superior 2-Mile LOS Range & 28 miles with High-Gain Antennas.Interface to Raspberry Pi, Microsoft Azure, Arduino, and More.
  • Long-Range Wireless Mesh Modem with USB Interface

Software Used

  • Arduino IDE
  • ThingSpeak
  • IFTTT

Library Used

  • PubSubClient Library
  • Wire.h

Arduino Client for MQTT

This library provides a client for doing simple publish/subscribe messaging with a server that supports MQTT For more information about MQTT, visit mqtt.org.

Download

  • The latest version of the library can be downloaded from GitHub

Documentation

  • The library comes with a number of example sketches. See File > Examples > PubSubClient within the Arduino application. Full API Documentation.

Compatible Hardware

The library uses the Arduino Ethernet Client API for interacting with the underlying network hardware. This means it Just Works with a growing number of boards and shields, including:

  • Arduino Ethernet
  • Arduino Ethernet Shield
  • Arduino YUN – use the included YunClient in place of EthernetClient, and be sure to do a Bridge.begin() first Arduino WiFi Shield - if you want to send packets greater than 90 bytes with this shield, enable the MQTT_MAX_TRANSFER_SIZE option in PubSubClient.h.
  • SparkFun WiFly Shield – when used with this library
  • Intel Galileo/Edison
  • ESP8266
  • ESP32The library cannot currently be used with hardware based on the ENC28J60 chip – such as the Nanode or the Nuelectronics Ethernet Shield. For those, there is an alternative library available.

Wire Library

The Wire library allows you to communicate with I2C devices, often also called "2 wire" or "TWI" (Two Wire Interface), can download from Wire.h

Basic Usage

  • Wire.begin() Begin using Wire in master mode, where you will initiate and control data transfers. This is the most common use when interfacing with most I2C peripheral chips.
  • Wire.begin(address)Begin using Wire in slave mode, where you will respond at "address" when other I2C masters chips initiate communication. Transmitting Wire.beginTransmission(address)Start a new transmission to a device at "address". Master mode is used.
  • Wire.write(data)Send data. In master mode, beginTransmission must be called first.
  • Wire.endTransmission()In master mode, this ends the transmission and causes all buffered data to be sent.

Receiving

  • Wire.requestFrom(address, count)Read "count" bytes from a device at "address". Master mode is used.
  • Wire.available()Returns the number of bytes available by calling receive.
  • Wire.read() Receive 1 byte.

Uploading the Code to ESP32 Using Arduino IDE

  • Before uploading the code you can view the working of this sensor at a given link.
  • Download and include the PubSubClient Library and Wire.h Library.
  • You must assign your API key, SSID (WiFi Name) and Password of the available network.
  • Compile and upload the Temp-ThinSpeak.ino code.
  • To verify the connectivity of the device and the data sent, open the serial monitor. If no response is seen, try unplugging your ESP32 and then plugging it again. Make sure the baud rate of the Serial monitor is set to the same one specified in your code 115200.

Serial Monitor Output

serialmonitor.jpg

Output

output1.jpg

Create an IFTTT Applet

uploads2ftmp2fd2ebb7ee-ad9c-4ce0-bea6-8fd2ea3e86432fimage_5UrT33Nuxg.jpg
uploads2ftmp2fb0d3abec-8190-4c09-bb76-59ca351366332fimage_cxqVAU5VNj.jpg
uploads2ftmp2f0032812f-d664-4ae2-b404-8c806b5cf2e92fimage_cOvgKMiFS8.jpg
uploads2ftmp2fb367a6e3-1fa4-4dbc-95c6-574b6b3455d62fimage_587NioTzAW.jpg
uploads2ftmp2f4936c050-8d37-4afe-acbd-640c49db36cd2fimage_QYkchRxshx.jpg
uploads2ftmp2f5db8f335-f968-46f7-b65a-49f09a0fe6202fimage_UODItBBjys.jpg
uploads2ftmp2f460cc000-7cf7-4377-8aea-c1a02df2c98d2fimage_aYru8kA5KU.jpg
uploads2ftmp2fd162e631-9877-469a-b300-cb0ed328c5a02fimage_Ak694Sass4.jpg
uploads2ftmp2f6e66c3fc-9a95-4c63-b03f-2ef86490f4c12fimage_M7TswAcQtF.jpg
uploads2ftmp2f1bae471c-8569-4eea-9907-77e1e66141482fimage_0NUhbR93iB.jpg
uploads2ftmp2f7437e046-88d5-4b9e-b180-65c78d6673052fimage_pLivOtbrmN.jpg
uploads2ftmp2fb81de077-ff67-43c9-9e9a-cff4af600a042fimage_gpSgmSysJK.jpg
uploads2ftmp2f6e3a5155-684a-434a-b5fa-68a813cdfdab2fimage_FWXtfRmQFL.jpg

  • To send data to ThingSpeak you can view it at this link.
  • IFTTT is a web service that lets you create applets that act in response to another action. You can use the IFTTT Webhooks service to create web requests to trigger an action. The incoming action is an HTTP request to the webserver, and the outgoing action is an email message.
  • First, create an IFTTT account.
  • Create an applet. Select My Applets.
  • Click the New Applet button.
  • Select the input action. Click the word this.
  • Click the Webhooks service. Enter Webhooks in the search field. Select the Webhooks.
  • Choose a trigger.
  • Complete the trigger fields. After you select Webhooks as the trigger, click the Receive a web request box to continue. Enter an event name.
  • Create trigger.
  • Now the trigger is created, for resulting action click That.
  • Enter “Google Sheets” in the search bar, and select the “Google Sheets” box.
  • If you have not connected to Google Sheet, then connect it first. Now choose action. Select add a row to a spreadsheet.
  • Then, complete the action fields.
  • Your applet should be created after you press the Finish.
  • Retrieve your Webhooks trigger information. Select My Applets, Services and search for Webhooks. Click Webhooks and Documentation button. You see your key and the format for sending a request. Enter the event name. The event name for this example is VibrationAndTempData.You can test the service using the test button or by pasting the URL into your browser.

Create a MATLAB Analysis

uploads2ftmp2fbfe65fba-ebab-411a-9186-0ac478aaa8062fimage_2jn2r8E1NZ.jpg
uploads2ftmp2f52bc3419-d0ac-480d-9e79-379cc315cea42fimage_vUVoBIog8I.jpg
uploads2ftmp2fdcd46706-bf5f-4461-9eb7-ec59589e45452fimage_PztSh4LO1o.jpg
uploads2ftmp2f545c2200-8a1a-43c7-82f2-8f2e1d3cd8a52fimage_RxCQkjuv0D.jpg

You can use the result of your analysis to trigger web requests, such as writing a trigger to IFTTT.

  • Click Apps, MATLAB Analysis and select New.
  • Select Trigger Email from IFTTT in the Examples section. The code below is prepopulated in your MATLAB analysis window.
  • Name your analysis and modify the code.
  • Save your MATLAB Analysis.

Create a Time Control to Run Your Analysis

uploads2ftmp2f1a5b5505-d5fa-42f9-a972-1bb3b77a9bf22fimage_jKpOtRNxC9.jpg
uploads2ftmp2f29e84eda-fb63-43ff-973b-dde5342996662fimage_W844tMvcfZ.jpg
uploads2ftmp2f534b92b6-b0f0-460c-93c0-7ffe7c801de72fimage_B6Zcw976zD.jpg
uploads2ftmp2f79158964-a3a2-4075-881c-016270bfa5db2fimage_eNpbbeip3k.jpg

Evaluate your ThingSpeak channel data and trigger other events.

  • Click Apps, TimeControl, and then click New TimeControl.
  • Save your TimeControl.

Output

uploads2ftmp2f37afd7ac-4aa3-4b0b-9af3-dbaab884dc7f2fimage_PsKuLg3xIi.jpg