As an Amazon Associate we earn from qualifying purchases.
Sometimes a plot on your own screen is not enough. You may want to check a sensor reading from your phone, share a chart with someone else, or keep a record that stays online when your computer is off. ThingSpeak is a free IoT analytics service that can store numeric data in the cloud and draw it as a live chart. Python can send data to it with a few lines of code.
This article explains how plotting data on the internet with Python and ThingSpeak works, what you need, and how to send your first values. The video below shows the process in action.
What ThingSpeak does
ThingSpeak organizes data into channels. Each channel has several fields (up to eight), and each field holds one series of values, such as temperature, humidity or voltage. Every time you send a value, ThingSpeak stores it with a timestamp and updates the chart for that field.
You talk to ThingSpeak over plain HTTP. That means any device or program that can make a web request can send data, including a Python script on a PC, a Raspberry Pi, or a laptop connected to an Arduino.
What you need
- A computer with Python 3 installed.
- The requests library (install it with pip install requests).
- A free ThingSpeak account.
- An internet connection.
- Optionally, a sensor or microcontroller that produces real readings.
Step 1: Create a channel
- Sign in to ThingSpeak and choose the option to create a new channel.
- Give the channel a name and a short description.
- Tick Field 1 and give it a label, for example “Temperature”. Add more fields if you plan to send more than one value.
- Save the channel.
ThingSpeak will create a default chart for each field you enabled. It stays empty until the first data arrives.
Step 2: Find your API keys
Open your channel and go to the API Keys tab. You will see a Write API Key and a Read API Key. The Write key is the one your Python script uses to send data. Treat it like a password: anyone who has it can add data to your channel, so do not post it in screenshots or public code.
Step 3: Send data from Python
ThingSpeak accepts updates through a simple request to its update address. You pass your Write key and the values for each field as parameters. In Python with the requests library, one update looks like this:
requests.get(“https://api.thingspeak.com/update”, params={“api_key”: “YOUR_WRITE_API_KEY”, “field1”: 24.5})
If the update works, ThingSpeak replies with the number of the new entry in your channel. If it replies with 0, the update was not accepted. The usual causes are a wrong key or sending updates too quickly.
To plot a continuous stream, put this call inside a loop. Generate or read a value, send it, print the response so you can see whether it worked, and then wait before the next update. A simple version of the script follows this order:
- Import requests and time.
- Store your Write key and the update address in variables.
- Start a loop that reads or generates a number.
- Send the number as field1.
- Print the reply, then pause with time.sleep().
For a first test, you can use random numbers in place of a sensor. That lets you confirm that the chart works before you connect any hardware.
Mind the update rate
Free ThingSpeak accounts limit how often a channel can be updated. If you send values too fast, the extra updates are ignored. Check the current limits on the ThingSpeak site and set your delay in the loop to stay safely above the minimum interval. A pause of a few tens of seconds is a sensible starting point for slowly changing values such as room temperature.
Sending several values at once
You can fill more than one field in a single request by adding field2, field3 and so on to the parameters. This keeps related readings under the same timestamp and uses fewer updates than sending each value separately.
Step 4: Use real sensor data
Once the test works, replace the random number with a real reading. A common setup is a microcontroller that measures something and sends it to the computer over a serial port, while Python forwards it to ThingSpeak. Our guide on how to send or receive serial data in Python covers the serial side, including reading from an Arduino or an XBee module.
If you want a concrete sensor example, you can display temperature in Python with an Arduino and an LM35 sensor, then add the ThingSpeak request to the loop so each reading is also uploaded.
Remember to convert the serial text to a number first, for example with float(), and to skip any empty or malformed lines so they do not break the loop.
Step 5: View and share the chart
Open the channel page on ThingSpeak. The field chart updates as new values arrive. You can adjust the chart title, axis labels, colors and the number of points shown. If you want others to see it, you can make the channel public or embed the chart in a web page. Keep it private if the data is not meant to be shared.
ThingSpeak also lets you download the stored data, which is useful if you want to do deeper work offline. For ideas on that, see Arduino data analysis with Python and our article on data visualization with charts and graphs.
Troubleshooting
- The response is 0: check the Write key, make sure you are not updating too often, and confirm the field names match your channel.
- Nothing appears on the chart: refresh the page, and check that you sent data to the right field number.
- The script stops with a connection error: check your internet connection and wrap the request in a try/except block so one failed request does not end the program.
- Values look wrong: print the value before sending it, and check units and any scaling you apply.
When this approach makes sense
Uploading to ThingSpeak suits slow, low-volume data like temperature, humidity, power use or battery level. It is not meant for fast signals that change many times per second. For those, plot locally or log to a file and upload a summary instead.
If you later want to control hardware over the internet as well as read data from it, the same kind of web requests can be used in the other direction.
FAQ
Is ThingSpeak free?
ThingSpeak offers a free tier for small, non-commercial projects, with limits on update rate and message volume. The details can change, so check the current terms on the ThingSpeak website.
Do I need an Arduino to use ThingSpeak with Python?
No. Any Python script that can make a web request can send data. An Arduino or other sensor board is only needed if you want real-world readings instead of test values.
Can I send more than one value at a time?
Yes. A channel supports up to eight fields, and you can set several of them in the same request by adding field1, field2 and so on to the parameters.
Why is my data not showing up on the chart?
The most common reasons are a wrong Write API Key, sending updates faster than the allowed interval, or using a field number that is not enabled in the channel. Print the server’s reply in your script to see whether each update was accepted.