In this project, you will learn how to send sensor readings to ThingSpeak with an ESP32. This project uses an AGSM sensor, but you can easily modify the example to use a different sensor. ESP32 boards are programmed using VS CODE (platform IDE).
Project OverviewThingSpeak allows you to publish your sensor readings to your website and display them in timestamped charts. You can also visualize your graphs with MATLAB Visualizations, and access your readings from anywhere in the world.
There are several ways to send sensor readings to ThingSpeak. This project uses the thingspeak-arduino library. You can see library examples on our GitHub page.
Things you'll need1. ESP32-DevKitC V4
2. AGSM_CO
Change the uart serial port. ESP32 can change the uart port you want. For the change method, you can change RX2, TX2 in the hardware.cpp(c>.platformio>packages>framework-arduinoespressif32>cores>esp32>HardwareSerial.cpp) file in vs code.
Another way is to click on the Serial function and select Go to Definition.
AGSM Gas SensorAGSM can be easily applied to devices linked to the Internet of Things (IoT) and provides an easy way to monitor sensor values and environmental changes.
- Measurement Range: 0~100ppm
- Accuracy: <5% @ Full Range
- T90 response time): <150 sec
- Operating Input Voltage Range: DC 3.3V ~ 5.0V
- Power Consumption: 5.15mA at 3.3VDC(17mW)
- Resolution: 0.001ppm
An AGSM sensor must be connected to the ESP32 to send data to ThingSpeak.
We will use the AGSM sensor module and Uart communication. To do this, connect the sensor to the main ESP32 RXD (GPIO 17) and TXD (GPIO 16) pins as shown in the following schematic.
SETTING UP THINGSPEAKGo to the thingspeak home page
Sign up and create a New Channel with two fields Temperature and Humidity.
On creating a new channel, you'll get something called the API Keys.
We'll use these later down the line
If you’re using VS Code with the PlatformIO extension, copy the following to the platformio.ini file to include the libraries. And download the Thingspeak library.
To make the code work, you need to insert your network credentials in the following variables:
- #define WIFI_SSID "your wifi ssid"
- #define WIFI_PASSWORD "your wifi pass"
For the code to work, you need to change the channel number and apikey to the following variables.
- const char* myWriteAPIKey = "your write apikey";
- unsigned long myChannelNumber = "your channelnumber";
Open the serial monitor with a baud rate of 115200. After 30 seconds it should connect to Wi-Fi and start posting readings to ThingSpeak.
Go to your ThingSpeak account to the channel you’ve just created, and you’ll see the temperature readings being published and plotted on the chart.
If you want to check more data and data from various sensors as well as CO, please visit the channel below.
Comments