ThingSpeak, ESP32 and Long Range Wireless Temp and Humidity

In this tutorial, we will measure different temperature and humidity data using Temp and humidity sensor. You will also learn how to send this data to ThingSpeak. So that you can analyze it from anywhere for different applications.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Hardware and Software Required

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

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.

Step 2: 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.

Step 3: Serial Monitor Output

Step 4: Making ThingSpeak Work

  • Create the account on ThnigSpeak.
  • Create a new channel, by clicking on Channels.
  • Click on My Channels.
  • Click New Channel.
  • Inside New Channel, name the channel.
  • Name the Field inside the Channel, Field is the variable in which the data is published.
  • Now save the Channel.
  • Now you can find your API keys on the dashboard. Go to the tap on the homepage and find your 'Write Api Key' which must be updated before uploading the code to ESP32.
  • Once Channel is created you would be able to view your temperature and Humiditydata in private view with Fields you created inside the Channel.
  • To plot a graph between Temp and Humidity data, you can use MATLAB Visualization.
  • For this go to App, Click on MATLAB Visualization.
  • Inside it selects Custom, in this, we have select plot temperature and wind speed on two different y-axes 8 as an example. Now click create.
  • MATLAB code will be autogenerated as you create visualization but you have to edit field id, read channel id, can check the following figure.
  • Then save and run the code.
  • You would see the plot.

Step 5: OUTPUT

Be the First to Share

    Recommendations

    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    Discussions