Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Send Sensor Data to Thingspeak with Raspberry Pi Pico W
Raspberry Pi Raspberry Pi Pico W Projects

Send Sensor Data to Thingspeak with Raspberry Pi Pico W

Mamtaz AlamBy Mamtaz AlamUpdated:January 12, 20233 Comments5 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Raspberry Pi Pico W thingspeak DHT11
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this tutorial, we will send the DHT11 Humidity Temperature Sensor Data to Thingspeak Server using Raspberry Pi Pico W Board. The latest Raspberry Pi Pico W brings WiFi to the Pico platform while retaining complete pin compatibility with its older sibling Raspberry Pi Pico.

Earlier we learned Getting Started with Raspberry Pi Pico W in detailed & discussed various method to connect the Pi Pico W to any Wi-Fi Access point. For testing the Wi-Fi capability and working with sensors, Thingspeak is the best platform. ThingSpeak is open-source software that allows users to communicate with internet-enabled devices. It facilitates data access, retrieval, and logging of data by providing an API to both the devices and social network websites.

The DHT11/22 Humidity Temperature sensor is the best sensor for beginners for getting started with any new microcontroller or new programming language. This guide will explain the method to interface the DHT11 Sensor with Raspberry Pi Pico W with MicroPython Code & post the Sensor Data on Thingspeak Server.



Components Required

You need following components for this project. You can buy the Raspberry Pi Pico W Kit from SunFounder which consist the Lipo Charger Module along with other 200+ components.

  1. Raspberry Pi Pico W – 1
  2. DHT11 Sensor – 1
  3. Lipo Battery Charger – 1
  4. Samsung 18650 Battery with Holder – 1
  5. Jumper Wires – 3
  6. Breadboard – 1
  7. Micro-USB Cable.

DHT11 Temperature & Humidity Sensor

DHT11 Temperature & Humidity sensor is a temperature and humidity composite sensor with calibrated digital signal output. It includes a resistive humidity sensing element and an NTC temperature measuring element and is connected to a high-performance 8-bit microcontroller.

DHT11 Sensor

Its application-specific digital module acquisition technology and temperature and humidity sensing technology ensure that the product has extremely high reliability and excellent long-term stability.

There is a dedicated post about DHT11 Raspberry Pi Pico interfacing in one of our previous article. You can go through it for more info.


Interfacing DHT11 Sensor with Raspberry Pi Pico W

Now lets interface the DHT11 Humidity and Temperature Sensor with Raspberry Pi Pico W. The connection is fairly simple.

Raspberry Pi Pico W DHT11 Sensor

Connect the VCC, GND & Output pin of DHT11 Sensor to Raspberry Pi Pico W 3.3V, GND & GP0 Pin respectively.

DHT11 Raspberry Pi Pico W

The Raspberry Pi Pico W has a buck-boost converter IC. Hence you can power the Raspberry Pi Pico W via a Lipo Battery. The Lipo Battery Charger Module which consists of LTC4054 IC has been modified and specially designed for powering Raspberry Pi Pico W using Lipo Battery.

Using the Lipo Charger Module and 3.7V Samsung 18650 Rechargeable Lithium-Ion Battery, you can power the Raspberry Pi Pico W & DHT11 Sensor & make the project portable.

Battery Powered Raspberry Pi Pico W




Setting up Thingspeak

ThingSpeak provides very good tool for IoT based projects. By using the ThingSpeak site, we can monitor our data and control our system over the Internet, using the Channels and web pages provided by ThingSpeak. So first you need to sign up for ThingSpeak. So visit https://thingspeak.com and create an account.

Thingspeak Setup

Then create a new channel and create two variables as shown in the image below.

Then create the API keys. This key is required for programming modifications and receiving data from Raspberry Pi Pico W.

Now click on channels so that you can see the online data streaming.


MicroPython Code

Now let us write a MicroPython code for Raspberry Pi Pico W to send the DHT11 Humidity Temperature Sensor Data to the Thingspeak Server.

To upload the data to Thingspeak Server, the Raspberry Pi Pico W needs to connect to the Wi-Fi network. Then using the API Key the Raspberry Pi Pico W uploads the humidity and temperature data to Thingspeak. You can observe the graphical data in visualized form in Thingspeak dashboard.

The MicroPython Code is has two parts as the DHT11 Sensor requires a library for retrieving the humidity temperature data.


dht.py

Copy the following code as paste it on your Thonny editor. Save the file in Raspberry Pi Pico as dht.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import array
import micropython
import utime
from machine import Pin
from micropython import const
class InvalidChecksum(Exception):
    pass
class InvalidPulseCount(Exception):
    pass
MAX_UNCHANGED = const(100)
MIN_INTERVAL_US = const(200000)
HIGH_LEVEL = const(50)
EXPECTED_PULSES = const(84)
class DHT11:
    _temperature: float
    _humidity: float
    def __init__(self, pin):
        self._pin = pin
        self._last_measure = utime.ticks_us()
        self._temperature = -1
        self._humidity = -1
    def measure(self):
        current_ticks = utime.ticks_us()
        if utime.ticks_diff(current_ticks, self._last_measure) < MIN_INTERVAL_US and (
            self._temperature > -1 or self._humidity > -1
        ):
            # Less than a second since last read, which is too soon according
            # to the datasheet
            return
        self._send_init_signal()
        pulses = self._capture_pulses()
        buffer = self._convert_pulses_to_buffer(pulses)
        self._verify_checksum(buffer)
        self._humidity = buffer[0] + buffer[1] / 10
        self._temperature = buffer[2] + buffer[3] / 10
        self._last_measure = utime.ticks_us()
    @property
    def humidity(self):
        self.measure()
        return self._humidity
    @property
    def temperature(self):
        self.measure()
        return self._temperature
    def _send_init_signal(self):
        self._pin.init(Pin.OUT, Pin.PULL_DOWN)
        self._pin.value(1)
        utime.sleep_ms(50)
        self._pin.value(0)
        utime.sleep_ms(18)
    @micropython.native
    def _capture_pulses(self):
        pin = self._pin
        pin.init(Pin.IN, Pin.PULL_UP)
        val = 1
        idx = 0
        transitions = bytearray(EXPECTED_PULSES)
        unchanged = 0
        timestamp = utime.ticks_us()
        while unchanged < MAX_UNCHANGED:
            if val != pin.value():
                if idx >= EXPECTED_PULSES:
                    raise InvalidPulseCount(
                        "Got more than {} pulses".format(EXPECTED_PULSES)
                    )
                now = utime.ticks_us()
                transitions[idx] = now - timestamp
                timestamp = now
                idx += 1
                val = 1 - val
                unchanged = 0
            else:
                unchanged += 1
        pin.init(Pin.OUT, Pin.PULL_DOWN)
        if idx != EXPECTED_PULSES:
            raise InvalidPulseCount(
                "Expected {} but got {} pulses".format(EXPECTED_PULSES, idx)
            )
        return transitions[4:]
    def _convert_pulses_to_buffer(self, pulses):
        """Convert a list of 80 pulses into a 5 byte buffer
        The resulting 5 bytes in the buffer will be:
            0: Integral relative humidity data
            1: Decimal relative humidity data
            2: Integral temperature data
            3: Decimal temperature data
            4: Checksum
        """
        # Convert the pulses to 40 bits
        binary = 0
        for idx in range(0, len(pulses), 2):
            binary = binary << 1 | int(pulses[idx] > HIGH_LEVEL)
        # Split into 5 bytes
        buffer = array.array("B")
        for shift in range(4, -1, -1):
            buffer.append(binary >> shift * 8 & 0xFF)
        return buffer
    def _verify_checksum(self, buffer):
        # Calculate checksum
        checksum = 0
        for buf in buffer[0:4]:
            checksum += buf
        if checksum & 0xFF != buffer[4]:
            raise InvalidChecksum()



main.py

Here is the main code for Raspberry Pi Pico which establishes WiFi Connections and post the DHT11 Sensor Data to Thinspeak Server.

From the following line, change the WiFi SSID, password and also the Thingspeak API key.

1
2
3
THINGSPEAK_WRITE_API_KEY = 'Y4VSS02J3VFSY0UK'  
ssid = 'BELL685'
password = '644642755D2F'

Here is the final code for the project. You can save this file with any name like main.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import machine
import urequests
from machine import Pin
import network, time
from dht import DHT11, InvalidChecksum
 
HTTP_HEADERS = {'Content-Type': 'application/json'}
THINGSPEAK_WRITE_API_KEY = 'Y4VSS02J3VFSY0UK'  
 
ssid = 'BELL685'
password = '644642755D2F'
 
# Configure Pico W as Station
sta_if=network.WLAN(network.STA_IF)
sta_if.active(True)
 
if not sta_if.isconnected():
    print('connecting to network...')
    sta_if.connect(ssid, password)
    while not sta_if.isconnected():
     pass
print('network config:', sta_if.ifconfig())
 
while True:
    time.sleep(5)
    pin = Pin(0, Pin.OUT, Pin.PULL_DOWN)
    sensor = DHT11(pin)
    t  = (sensor.temperature)
    h = (sensor.humidity)
    print("Temperature: {}".format(sensor.temperature))
    print("Humidity: {}".format(sensor.humidity))
    
    dht_readings = {'field1':t, 'field2':h}
    request = urequests.post( 'http://api.thingspeak.com/update?api_key=' + THINGSPEAK_WRITE_API_KEY, json = dht_readings, headers = HTTP_HEADERS )  
    request.close()
    print(dht_readings)


Monitor DHT11 Sensor Data on Thingspeak with Raspberry Pi Pico W

Run the library and also the main code.

The Raspberry Pi Pico W will connect to the WiFi network and establish connection with the Thingspeak Server. The Python Shell will display the event.

To have a visual representation of Temperature Humidity Data, you can go to the private view of Thingspeak Server Dashboard. The dashboard will have an entry of humidity temperature latest data after an interval of every 15 seconds.

Raspberry Pi Pico W Thingspeak

This is how you can upload any sensor data to Thingspeak Server using Raspberry Pi Pico W, WiFi chip.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleDigital Taxi Fare Meter using Arduino & Speed Sensor
Next Article Raspberry Pi Pico W Web Server Tutorial with MicroPython

Related Posts

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

Updated:July 24, 2025
Interface BMI160 with Raspberry Pi Pico & MicroPython

Interface BMI160 with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Updated:February 2, 202513K
Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Modbus RTU with Raspberry Pi Pico & Micropython

Modbus RTU with Raspberry Pi Pico & MicroPython

Updated:February 2, 20258K
Fever Detector with MLX90640 & OpenCV Raspberry Pi

Thermal Fever Detector with MLX90640 & OpenCV Raspberry Pi

Updated:February 2, 20256K
View 3 Comments

3 Comments

  1. David L Wiener on December 23, 2022 5:53 PM

    I thought I could substitute a DHT22 in place of DHT11 into Your instructions. When I run main.py I get a response that says “connecting to network…” and nothing happens. I’m sure my ThingSpeak Key is accurate, I’m using ThingSpeak and it runs fine with input from a similar Arduino project. I’m trying to put new data from my Pico W into fields 7 and 8.

    I think I don’t get how to “Run the Library and the main code”. I’m new to MicroPython and Pico W and I don’t know what is meant by Run Library, what library? There are two files in these instructions, dht.py and main.py. How do I run two files?

    Any help is greatly appreciated, Thank You!

    Reply
  2. David L Wiener on February 3, 2023 12:34 PM

    Unfortunately I can’t delete previous comments which are not very helpful.

    The following is a link to my DHT22 solution that is working well:
    https://github.com/dlwiener/Pico-W-DHT22-ThingSpeak/blob/main/PicoW%20DHT22%20ThingSpeak

    Reply
    • Admin on February 3, 2023 12:42 PM

      I deleted it dont worry. And thank you for the code.

      Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • Half Wave Rectifier Basics, Circuit, Working & Applications
    Half Wave Rectifier Basics, Circuit, Working & Applications
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.