Sensing the world · Lesson 3 of 5· 18 min

Watching temperature and damp

Why this matters

Heat and damp spoil stored food. Maize and rice that get damp can grow mould, and the loss can be a family's income for months.

Example

Teaching scenario (fictional)

Achieng stores maize for a farmers' group near Kisumu. She wants a light to come on when the store gets too warm or too humid, so the group can open it to air.

The DHT22 sensor

The DHT22 measures temperature and humidity (how much water is in the air) on one data wire.

Open a tool

Wokwi simulator

Free, nothing to install. Works best on a laptop; on a phone you can still read the steps and the code below.

Opens wokwi.com in a new tab. Come back here when you are done.

Open Wokwi simulator

Step by step

  1. Add a DHT22 in Wokwi.

  2. Wire VCC to 3V3, GND to GND and SDA to GP15.

  3. Add an LED with its resistor on GP16, as in the earlier course.

from machine import Pin
import dht
import time

sensor = dht.DHT22(Pin(15))
warning = Pin(16, Pin.OUT)

while True:
    sensor.measure()
    temp = sensor.temperature()     # degrees Celsius
    damp = sensor.humidity()        # percent
    print(temp, "C", damp, "%")
    if temp > 30 or damp > 70:
        warning.value(1)
    else:
        warning.value(0)
    time.sleep(2)

Click the sensor in the simulator to change the temperature and humidity, and watch the light.

Where do 30 and 70 come from?

They are examples. For a real store, ask someone who knows the crop, such as an agriculture extension officer, what is safe, and use their numbers. A sensor project is only as good as its limits.

You’re reading for free. Sign in to save your progress, ask questions on any lesson, and earn a certificate when you finish.Sign in to keep my progress →

Lesson 3 of 5