What Is IoT? Internet of Things Explained With ESP32 Examples
What is IoT and how does it work? Sensor, network and cloud layers, Wi-Fi vs BLE, LoRa and Zigbee, Blynk and Home Assistant, and a first ESP32 IoT device.
IoT (the Internet of Things) means ordinary objects fitted with sensors that connect to the internet or a local network, share what they measure and accept commands remotely. So what is IoT in one line? A device measures something, sends it over a network, software looks at the data and decides, and if needed sends a command back to the device. A smart plug, a thermostat that reports to your phone, a bin that says when it's full and a field sensor that starts irrigation when the soil dries out are all IoT devices.
In this guide you'll learn the four layers that make up IoT (sensor, microcontroller, network and cloud), how Wi-Fi, Bluetooth Low Energy, LoRa and Zigbee differ, and which job platforms like Blynk, ThingSpeak and Home Assistant are good for. Then you'll build a first IoT device that sends temperature to the internet with an ESP32 and a DHT22, do the same on a Raspberry Pi Pico W in MicroPython, and look at the most neglected side of IoT: security and privacy.

What is IoT and how does it work?
Kevin Ashton first used the term in 1999, in a presentation about tracking products in a supply chain with RFID tags. Today it means much more: once small Wi-Fi chips became cheap, it became possible to give almost any object a "voice". Picture an IoT system with a water tank. An ultrasonic sensor in the lid measures the distance to the water surface, the ESP32 turns that distance into a fill percentage and sends it over Wi-Fi to a server; the server adds the value to a chart and sends a notification to your phone when the level drops below 20 percent. If you like, a command coming back the same way can switch the relay that runs the pump. Measure, send, decide, act: every IoT device is a version of this loop.
The four layers of IoT: sensor, microcontroller, network and cloud
| Layer | Job | Example parts | In the water tank example |
|---|---|---|---|
| 1. Sensing and actuation | Measure or change the physical world | DHT22, HC-SR04, PIR, relay, servo | The HC-SR04 measures the distance to the water |
| 2. Microcontroller (edge device) | Read, process and package the measurement | ESP32, Raspberry Pi Pico W, ESP8266 | The ESP32 turns distance into a fill percentage |
| 3. Network (connectivity) | Carry the data from the device to a server | Wi-Fi, BLE, LoRa, Zigbee, 4G | Home Wi-Fi and the router's internet connection |
| 4. Cloud and application | Store, display, decide, notify | ThingSpeak, Blynk, Home Assistant | A chart is drawn and an alert fires below 20% |
Thinking in layers tells you where to look when something breaks. If no values arrive, check the sensor wiring first, then the Wi-Fi connection, and only then the server settings. Also, not every decision has to go to the cloud: making safety decisions such as "stop the pump at once when the level falls to 5 percent" on the device itself keeps the system behaving correctly even when the internet is down. This is called edge computing, and well-designed IoT devices have it in common.
Everyday IoT examples
- Smart home: plugs and lights you switch from your phone, an alert when a door opens, a thermostat that works room by room.
- Energy monitoring: meters that read live consumption and predict the monthly bill in advance.
- Agriculture: systems that open drip irrigation based on soil moisture and run a fan when the greenhouse gets too warm.
- Health: wearables that measure heart rate and blood oxygen and pass them on to a doctor.
- Cities and transport: sensors that show empty parking spaces, GPS trackers that publish where buses are.
- Industry (IIoT): machines that watch motor vibration and flag maintenance before a breakdown.
Which board for IoT? ESP32, Pico W, ESP8266 and Arduino
| Board | Wireless | Programming | When to choose it |
|---|---|---|---|
| ESP32 (WROOM-32) | 2.4 GHz Wi-Fi, Bluetooth Classic and BLE | Arduino IDE (C++), MicroPython, ESPHome | First choice for most IoT projects |
| ESP32-C6 / ESP32-H2 | C6: Wi-Fi 6, BLE, Zigbee and Thread; H2: BLE, Zigbee and Thread (no Wi-Fi) | Arduino IDE, ESP-IDF | Zigbee, Thread and Matter devices |
| Raspberry Pi Pico W / Pico 2 W | 2.4 GHz Wi-Fi and BLE | MicroPython, C/C++, Arduino IDE | If you want to learn with Python |
| ESP8266 (NodeMCU, Wemos D1 mini) | 2.4 GHz Wi-Fi only | Arduino IDE, MicroPython | Simple Wi-Fi devices with one sensor |
| Arduino Uno R3 | None; needs an add-on module | Arduino IDE | Projects without Wi-Fi or with a LoRa module |
| Arduino Uno R4 WiFi | Wi-Fi and BLE (ESP32-S3 co-processor) | Arduino IDE, Arduino Cloud | IoT projects that need Uno compatibility |
If you're just starting, the ESP32 is the easiest way in: Wi-Fi and Bluetooth are inside the chip, it's programmed with the commands you know from the Arduino IDE, and nearly every IoT library is written for it first. If you like Python, the Pico W is a good alternative. The classic Arduino Uno has no wireless; adding Wi-Fi takes a module such as the ESP-01, which makes both the wiring and the code harder. That's why you mostly see the Uno in projects that don't need Wi-Fi, or that send data over long distances with a LoRa module.
IoT communication protocols: Wi-Fi, BLE, LoRa and Zigbee
| Protocol | Typical range | Data rate | Power use | Best for |
|---|---|---|---|---|
| Wi-Fi (2.4 GHz) | 20–50 m indoors | Megabits per second | High (100–250 mA while sending) | Mains-powered devices, cameras, frequent data |
| Bluetooth Low Energy (BLE) | 10–30 m | 1–2 Mbit/s (PHY rate) | Very low | Wearables and battery sensors that pair with a phone |
| LoRa / LoRaWAN | 2–5 km in town, 10 km or more in open country | 0.3–27 kbit/s | Very low | Remote spots with little data: fields, storage, water meters |
| Zigbee / Thread | 10–30 m per device, whole house via mesh | 250 kbit/s | Low | Battery home sensors, bulbs, Matter devices |
| ESP-NOW | 100–200 m in the open | 250 bytes per packet | Low | Fast ESP32-to-ESP32 messages without a router |
| Cellular (4G, LTE-M, NB-IoT) | Wherever the carrier covers | From kbit/s to Mbit/s | Medium to high | Vehicles, boats, remote cabins with no Wi-Fi |
When you choose, you weigh three things: range, amount of data and energy. Physics doesn't negotiate here; a signal that travels far either travels slowly or costs a lot of energy. LoRa covers several kilometres to the far end of a field but carries only a few hundred bytes a second, so it's no good for photos. Wi-Fi moves megabytes per second but can drain a battery device in days, which is why battery sensors put the ESP32 into deep sleep between readings. LoRa frequencies depend on the region: Europe uses 868 MHz and North America 915 MHz, so buy the module that matches where you live. For details see the LoRa module and ESP-NOW guides.
How is the data packaged? HTTP, MQTT and WebSocket
Wi-Fi or LoRa is the road the data travels on; HTTP, MQTT and WebSocket are the language spoken on that road. HTTP is the request-response method web pages use: the device says "store this value", the server answers and the connection closes. It's the easiest to set up, and services such as ThingSpeak accept data this way. MQTT is a lightweight publish-subscribe system designed for IoT: devices stay connected to a server called a broker, publish their reading to a topic, and everyone subscribed to that topic gets the message instantly. Home Assistant and most industrial systems speak MQTT; you'll find the setup in the ESP32 MQTT and Home Assistant guide. WebSocket is a line that stays open between a browser and the device, used for live dashboards that update without reloading the page.
IoT platforms: Blynk, ThingSpeak, Home Assistant and more
| Platform | Where it runs | Strength | Watch out for |
|---|---|---|---|
| Blynk | Blynk cloud and phone app | Drag-and-drop phone interface without code | Device and feature limits on the starter plan |
| ThingSpeak | MathWorks cloud | Every field becomes a chart automatically, MATLAB analysis | Personal accounts update at most every 15 seconds |
| Home Assistant | A Raspberry Pi or mini PC at home | Open source, data stays at home, thousands of integrations | Setup and maintenance are up to you |
| Arduino Cloud | Arduino cloud | Built into the Arduino IDE, generates the skeleton code | Advanced features need a subscription |
| Node-RED and Mosquitto | Your own computer or server | Visual flow-based automation plus an MQTT broker | You build the dashboard and rules yourself |
Your first IoT device with an ESP32: step by step
Enough theory: let's build a real device that sends temperature and humidity to the internet every 20 seconds. You need an ESP32 DevKit, a DHT22 (AM2302) sensor, three jumper wires, a breadboard and a ThingSpeak account. Setup takes less than half an hour.
- Install the ESP32 board package in the Arduino IDE and choose ESP32 Dev Module under Tools > Board.
- Install Adafruit's DHT sensor library from the Library Manager and accept Adafruit Unified Sensor as a dependency.
- Create a ThingSpeak account, add a channel with New Channel, and name Field 1 "Temperature" and Field 2 "Humidity".
- Copy the Write API Key from the channel's API Keys tab.
- Wire the DHT22 as in the table below, replace the Wi-Fi name, password and API key in the code with yours, and upload.
- Open the Serial Monitor at 115200 baud; you should see an entry number after every upload. After a few minutes the charts in your ThingSpeak channel start to fill.
| DHT22 pin | ESP32 pin | Note |
|---|---|---|
| VCC (+) | 3V3 | Power it from 3.3 V; ESP32 pins aren't 5 V tolerant |
| DATA (OUT) | GPIO 4 | On a bare sensor, a 10 kΩ resistor between DATA and 3V3; modules have it built in |
| GND (-) | GND | Common ground |
1// ESP32 + DHT22: ilk IoT cihazı, ölçümü ThingSpeak'e gönderir / first IoT device, sends readings to ThingSpeak
2#include <WiFi.h>
3#include <HTTPClient.h>
4#include <DHT.h>
5
6const char* WIFI_SSID = "AgAdi"; // Wi-Fi adın / your Wi-Fi name
7const char* WIFI_PASS = "Sifre123"; // Wi-Fi şifren / your Wi-Fi password
8const char* API_KEY = "XXXXXXXXXXXXXXXX"; // ThingSpeak Write API Key
9
10const int DHT_PIN = 4; // DHT22 veri pini / DHT22 data pin
11const unsigned long SEND_INTERVAL = 20000; // 20 sn; ThingSpeak en az 15 sn ister / ThingSpeak needs at least 15 s
12
13DHT dht(DHT_PIN, DHT22);
14unsigned long lastSend = 0;
15
16void connectWiFi() {
17 if (WiFi.status() == WL_CONNECTED) return;
18 Serial.print("Wi-Fi'ye bağlanıyor / connecting");
19 WiFi.begin(WIFI_SSID, WIFI_PASS);
20 unsigned long start = millis();
21 while (WiFi.status() != WL_CONNECTED && millis() - start < 15000) { // en fazla 15 sn / at most 15 s
22 delay(500);
23 Serial.print(".");
24 }
25 Serial.println(WiFi.status() == WL_CONNECTED ? " OK" : " zaman aşımı / timeout");
26}
27
28void setup() {
29 Serial.begin(115200);
30 dht.begin();
31 WiFi.mode(WIFI_STA);
32 connectWiFi();
33}
34
35void loop() {
36 if (millis() - lastSend < SEND_INTERVAL) return;
37 lastSend = millis();
38
39 float t = dht.readTemperature(); // °C
40 float h = dht.readHumidity(); // %
41 if (isnan(t) || isnan(h)) {
42 Serial.println("DHT22 okunamadı / read failed");
43 return;
44 }
45
46 connectWiFi(); // bağlantı koptuysa yeniden dene / reconnect if dropped
47 if (WiFi.status() != WL_CONNECTED) return;
48
49 HTTPClient http;
50 String url = String("http://api.thingspeak.com/update?api_key=") + API_KEY +
51 "&field1=" + String(t, 1) + "&field2=" + String(h, 1);
52 http.begin(url);
53 int code = http.GET(); // 200 = sunucu cevap verdi / server replied
54 String body = http.getString(); // "0" ise kayıt reddedildi / "0" means rejected
55 http.end();
56
57 Serial.printf("T=%.1f C H=%.1f %% HTTP %d kayıt / entry: %s\n", t, h, code, body.c_str());
58}After joining Wi-Fi, the code uses millis() to take a reading every 20 seconds, adds it to a web address as parameters and sends it with an HTTP GET request. ThingSpeak returns an increasing number for every successful entry; if it returns 0, you sent too often or the API key is wrong. If the connection drops, connectWiFi() retries for at most 15 seconds and the board waits for the next round instead of locking up. If the sensor can't be read (isnan), that round is skipped instead of sending an empty value, so your chart doesn't fill up with meaningless zeros.
The same device on a Raspberry Pi Pico W (MicroPython)
If you prefer Python, you can build the same device with a Raspberry Pi Pico W. Flash the Pico W build of MicroPython with Thonny, then save the code below as main.py. There's no external sensor in this example: it reads the temperature sensor inside the RP2040, so you can try it with just the board. Because this sensor measures the chip's own temperature, it can read a few degrees above room temperature; for real measurements add a DHT22 or DS18B20.
1# Pico W: dahili sıcaklık sensörünü ThingSpeak'e gönderir / sends the internal temperature sensor to ThingSpeak
2import network, time
3from machine import ADC
4try:
5 import urequests as requests
6except ImportError:
7 import requests
8
9WIFI_SSID = "AgAdi" # Wi-Fi adın / your Wi-Fi name
10WIFI_PASS = "Sifre123" # Wi-Fi şifren / your Wi-Fi password
11API_KEY = "XXXXXXXXXXXXXXXX" # ThingSpeak Write API Key
12
13sensor = ADC(4) # RP2040 dahili sıcaklık sensörü / internal temperature sensor
14wlan = network.WLAN(network.STA_IF)
15wlan.active(True)
16wlan.connect(WIFI_SSID, WIFI_PASS)
17while not wlan.isconnected():
18 time.sleep(0.5)
19print("IP:", wlan.ifconfig()[0])
20
21def read_temp():
22 volts = sensor.read_u16() * 3.3 / 65535
23 return 27 - (volts - 0.706) / 0.001721 # veri sayfası formülü / datasheet formula
24
25while True:
26 t = read_temp()
27 if not wlan.isconnected(): # bağlantı koptuysa yeniden bağlan / reconnect if dropped
28 wlan.connect(WIFI_SSID, WIFI_PASS)
29 time.sleep(5)
30 continue
31 try:
32 r = requests.get("http://api.thingspeak.com/update?api_key=%s&field1=%.1f" % (API_KEY, t))
33 print("T=%.1f C, kayıt / entry:" % t, r.text)
34 r.close()
35 except OSError as e:
36 print("Gönderilemedi / send failed:", e)
37 time.sleep(20) # ThingSpeak en az 15 sn ister / needs at least 15 sPut the two programs side by side and you see the essence of IoT: whichever board or language you pick, the steps are the same. Join the network, measure, package the reading in a set format, send it, check the reply, and retry if the connection drops. For examples where the Pico W serves its own web page, see the Pico W Wi-Fi and web server guide.
IoT security and privacy: connect your device without leaving the door open
Because IoT devices are cheap and small, security often gets left for later. In 2016 the Mirai malware took over hundreds of thousands of cameras and routers whose default passwords had never been changed and knocked major websites offline for hours. The devices you build live on the same network, and these habits remove most of the risk:
- Don't keep default passwords: if your device has a web panel or OTA updates, always set a password, and a different one per device.
- Use a separate network: put your devices on the router's guest network or a dedicated IoT network; if one is compromised, it can't reach your computer.
- Don't open ports on the router: to reach your device from outside, use outgoing connections such as a Telegram bot, an MQTT broker or a VPN instead of port forwarding.
- Encrypt the connection: prefer HTTPS and MQTT over TLS on devices that accept commands; with plain HTTP anyone on the same network can read the traffic.
- Keep it updated: update libraries and the board package, and add OTA updates to devices in the field.
- Collect little data: don't record personal data such as camera images, location or audio unless you need to; if you do, keep it on a local server and know who can see it.
IoT project ideas for beginners
- Wi-Fi thermometer: run the code above with a DHT11 or DHT22 and watch the chart on your phone.
- Motion alert: when a PIR sensor detects someone, have a Telegram bot message your phone.
- Smart plug: switch a lamp from a web page or a voice assistant with a relay module; the steps are in the ESP32 smart plug guide.
- Plant watering: run a mini pump when the soil dries out and send the moisture chart to the cloud.
- Bluetooth sensor: broadcast the reading straight to your phone with BLE, no router needed.
- Going further: for 15 complete projects with MQTT, Home Assistant and the cloud, move on to the ESP32 IoT projects guide.
Common mistakes and how to fix them
- The ESP32 won't connect to Wi-Fi: the network may be 5 GHz; the ESP32 and Pico W only see 2.4 GHz. For other causes see ESP32 won't connect to Wi-Fi.
- ThingSpeak returns entry 0: you're sending more often than every 15 seconds, or you used the Read API Key; use the Write API Key.
- The board freezes after a few hours: it gets stuck in an endless while loop when the connection drops; use a reconnect with a timeout.
- Analog readings go wrong when Wi-Fi is on: the sensor is on one of the ESP32's ADC2 pins; move it to GPIO 32–39.
- The board resets at random: current jumps to 250 mA when Wi-Fi transmits and a weak USB cable can't supply it; use a good cable and add a 100 µF capacitor between 3V3 and GND.
- The battery is flat in two days: Wi-Fi is always on; go to deep sleep between readings and work out the consumption with the battery life calculator.
IoT may sound like a big concept, but at its core it's a small device that measures, sends and decides, and you can build your first one in an evening. If you want to keep going, the ESP32 projects in the BlueGrays app walk you step by step through IoT examples such as Wi-Fi connection, a web server, WebSocket, a weather API and a Telegram alarm, each with its circuit diagram and code.
Frequently asked questions
What is IoT in simple words?
IoT, the Internet of Things, is the network of everyday objects that have sensors and a wireless chip, so they can send what they measure over the internet and be controlled remotely. A smart plug you switch from your phone or a thermostat that reports the room temperature are typical examples.
What are some examples of IoT devices?
Common IoT devices include smart plugs, bulbs and thermostats, video doorbells, fitness trackers, connected energy meters, GPS trackers and soil moisture sensors in farming. In industry, connected machines that report vibration or temperature for predictive maintenance are also IoT.
Is Alexa an IoT device?
An Amazon Echo smart speaker is itself an internet-connected device, and it often acts as the hub that controls other IoT devices such as plugs and lights. The voice assistant Alexa is the cloud service behind it rather than a device on its own.
What are the four components of IoT?
An IoT system is usually described in four parts: sensors and actuators, a microcontroller or device that processes the data, the network that carries it (Wi-Fi, BLE, LoRa, cellular) and a cloud or application layer that stores, displays and acts on it.
Is Arduino an IoT device?
A classic Arduino Uno isn't, because it has no Wi-Fi or Bluetooth. It becomes part of an IoT system with an added Wi-Fi or LoRa module, and boards such as the Arduino Uno R4 WiFi or the ESP32 are IoT-ready out of the box.
What is the difference between IoT and IIoT?
IIoT, the Industrial Internet of Things, applies the same idea to factories, energy and logistics. It focuses on reliability, industrial protocols such as Modbus and OPC UA, and predictive maintenance, while consumer IoT focuses on homes, wearables and convenience.
Projects to build after reading this
See all projects
ESP32 Wi-Fi STA Connection (with LCD Screen)
In this project, we connect the ESP32 to the home Wi-Fi network in Station (STA) mode in a secure, fault-tolerant manner. We store the SSID and password in a separate secrets.h file to prevent leaking to Git, set up an auto-reconnect mechanism, and display the RSSI signal level and IP address on an I2C LCD screen. The internal LED works as a status indicator. It is a production-grade connection manager.

ESP32 Asynchronous Web Server (with IP Display on LCD)
In this project, we’re turning the ESP32 into an asynchronous web server that you can control from your phone or computer on the same Wi-Fi network. Thanks to the ESPAsyncWebServer library, the server can process multiple requests simultaneously (unlike the classic WebServer.h, which blocks on a single request). You’ll be able to open the ESP32’s IP address in a browser and click the ON/OFF buttons (the /on and /off routes) to turn the LED connected to GPIO 5 on and off.

ESP32 WebSocket Counter (2 Buttons + LCD + Real-Time Web)
In this project, two buttons wired to the ESP32 (GPIO 5 counts up, GPIO 4 counts down) change a counter. The value updates instantly both on a 16x2 I2C LCD and, through the WebSocket support of ESPAsyncWebServer, in every connected browser without reloading the page. Instead of HTTP polling a single persistent connection is used, and the ESP32 sends the new value to everyone with ws.textAll().

ESP32 HTTPClient + Weather API (with LCD Screen)
In this project the ESP32 makes a REST API call over the internet to a weather API (wttr.in) using HTTPClient.h. The JSON response is parsed with ArduinoJson v7, and the city, temperature, humidity, weather and wind are shown on an I2C LCD. wttr.in needs no API key; just type the name of any city.

ESP32 Motion Alarm System (PIR + Buzzer + LED + Telegram)
A smart security alarm: when the PIR sensor detects motion, it sounds the buzzer, lights the LED and sends the owner an instant Telegram notification. A 30-second cooldown limits how often the alarm repeats; it does not filter out the PIR sensor's false detections. Use it at home, in a garage, a storeroom or a study.

ESP32 Deep Sleep — Battery Saving (OLED + RTC RAM Counter)
The ESP32's Deep Sleep mode shuts down the CPU and most peripherals, cutting current draw to about 10µA, which is vital for battery-powered IoT devices. This project uses three wake-up sources: a timer (15 s), an external pin (EXT0, the button on GPIO 33) and a touch pin (T0/GPIO 4). Counters marked with RTC_DATA_ATTR survive deep sleep.

Real-Time Clock from the Internet via ESP32 NTP
The ESP32 connects to Wi-Fi and fetches the real time from NTP (Network Time Protocol) servers with millisecond precision. configTzTime() applies the Turkey time zone (TRT, UTC+3) automatically, and in countries with daylight saving time the DST switch is handled by a POSIX TZ string. The time is printed both to the Serial Monitor and to an optional I2C LCD.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

