How artificial intelligence helps in the Internet of Things

Module 4 · Lesson 1 of 5 · Artificial intelligence

In the course Arduino and ESP32 (SR) we built devices that measure temperature, light and motion, and devices that move something – a pump, a servo motor, lights. Until now, decisions were made by rules we wrote ourselves: “if the humidity is below 35%, water the plant”. In this module, decisions will be made by a model that has learned from data.

From sensor to decision

The chain: sensor, data, model, decision, actuator
Every “smart” device works by the same chain
  1. A sensor measures something in the real world (temperature, humidity, light, acceleration, sound).
  2. The measurements become data – numbers.
  3. A model uses the data to conclude what is happening (“the air is stuffy”, “someone is waving”, “the plant is thirsty”).
  4. Based on that conclusion, the device makes a decision.
  5. An actuator (motor, relay, light, speaker) carries out the decision.

Until now, step 3 was an if we wrote ourselves. Now we will learn the rule from data – just like in the lesson “Rules or learning”.

Where AI is used in the Internet of Things

AreaSensorsWhat AI does
smart hometemperature, humidity, motion, power consumptionlearns the habits of the people living there and adjusts the heating and lights by itself
agriculturesoil moisture, temperature, cameraestimates when to water; recognizes a leaf disease in a photo
industryvibrations and sound of a machinenotices “strange” behavior of a machine before it breaks down
health and sportaccelerometer, pulserecognizes walking, running, falling; counts steps
trafficcameras, sensors on the roadestimates traffic jams and adjusts traffic lights
environmentair quality, water levelpredicts pollution or floods

AI in the cloud and AI on the device

Comparison: a model in the cloud and a model on the device itself
A model can run on a server or on the microcontroller itself
  • In the cloud: the device sends data over the internet to a server where a large model runs, and the server sends back an answer. This is how voice assistants work when they understand complex questions.
  • On the device (edge AI, and for small microcontrollers TinyML): a small model runs on the board itself – on an ESP32 or a micro:bit. The answer is instant, it works without the internet and the data never leaves the device. But the model has to be small.

In this module we work on the device: we will train the model on a computer and then transfer it to an ESP32 and a micro:bit.

Module plan

LessonWhat we do
ESP32 collects datathe ESP32 measures, we label the state, Python saves the table
A model from Python on the ESP32a decision tree learns on the computer, then we convert it to C++ for the ESP32
micro:bit recognizes gesturesthe micro:bit learns and recognizes gestures – all on the board itself
TinyMLhow much “intelligence” fits into a small chip and which tools exist
For the class (for teachers): duration 20–30 minutes; materials: –.
Groups choose one area from the table and draw the chain sensor → data → model → decision → actuator for one imaginary device. At the end, each group says whether the model would run in the cloud or on the device, and why.

Common misconceptions

  • “Every smart device has artificial intelligence” – many “smart” devices work only by rules (a timer, a threshold) – and that is often quite enough.
  • “AI always has to run on the internet” – small models also run on the microcontroller itself, without the internet.

Practice tasks

Try it yourself first, and only then open the solution.

  1. Draw the chain sensor → data → model → decision → actuator for a “smart trash can” that recognizes plastic by itself.
  2. Name two advantages and one disadvantage of a model that runs on the device itself.
  3. The automatic watering from the Arduino and ESP32 course has the rule “if the humidity is below 35% – water”. What could a model learn better than this rule?
Solution 1: one possible solution

sensor: camera (and scale) → data: photo and mass of the object → model: image recognition (plastic / paper / glass) → decision: “plastic” → actuator: a motor opens the right compartment.

Solution 2: answer

Advantages: it works without the internet, it answers immediately, the data stays on the device (privacy), it uses less data. Disadvantage: the model has to be small, so it is less “smart” than large models in the cloud.

Solution 3: ideas

For example: to take into account the temperature and the time of day (in summer evenings more water is needed), to learn how quickly the soil dries after watering, or to recognize from a photo of a leaf that the plant is thirsty. For that we would need data: measurements and labels “the plant needed water” or “it didn't”.

Check your knowledge

Open the quiz

Quiz: AI and the Internet of Things

1. What is the correct order in a “smart” device?




2. What is the advantage of a model that runs on the device itself?




3. What is machine learning on very small chips called?




4. What is an actuator?