{"id":103345,"date":"2021-06-15T14:26:46","date_gmt":"2021-06-15T14:26:46","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=103345"},"modified":"2021-06-17T10:50:46","modified_gmt":"2021-06-17T10:50:46","slug":"esp32-thingspeak-publish-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-thingspeak-publish-arduino\/","title":{"rendered":"ESP32 Publish Sensor Readings to ThingSpeak (easiest way)"},"content":{"rendered":"\n<p>In this guide, you&#8217;ll learn how to send sensor readings with the ESP32 to ThingSpeak. For demonstration purposes, we&#8217;ll use a <a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">BME280 sensor<\/a>, but you can easily modify the examples to use any other sensor. The ESP32 board will be programmed using the Arduino core.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Send-Sensor-Readings-to-ThingSpeak.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Publish Sensor Readings to ThingSpeak easiest way Arduino\" class=\"wp-image-103387\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Send-Sensor-Readings-to-ThingSpeak.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Send-Sensor-Readings-to-ThingSpeak.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Send-Sensor-Readings-to-ThingSpeak.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Send-Sensor-Readings-to-ThingSpeak.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>ThingSpeak allows you to publish your sensor readings to their website and plot them in charts with timestamps. Then, you can access your readings from anywhere in the world.<\/p>\n\n\n\n<p>We have a similar tutorial for the ESP8266 board: <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-thingspeak-publish-arduino\/\">ESP8266 NodeMCU Publish Sensor Readings to ThingSpeak (easiest way)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Overview<\/h2>\n\n\n\n<p>There are many ways to send sensor readings to ThingSpeak. In this tutorial, we&#8217;ll use one of the easiest ways\u2014using the <a href=\"https:\/\/github.com\/mathworks\/thingspeak-arduino\" target=\"_blank\" rel=\"noreferrer noopener\">thingspeak-arduino library<\/a>. This library provides methods to easily publish sensor readings to single fields or multiple fields. You can check the library examples on its GitHub page.<\/p>\n\n\n\n<p>To exemplify, we&#8217;ll use the BME280 sensor, but you can use any other sensor (you need to modify the code). <\/p>\n\n\n\n<p class=\"rntbox rntclblue\">Recommended reading: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\" title=\"https:\/\/randomnerdtutorials.com\/esp32-bme280-arduino-ide-pressure-temperature-humidity\/\">ESP32 with BME280 Sensor using Arduino IDE (Pressure, Temperature, Humidity)<\/a>.<\/p>\n\n\n\n<p>We&#8217;ll cover how to publish to a <a href=\"#single\">single field<\/a> and how to publish to <a href=\"#multiple\">multiple fields<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing Arduino IDE<\/h2>\n\n\n\n<p>For this tutorial we&#8217;ll program the ESP32 using the Arduino core. So, make sure you have the ESP32 add-on installed in your Arduino IDE:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-windows-instructions\/\">Installing the ESP32 Board in Arduino IDE (Windows, Mac OS X, Linux)<\/a><\/li><\/ul>\n\n\n\n<p>If you want to program the ESP32 using VS Code with the PlatformIO extension, follow the next tutorial instead:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/vs-code-platformio-ide-esp32-esp8266-arduino\/\">Getting Started with VS Code and PlatformIO IDE for ESP32 and ESP8266<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Installing the ThingSpeak Library<\/h3>\n\n\n\n<p>To send sensor readings to ThingSpeak, we&#8217;ll use the thingspeak-arduino library. You can install this library through the Arduino Library Manager. Go to <strong>Sketch <\/strong>> <strong>Include Library<\/strong> > <strong>Manage Libraries&#8230;<\/strong> and search for &#8220;<strong>ThingSpeak<\/strong>&#8221; in the Library Manager. Install the ThingSpeak library by MathWorks.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Install-Thingspeak-library-Arduino-IDE.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install ThingSpeak Library Arduino IDE\" class=\"wp-image-103348\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Install-Thingspeak-library-Arduino-IDE.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Install-Thingspeak-library-Arduino-IDE.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Install-Thingspeak-library-Arduino-IDE.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Installing BME280 Libraries<\/h3>\n\n\n\n<p>As mentioned previously, we&#8217;ll publish sensor readings from a BME280 sensor. So, you also need to install the libraries to interface with the BME280 sensor.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_BME280_Library\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit_BME280 library<\/a><\/li><li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\" target=\"_blank\" rel=\"noreferrer noopener\">Adafruit_Sensor library<\/a><\/li><\/ul>\n\n\n\n<p>You can install the libraries using the Arduino Library Manager. Go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>&nbsp;and search for the library name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Libraries (VS Code + PlatformIO)<\/h3>\n\n\n\n<p>If you&#8217;re using VS Code with the PlatformIO extension, copy the following to the <span class=\"rnthl rntliteral\">platformio.ini<\/span> file to include the libraries.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>lib_deps = mathworks\/ThingSpeak@^2.0.0\n            adafruit\/Adafruit Unified Sensor @ ^1.1.4\n            adafruit\/Adafruit BME280 Library @ ^2.1.2  <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Building the Circuit<\/h2>\n\n\n\n<p>To exemplify how to send data to ThingSpeak, we&#8217;ll send sensor readings from a BME280 sensor. So, you need to wire a BME280 sensor to your ESP32.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>To complete this tutorial you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\">BME280 sensor module<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\">ESP32<\/a>&nbsp;(read&nbsp;<a href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best ESP32 development boards<\/a>)<\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\">Breadboard<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper wires<\/a><\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic Diagram<\/h3>\n\n\n\n<p>We\u2019re going to use I2C communication with the BME280 sensor module. For that, wire the sensor to the default ESP32&nbsp;SCL (<span class=\"rnthl rntcblue\">GPIO 22<\/span>)&nbsp;and&nbsp;SDA (<span class=\"rnthl rntcgreen\">GPIO 21<\/span>)&nbsp;pins, as shown in the following schematic diagram.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"675\" height=\"670\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?resize=675%2C670&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Wiring Circuit to BME280 Schematic Diagram\" class=\"wp-image-99755\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?w=675&amp;quality=100&amp;strip=all&amp;ssl=1 675w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?resize=300%2C298&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/ESP32-BME280-Sensor-Temperature-Humidity-Pressure-Wiring-Diagram-Circuit_f.png?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/figure><\/div>\n\n\n\n<p class=\"rntbox rntclblue\">Recommended reading: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-pinout-reference-gpios\/\">ESP32 Pinout Reference: Which GPIO pins should you use?<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"single\">ThingSpeak &#8211; Getting Started<\/h2>\n\n\n\n<p><a href=\"https:\/\/thingspeak.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Go to ThingSpeak<\/a> an click the \u201c<strong>Get Started For Free<\/strong>\u201d button to create a new account. This account is linked to a Mathworks account. So, if you already have a Mathworks account, you should log in with that account.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating New Channel<\/h3>\n\n\n\n<p>After your account is ready, sign in, open the \u201c<strong>Channels<\/strong>\u201d tab and select &#8220;<strong>My Channels<\/strong>&#8220;.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"438\" height=\"258\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-my-channels.png?resize=438%2C258&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ThingSpeak Getting Started my channels tab\" class=\"wp-image-52352\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-my-channels.png?w=438&amp;quality=100&amp;strip=all&amp;ssl=1 438w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-my-channels.png?resize=300%2C177&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 438px) 100vw, 438px\" \/><\/figure><\/div>\n\n\n\n<p>Press the \u201cNew Channel\u201d button to create a new channel.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"453\" height=\"326\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP32-ESP8266-NodeMCU-ThingSpeak-New-Channel.png?resize=453%2C326&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 NodeMCU ThingSpeak Create New Channel\" class=\"wp-image-96802\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP32-ESP8266-NodeMCU-ThingSpeak-New-Channel.png?w=453&amp;quality=100&amp;strip=all&amp;ssl=1 453w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/05\/ESP32-ESP8266-NodeMCU-ThingSpeak-New-Channel.png?resize=300%2C216&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 453px) 100vw, 453px\" \/><\/figure><\/div>\n\n\n\n<p>Type a name for your channel and add a description. In this example, we&#8217;ll just publish temperature. If you want to publish multiple readings (like humidity and pressure), you can enable more fields as you&#8217;ll see later in this tutorial.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"740\" height=\"500\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-create-new-channel-ESP32.png?resize=740%2C500&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ThingSpeak Edit Add New Channel Settings Configuration\" class=\"wp-image-103354\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-create-new-channel-ESP32.png?w=740&amp;quality=100&amp;strip=all&amp;ssl=1 740w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-create-new-channel-ESP32.png?resize=300%2C203&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/figure><\/div>\n\n\n\n<p>Click the <strong>Save Channel<\/strong> button to create and save your channel.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"313\" height=\"91\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-save-channel.png?resize=313%2C91&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 NodeMCU ThingSpeak Save New Channel\" class=\"wp-image-103355\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-save-channel.png?w=313&amp;quality=100&amp;strip=all&amp;ssl=1 313w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-save-channel.png?resize=300%2C87&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 313px) 100vw, 313px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Customizing Chart<\/h3>\n\n\n\n<p>The chart can be customized, go to your <strong>Private View<\/strong> tab and click on the edit icon.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"690\" height=\"693\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Customize-Chart.png?resize=690%2C693&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ThingSpeak Customize Chart Private View ThingSpeak\" class=\"wp-image-103356\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Customize-Chart.png?w=690&amp;quality=100&amp;strip=all&amp;ssl=1 690w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Customize-Chart.png?resize=300%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Customize-Chart.png?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w\" sizes=\"(max-width: 690px) 100vw, 690px\" \/><\/figure><\/div>\n\n\n\n<p>You can give a title to your chart, customize the background color, x and y axis, and much more. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"739\" height=\"613\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-field1-options.png?resize=739%2C613&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ThingSpeak field 1 chart options save settings\" class=\"wp-image-103357\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-field1-options.png?w=739&amp;quality=100&amp;strip=all&amp;ssl=1 739w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-field1-options.png?resize=300%2C249&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 739px) 100vw, 739px\" \/><\/figure><\/div>\n\n\n\n<p>When you\u2019re done, press the \u201c<strong>Save<\/strong>\u201d button.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">API Key<\/h3>\n\n\n\n<p>To send values from the ESP32 to ThingSpeak, you need the Write API Key. Open the \u201c<strong>API Keys<\/strong>\u201d<br>tab and copy the Write API Key to a safe place because you\u2019ll need it in a moment.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"701\" height=\"337\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Write-API-key.png?resize=701%2C337&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Thingspeak Write API Key generate new key\" class=\"wp-image-103358\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Write-API-key.png?w=701&amp;quality=100&amp;strip=all&amp;ssl=1 701w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Write-API-key.png?resize=300%2C144&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 701px) 100vw, 701px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">ESP32 Publish Sensor Readings to ThingSpeak &#8211; Code<\/h2>\n\n\n\n<p>Copy the following code to your Arduino IDE (or to the <span class=\"rnthl rntliteral\">main.cpp<\/span> file if you&#8217;re using PlatformIO).<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Adapted from WriteSingleField Example from ThingSpeak Library (Mathworks)  \n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-thingspeak-publish-arduino\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n\n#include &lt;WiFi.h&gt;\n#include &quot;ThingSpeak.h&quot;\n#include &lt;Adafruit_BME280.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;   \/\/ your network SSID (name) \nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;   \/\/ your network password\n\nWiFiClient  client;\n\nunsigned long myChannelNumber = X;\nconst char * myWriteAPIKey = &quot;XXXXXXXXXXXXXXXX&quot;;\n\n\/\/ Timer variables\nunsigned long lastTime = 0;\nunsigned long timerDelay = 30000;\n\n\/\/ Variable to hold temperature readings\nfloat temperatureC;\n\/\/uncomment if you want to get temperature in Fahrenheit\n\/\/float temperatureF;\n\n\/\/ Create a sensor object\nAdafruit_BME280 bme; \/\/BME280 connect to ESP32 I2C (GPIO 21 = SDA, GPIO 22 = SCL)\n\nvoid initBME(){\n  if (!bme.begin(0x76)) {\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring!&quot;);\n    while (1);\n  }\n}\n\nvoid setup() {\n  Serial.begin(115200);  \/\/Initialize serial\n  initBME();\n  \n  WiFi.mode(WIFI_STA);   \n  \n  ThingSpeak.begin(client);  \/\/ Initialize ThingSpeak\n}\n\nvoid loop() {\n  if ((millis() - lastTime) &gt; timerDelay) {\n    \n    \/\/ Connect or reconnect to WiFi\n    if(WiFi.status() != WL_CONNECTED){\n      Serial.print(&quot;Attempting to connect&quot;);\n      while(WiFi.status() != WL_CONNECTED){\n        WiFi.begin(ssid, password); \n        delay(5000);     \n      } \n      Serial.println(&quot;\\nConnected.&quot;);\n    }\n\n    \/\/ Get a new temperature reading\n    temperatureC = bme.readTemperature();\n    Serial.print(&quot;Temperature (\u00baC): &quot;);\n    Serial.println(temperatureC);\n    \n    \/\/uncomment if you want to get temperature in Fahrenheit\n    \/*temperatureF = 1.8 * bme.readTemperature() + 32;\n    Serial.print(&quot;Temperature (\u00baF): &quot;);\n    Serial.println(temperatureF);*\/\n    \n    \/\/ Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different\n    \/\/ pieces of information in a channel.  Here, we write to field 1.\n    int x = ThingSpeak.writeField(myChannelNumber, 1, temperatureC, myWriteAPIKey);\n    \/\/uncomment if you want to get temperature in Fahrenheit\n    \/\/int x = ThingSpeak.writeField(myChannelNumber, 1, temperatureF, myWriteAPIKey);\n\n    if(x == 200){\n      Serial.println(&quot;Channel update successful.&quot;);\n    }\n    else{\n      Serial.println(&quot;Problem updating channel. HTTP error code &quot; + String(x));\n    }\n    lastTime = millis();\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_ThingSpeak_Single_Field.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>To make the code work, you need to insert your network credentials in the following variables:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"REPLACE_WITH_YOUR_SSID\";   \nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";  <\/code><\/pre>\n\n\n\n<p>You need to insert the number of the channel that you&#8217;re publishing to. If you only have one channel created in ThingSpeak, the channel number is 1. Otherwise, you can see the number of the channel on the <strong>Private View<\/strong> tab.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>unsigned long myChannelNumber = 1;<\/code><\/pre>\n\n\n\n<p>Finally, you need to insert the Write API key you&#8217;ve gotten from the previous steps:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char * myWriteAPIKey = \"XXXXXXXXXXXXXXXX\";<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How the Code Works<\/h3>\n\n\n\n<p>First, you need to include the necessary libraries.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;WiFi.h&gt;\n#include \"ThingSpeak.h\"\n#include &lt;Adafruit_BME280.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;<\/code><\/pre>\n\n\n\n<p>Insert your network credentials in the following variables:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const char* ssid = \"REPLACE_WITH_YOUR_SSID\";   \nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\"; <\/code><\/pre>\n\n\n\n<p>Create a Wi-Fi client to connect to ThingSpeak.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFiClient  client;<\/code><\/pre>\n\n\n\n<p>Insert your channel number as well as your write API key:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>unsigned long myChannelNumber = 1;\nconst char * myWriteAPIKey = \"XXXXXXXXXXXXXXXX\";<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">timerDelay<\/span> variable insert how frequently you want to publish readings. In this case, we&#8217;re publishing readings every 30 seconds (30000 milliseconds). You can change this delay time if you want.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>unsigned long lastTime = 0;\nunsigned long timerDelay = 30000;<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">temperatureC<\/span> variable holds the temperature value in Celsius degrees.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float temperatureC;<\/code><\/pre>\n\n\n\n<p>If you want to get the temperature in Fahrenheit degrees, uncomment the following line.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/float temperatureF;<\/code><\/pre>\n\n\n\n<p>Create an <span class=\"rnthl rntliteral\">Adafruit_BME280<\/span> object called <span class=\"rnthl rntliteral\">bme<\/span> on the default ESP32 pins.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Adafruit_BME280 bme; \/\/BME280 connect to ESP32 I2C (GPIO 21 = SDA, GPIO 22 = SCL)<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">initBME()<\/span> function initializes the BME280 sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void initBME(){\n  if (!bme.begin(0x76)) {\n    Serial.println(\"Could not find a valid BME280 sensor, check wiring!\");\n    while (1);\n  }\n}<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);  \/\/Initialize serial<\/code><\/pre>\n\n\n\n<p>Initialize the BME280 sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>initBME();<\/code><\/pre>\n\n\n\n<p>Set the ESP32 as a Wi-Fi station:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFi.mode(WIFI_STA);<\/code><\/pre>\n\n\n\n<p>Initialize ThingSpeak:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ThingSpeak.begin(client);  \/\/ Initialize ThingSpeak<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, connect or reconnect to Wi-Fi in case the connection was lost:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Connect or reconnect to WiFi\nif(WiFi.status() != WL_CONNECTED){\n  Serial.print(\"Attempting to connect\");\n  while(WiFi.status() != WL_CONNECTED){\n    WiFi.begin(ssid, password); \n    delay(5000);     \n  } \n  Serial.println(\"\\nConnected.\");\n}<\/code><\/pre>\n\n\n\n<p>Get a new temperature reading and print it in the Serial Monitor:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>temperatureC = bme.readTemperature();<\/code><\/pre>\n\n\n\n<p>Uncomment the following lines if you want to get the temperature in Fahrenheit degrees.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/*temperatureF = 1.8 * bme.readTemperature() + 32;\nSerial.print(\"Temperature (\u00baC): \");\nSerial.println(temperatureF);*\/<\/code><\/pre>\n\n\n\n<p>Finally, write to ThingSpeak. You can use the <span class=\"rnthl rntliteral\">writeField()<\/span> method that accepts as arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>the channel number;<\/li><li>the field number (in our case, we just have one field);<\/li><li>the value you want to publish (<span class=\"rnthl rntliteral\">temperatureC<\/span> or <span class=\"rnthl rntliteral\">temperatureF<\/span>); <\/li><li>your write API key.<\/li><\/ul>\n\n\n\n<p>This function returns the code 200 if it has succeeded in publishing the readings.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int x = ThingSpeak.writeField(myChannelNumber, 1, temperatureC, myWriteAPIKey);\nif(x == 200){\n  Serial.println(\"Channel update successful.\");\n}\nelse{\n  Serial.println(\"Problem updating channel. HTTP error code \" + String(x));\n}<\/code><\/pre>\n\n\n\n<p>If you want to publish your readings in Fahrenheit degrees, uncomment the following line in the code:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/int x = ThingSpeak.writeField(myChannelNumber, 1, temperatureF, myWriteAPIKey);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Demonstration<\/h3>\n\n\n\n<p>After inserting your network credentials, channel number and API key, upload the code to your board.<\/p>\n\n\n\n<p>Open the Serial Monitor at a baud rate of 115200, and press the on-board RST button. After 30 seconds, it should connect to Wi-Fi and start publishing the readings to ThingSpeak.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"731\" height=\"525\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Publish-temperature-readings-to-thingspeak-esp32.png?resize=731%2C525&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Publish Temperature Readings ThingSpeak ESP32 Serial Monitor\" class=\"wp-image-103377\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Publish-temperature-readings-to-thingspeak-esp32.png?w=731&amp;quality=100&amp;strip=all&amp;ssl=1 731w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Publish-temperature-readings-to-thingspeak-esp32.png?resize=300%2C215&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/figure><\/div>\n\n\n\n<p>Go to your ThingSpeak account to the channel you&#8217;ve just created, and you&#8217;ll see the temperature readings being published and plotted on the chart.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"599\" height=\"470\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-chart-bme280-sensor-readings-temperature.png?resize=599%2C470&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ThingSpeak Chart BME280 Readings ESP32\" class=\"wp-image-103366\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-chart-bme280-sensor-readings-temperature.png?w=599&amp;quality=100&amp;strip=all&amp;ssl=1 599w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-chart-bme280-sensor-readings-temperature.png?resize=300%2C235&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/figure><\/div>\n\n\n\n<p>Now, you can get access to those readings from anywhere in the world by accessing your ThingSpeak account.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"multiple\">Sending Multiple Fields (Temperature, Humidity, and Pressure)<\/h2>\n\n\n\n<p>In this section, you&#8217;ll learn how to send multiple fields\u2014this is sending more than one value at a time\u2014we&#8217;ll send temperature, humidity, and pressure readings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enable Multiple Fields &#8211; ThingSpeak<\/h3>\n\n\n\n<p>First, you need to create more fields in your ThingSpeak account. This is simple. You need to go to your <strong>Channel Settings<\/strong> and add as many fields as you want. In this case, we&#8217;ve added two more fields, one for the humidity and another for the pressure.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"560\" height=\"460\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-enable-multiple-fields.png?resize=560%2C460&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Thingspeak add new fields channel settings change\" class=\"wp-image-103381\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-enable-multiple-fields.png?w=560&amp;quality=100&amp;strip=all&amp;ssl=1 560w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-enable-multiple-fields.png?resize=300%2C246&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/figure><\/div>\n\n\n\n<p>Finally, save the channel\u2014click the <strong>Save Channel<\/strong> button.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"313\" height=\"91\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-save-channel.png?resize=313%2C91&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 NodeMCU ThingSpeak Save New Channel\" class=\"wp-image-103355\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-save-channel.png?w=313&amp;quality=100&amp;strip=all&amp;ssl=1 313w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-save-channel.png?resize=300%2C87&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 313px) 100vw, 313px\" \/><\/figure><\/div>\n\n\n\n<p>Now, if you go to the <strong>Private View<\/strong> tab, you should have three charts. Edit the newly created charts with a title and axis labels.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ESP32 Write Multiple Fields to ThingSpeak &#8211; Code<\/h3>\n\n\n\n<p>The following code sends multiple fields to ThingSpeak (temperature, humidity, and pressure from the BME280 sensor).<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Adapted from Example from ThingSpeak Library (Mathworks) \n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-thingspeak-publish-arduino\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n\n#include &lt;WiFi.h&gt;\n#include &quot;ThingSpeak.h&quot;\n#include &lt;Adafruit_BME280.h&gt;\n#include &lt;Adafruit_Sensor.h&gt;\n\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;   \/\/ your network SSID (name) \nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;   \/\/ your network password\n\nWiFiClient  client;\n\nunsigned long myChannelNumber = X;\nconst char * myWriteAPIKey = &quot;XXXXXXXXXXXXXXXX&quot;;\n\n\/\/ Timer variables\nunsigned long lastTime = 0;\nunsigned long timerDelay = 30000;\n\n\/\/ Variable to hold temperature readings\nfloat temperatureC;\nfloat humidity;\nfloat pressure;\n\/\/uncomment if you want to get temperature in Fahrenheit\n\/\/float temperatureF;\n\n\/\/ Create a sensor object\nAdafruit_BME280 bme; \/\/BME280 connect to ESP32 I2C (GPIO 21 = SDA, GPIO 22 = SCL)\n\nvoid initBME(){\n  if (!bme.begin(0x76)) {\n    Serial.println(&quot;Could not find a valid BME280 sensor, check wiring!&quot;);\n    while (1);\n  }\n}\n\nvoid setup() {\n  Serial.begin(115200);  \/\/Initialize serial\n  initBME();\n  \n  WiFi.mode(WIFI_STA);   \n  \n  ThingSpeak.begin(client);  \/\/ Initialize ThingSpeak\n}\n\nvoid loop() {\n  if ((millis() - lastTime) &gt; timerDelay) {\n    \n    \/\/ Connect or reconnect to WiFi\n    if(WiFi.status() != WL_CONNECTED){\n      Serial.print(&quot;Attempting to connect&quot;);\n      while(WiFi.status() != WL_CONNECTED){\n        WiFi.begin(ssid, password); \n        delay(5000);     \n      } \n      Serial.println(&quot;\\nConnected.&quot;);\n    }\n\n    \/\/ Get a new temperature reading\n    temperatureC = bme.readTemperature();\n    Serial.print(&quot;Temperature (\u00baC): &quot;);\n    Serial.println(temperatureC);\n    humidity = bme.readHumidity();\n    Serial.print(&quot;Humidity (%): &quot;);\n    Serial.println(humidity);\n    pressure = bme.readPressure() \/ 100.0F;\n    Serial.print(&quot;Pressure (hPa): &quot;);\n    Serial.println(pressure);\n    \n    \/\/uncomment if you want to get temperature in Fahrenheit\n    \/*temperatureF = 1.8 * bme.readTemperature() + 32;\n    Serial.print(&quot;Temperature (\u00baF): &quot;);\n    Serial.println(temperatureF);*\/\n\n    \/\/ set the fields with the values\n    ThingSpeak.setField(1, temperatureC);\n    \/\/ThingSpeak.setField(1, temperatureF);\n    ThingSpeak.setField(2, humidity);\n    ThingSpeak.setField(3, pressure);\n    \n    \/\/ Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different\n    \/\/ pieces of information in a channel.  Here, we write to field 1.\n    int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);\n\n    if(x == 200){\n      Serial.println(&quot;Channel update successful.&quot;);\n    }\n    else{\n      Serial.println(&quot;Problem updating channel. HTTP error code &quot; + String(x));\n    }\n    lastTime = millis();\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_ThingSpeak_Multiple_Fields.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>This code is very similar to the previous one, but sends multiple fields. Let&#8217;s take a look at the relevant parts for this example.<\/p>\n\n\n\n<p>Frist, create variables to hold the sensor readings:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float temperatureC;\nfloat humidity;\nfloat pressure;<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, get new temperature, humidity and pressure readings:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Get a new temperature reading\ntemperatureC = bme.readTemperature();\nSerial.print(\"Temperature (\u00baC): \");\nSerial.println(temperatureC);\nhumidity = bme.readHumidity();\nSerial.print(\"Humidity (%): \");\nSerial.println(humidity);\npressure = bme.readPressure() \/ 100.0F;\nSerial.print(\"Pressure (hPa): \");\nSerial.println(pressure);<\/code><\/pre>\n\n\n\n<p>You need to assign a value to each field. If you&#8217;ve created the fields as we did, the first field corresponds to the temperature, the second to the humidity, and the third to the pressure. The following lines assign the corresponding values to each field using the <span class=\"rnthl rntliteral\">setField()<\/span> method\u2014it accepts as arguments the field number and the value:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ set the fields with the values\nThingSpeak.setField(1, temperatureC);\n\/\/ThingSpeak.setField(1, temperatureC);\nThingSpeak.setField(2, humidity);\nThingSpeak.setField(3, pressure);<\/code><\/pre>\n\n\n\n<p>Finally, use the <span class=\"rnthl rntliteral\">writeFields()<\/span> method and set as arguments the channel number and the write API key:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Demonstration<\/h3>\n\n\n\n<p>Upload the previous code to your board\u2014don&#8217;t forget to insert your network credentials, Write API Key and channel number. After uploading, it should connect successfully and send the readigns:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"731\" height=\"525\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Write-Multiple-Fields-ThingSpeak-Serial-Monitor.png?resize=731%2C525&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Write Multiple Fields ThingSpeak Serial Monitor\" class=\"wp-image-103383\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Write-Multiple-Fields-ThingSpeak-Serial-Monitor.png?w=731&amp;quality=100&amp;strip=all&amp;ssl=1 731w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Write-Multiple-Fields-ThingSpeak-Serial-Monitor.png?resize=300%2C215&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/figure><\/div>\n\n\n\n<p>If you go to your ThingSpeak account, under <strong>Private View<\/strong>, you can see three charts with the sensor readings.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"540\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Temperature-Humidity-Pressure-Fields-ESP32.png?resize=750%2C540&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Publish Send Sensor Readings to ThingSpeak Demonstration easiest way\" class=\"wp-image-103385\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Temperature-Humidity-Pressure-Fields-ESP32.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/Thingspeak-Temperature-Humidity-Pressure-Fields-ESP32.png?resize=300%2C216&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial you&#8217;ve learned how to publish readings from a BME280 sensor to ThingSpeak using the ESP32 and the thingspeak-arduino library. You can change the examples to send readings from any other sensors or data from any other source. We have tutorials for the most popular sensors:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-dht11-dht22-temperature-humidity-sensor-arduino-ide\/\">ESP32 with <strong>DHT11\/DHT22 <\/strong>Temperature and Humidity Sensor using Arduino IDE<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-bme680-sensor-arduino\/\">ESP32: <strong>BME680<\/strong> Environmental Sensor using Arduino IDE (Gas, Pressure, Humidity, Temperature)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-ds18b20-temperature-arduino-ide\/\">ESP32 <strong>DS18B20 <\/strong>Temperature Sensor with Arduino IDE (Single, Multiple, Web Server)<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-with-bmp180-barometric-sensor\/\">ESP32 with BMP180 Barometric Sensor \u2013 Guide<\/a><\/li><\/ul>\n\n\n\n<p>You can visualize the sensor readings from anywhere by logging in to your ThingSpeak account.<\/p>\n\n\n\n<p>The library used throughout this tutorial provides several examples that may be useful\u2014<a href=\"https:\/\/github.com\/mathworks\/thingspeak-arduino\" target=\"_blank\" rel=\"noreferrer noopener\">check the examples here<\/a> or in your Arduino IDE go to <strong>File <\/strong>&gt; <strong>Examples <\/strong>&gt; <strong>ThingSpeak, <\/strong>and you&#8217;ll have several examples.<\/p>\n\n\n\n<p>We hope you\u2019ve found this tutorial useful. Learn more about the ESP32 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">More ESP32 Projects and Tutorials\u2026<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;ll learn how to send sensor readings with the ESP32 to ThingSpeak. For demonstration purposes, we&#8217;ll use a BME280 sensor, but you can easily modify the examples &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32 Publish Sensor Readings to ThingSpeak (easiest way)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-thingspeak-publish-arduino\/#more-103345\" aria-label=\"Read more about ESP32 Publish Sensor Readings to ThingSpeak (easiest way)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":103387,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[276,281,277,299,264],"tags":[],"class_list":["post-103345","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32","category-esp32-project","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/04\/ESP32-Send-Sensor-Readings-to-ThingSpeak.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/103345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=103345"}],"version-history":[{"count":9,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/103345\/revisions"}],"predecessor-version":[{"id":104708,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/103345\/revisions\/104708"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/103387"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=103345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=103345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=103345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}