lesson
30 min

Connected Devices, Everyday

The Internet of Things connects sensors and devices to the internet. Learn the four-step chain and write a sensor alert.

What you will be able to do

By the end of this lesson, you can explain the sensor, network, data, action chain and write a simple sensor alert in Python.

What IoT is

The Internet of Things (IoT) means everyday objects with sensors that connect to the internet. A sensor is a small part that measures something, like temperature, motion, light, or location.

You may already live with IoT: a smart thermostat, a video doorbell, a fitness watch, a smart speaker, or the GPS tracker that shows when a school bus is near.

The four-step chain

Every IoT system follows the same chain:

  1. Sense. A sensor measures something. The fridge is 41 degrees.
  2. Send. The device sends that reading over Wi-Fi, a cell network, or another connection.
  3. Decide. Software compares the reading to a rule. Is 41 too warm?
  4. Act. The system does something. It sends a text alert or turns on a fan.

If any link breaks, the system fails. A dead battery, a weak signal, or a wrong rule can all stop the alert from coming.

Where IoT helps

ProblemIoT approachExample
Food spoils when a fridge fails overnightTemperature sensor sends a text alertFood banks and restaurants
Water leaks cause hidden damageLeak sensor under a sinkHomes and apartment buildings
Families wait in the cold for a busGPS on buses shares arrival timesBus tracking apps used by school districts
Cities do not know where air is unhealthyLow-cost air sensors share readingsCommunity air monitoring networks

Write a sensor alert

The code below checks eight hourly temperature readings from a fridge sensor. It flags any reading above the safe limit. The first run downloads the Python runtime, which is several MB.

Run the code. Then change limit to 42 and run it again. How many alerts now? Which setting would you trust to protect food for families?
Python 3
Ctrl+Enter to run | Tab to indent | Python runs in your browser via Pyodide
# Temperature readings (Fahrenheit) from a sensor in a food pantry fridge
readings = [37, 38, 38, 39, 41, 43, 44, 40]
limit = 40

alerts = 0
for hour, temp in enumerate(readings):
    if temp > limit:
        alerts = alerts + 1
        print("Hour", hour, "ALERT:", temp, "is too warm")

print("Alerts:", alerts)

The rule is the judgment. Set it too high and food spoils. Set it too low and people stop paying attention to constant alerts. A real system also needs a person who gets the text and knows what to do.

Reflection

Private. Saved only in this browser. No one else can see it.

Go deeper: The Internet of Things, Demystified

Ask. Answer. Build together.