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:
- GND to Ground Pin of Quarky Expansion Board
- VCC to 3.3V or VCC Pin of Quarky Expansion Board
- 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:
- To do this, it first creates objects for the Quarky, ThingSpeak, and IoTHouse classes.
- Then it connects to the ThingSpeak cloud with the given channel number, read key, and write key.
- After this, it enters a while loop and measures the temperature and humidity from the IoT house, and sends the data to the cloud.
- 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.