How artificial intelligence helps in the Internet of Things
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
- A sensor measures something in the real world (temperature, humidity, light, acceleration, sound).
- The measurements become data – numbers.
- A model uses the data to conclude what is happening (“the air is stuffy”, “someone is waving”, “the plant is thirsty”).
- Based on that conclusion, the device makes a decision.
- 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
| Area | Sensors | What AI does |
|---|---|---|
| smart home | temperature, humidity, motion, power consumption | learns the habits of the people living there and adjusts the heating and lights by itself |
| agriculture | soil moisture, temperature, camera | estimates when to water; recognizes a leaf disease in a photo |
| industry | vibrations and sound of a machine | notices “strange” behavior of a machine before it breaks down |
| health and sport | accelerometer, pulse | recognizes walking, running, falling; counts steps |
| traffic | cameras, sensors on the road | estimates traffic jams and adjusts traffic lights |
| environment | air quality, water level | predicts pollution or floods |
AI in the cloud and AI on the device
- 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
| Lesson | What we do |
|---|---|
| ESP32 collects data | the ESP32 measures, we label the state, Python saves the table |
| A model from Python on the ESP32 | a decision tree learns on the computer, then we convert it to C++ for the ESP32 |
| micro:bit recognizes gestures | the micro:bit learns and recognizes gestures – all on the board itself |
| TinyML | how much “intelligence” fits into a small chip and which tools exist |
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.
- Draw the chain sensor → data → model → decision → actuator for a “smart trash can” that recognizes plastic by itself.
- Name two advantages and one disadvantage of a model that runs on the device itself.
- 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?
