Back to Hub | RP2040 MicroPython Lab
Logic & Protocol Engine Active

🌡️ Automated Greenhouse Roof & Single-Wire Protocol

Learn how the DHT11 communicates using a 40-bit Single-Bus Protocol before evaluating compound boolean logic (if ... and ..., elif).

🌱 Greenhouse Structure & Roof Motor Roof: CLOSED • Motor: OFF
Temp: 25.0°C Humidity: 50.0% ROOF MOTOR DHT FAN
🎛️ Climate Environmental Controls
25.0 °C
15°C (Cool) 30°C (Warm Threshold) 45°C (Extreme Heat)
50.0 %
20% (Dry) 70% (High Moisture Threshold) 95% (Saturated)
📡 DHT11 Single-Wire Communication Protocol 40-Bit Frame

When sensor.measure() runs, RP2040 pulls GP15 LOW for 18ms to signal start. The DHT11 responds with 40-bit Pulse-Width Modulated data (16-bit Humidity, 16-bit Temp, 8-bit Checksum):

MCU 18ms LOW ACK 80µs Bit 0 (26µs) Bit 1 (70µs)
Humidity (16-bit): 00110010 00000000
Temp (16-bit): 00011001 00000000
Checksum (8-bit): 01001011
🐍 MicroPython Logic Inspector RP2040 Executing
import dht, machine, time
sensor = dht.DHT11(machine.Pin(15)) # Single-wire GP15
in1 = machine.Pin(16, machine.Pin.OUT) # Roof Motor CW
in2 = machine.Pin(17, machine.Pin.OUT) # Roof Motor CCW
fan = machine.Pin(18, machine.Pin.OUT) # Exhaust Fan

while True:
  sensor.measure() # Triggers 40-bit Single-Bus Read
  temp = sensor.temperature() # 25.0°C
  hum = sensor.humidity() # 50.0%

  # Compound Condition: HIGH Temp AND HIGH Humidity
  if temp > 30 and hum > 70:
    in1.value(1); in2.value(0) # Close Roof (Protect)
    fan.value(1) # Turn ON Exhaust Fan
  elif temp > 32:
    in1.value(0); in2.value(1) # Open Roof (Vent Heat)
    fan.value(0) # Fan OFF
  else:
    in1.value(0); in2.value(0) # Motor STOP
    fan.value(0) # Fan OFF

  time.sleep(2)
📝 Compound Logic & Protocol Quiz
How does the RP2040 differentiate between a binary '0' and a binary '1' in the DHT11 single-wire data stream?