• Home
  • Examples
  • Sending Temperature and Humidity Data from IoT House to ThingSpeak Cloud

Sending Temperature and Humidity Data from IoT House to ThingSpeak Cloud

Example Description
Connect your IoT house to the ThingSpeak cloud using PictoBlox Python Environment and send temperature and humidity data every 20 seconds.

In this example, we will send the humidity and temperature sensor data to the cloud on the ThingSpeak servers using PictoBlox Python Environment.

ThingSpeak Channel

Create a channel on ThingSpeak with 2 fields – Temperature and Humidity.

DHT Sensor Connection to Quarky

DHT sensors have 3 pins: GND, VCC, and Signal. You have to connect the following 3 pins to the Quarky Expansion Board:

  1. GND to Ground Pin of Quarky Expansion Board
  2. VCC to 3.3V or VCC Pin of Quarky Expansion Board
  3. Signal to the D3 (Digital Pin) of the Quarky Expansion Board

Script

This code helps to send temperature and humidity data from an IoT house to the ThingSpeak cloud every 20 seconds:

  1. To do this, it first creates objects for the Quarky, ThingSpeak, and IoTHouse classes.
  2. Then it connects to the ThingSpeak cloud with the given channel number, read key, and write key.
  3. After this, it enters a while loop and measures the temperature and humidity from the IoT house, and sends the data to the cloud.
  4. Finally, it waits for 20 seconds before sending the next set of data.
# The following code connects to the ThingSpeak cloud and sends temperature and humidity data from an IoT house every 20 seconds. 
# The code first creates objects for the Quarky, ThingSpeak and IoTHouse classes. 
quarky = Quarky() 
import time 
ts = ThingSpeak() 
house = IoTHouse() 

# Next, the code connects to the ThingSpeak cloud using the given channel number, read key and write key. 
ts.connecttoThingSpeak(1908986, "KCVAWGG8Q4X9OM2L", "VQ8IAZ2MPFECXIO4") 

# Then, the code enters a while loop and measures the temperature and humidity from the IoT house and sends the data to the cloud. 
while True: 
  Temp = house.dhtmeasure(1, "D3") 
  Hum = house.dhtmeasure(2, "D3") 
  ts.sendmultipledatatocloud(2, Temp, Hum, 100, 100, 100, 100, 100, 100) 
  time.sleep(20)  # The code then waits for 20 seconds before sending the next set of data.

 

Output

Table of Contents