Sub topic 1
Choosing a Wi-Fi board and its library
Every Arduino Wi-Fi example looks almost the same: call WiFi.begin(), wait for a connection, and open a client. The details differ by board. The #include line, the library you install, and the firmware on the radio chip all depend on which board you own. This chapter helps you pick a board and match it to its library. It also shows how to write sketches that survive a change of hardware.
Prerequisites
This chapter assumes you can do the following:
- Write and upload a basic sketch that uses
setup(),loop(), andSerialoutput. - Use the Arduino IDE or Arduino CLI to install a board package and a library.
- Explain what an SSID, an IP address, a port, and a router are.
- Reach a 2.4 GHz Wi-Fi network that you are allowed to use.
You do not need any network programming experience yet. The next chapter covers the networking terms in more depth.
Why the board determines the library
Most Arduino boards have no Wi-Fi radio on the main microcontroller. The Wi-Fi boards use one of two designs:
- A separate radio module. The main microcontroller talks to a Wi-Fi chip over SPI or a serial link. The radio chip runs its own firmware, which handles the Wi-Fi association, DHCP, TCP/IP, and TLS. Your sketch sends commands to it through a library.
- A microcontroller with the radio built in. The Espressif ESP32 family works this way. The Wi-Fi stack is part of the board's core software, so no extra library is needed.
In both designs, the library hides the details behind a familiar set of classes: WiFi, WiFiClient, WiFiSSLClient, and WiFiServer. The class names are shared, but the header files and some features are not. If you include the wrong header for your board, the sketch fails to compile or fails to find the radio.
Board families and their libraries
The table lists the common official boards and the library each one uses.
| Board | Radio | Library | Header |
|---|---|---|---|
| Arduino MKR WiFi 1010 | u-blox NINA-W10 (ESP32-based) | WiFiNINA | `WiFiNINA.h` |
| Arduino Nano 33 IoT | u-blox NINA-W10 | WiFiNINA | `WiFiNINA.h` |
| Arduino Nano RP2040 Connect | u-blox NINA-W10 | WiFiNINA | `WiFiNINA.h` |
| Arduino Uno WiFi Rev2 | u-blox NINA-W10 | WiFiNINA | `WiFiNINA.h` |
| Arduino MKR1000 | Microchip ATWINC1500 | WiFi101 | `WiFi101.h` |
| Arduino Uno R4 WiFi | ESP32-S3 co-processor | WiFiS3 | `WiFiS3.h` |
| Arduino Nano ESP32 | ESP32-S3 (built in) | WiFi (from the ESP32 core) | `WiFi.h` |
| Third-party ESP32 boards | ESP32 (built in) | WiFi (from the ESP32 core) | `WiFi.h` |
Other Arduino boards, such as the GIGA R1 WiFi and the Portenta family, use their own board-package libraries. Check the board's documentation page for the exact name. The pattern stays the same: the board package or the Library Manager provides the library, and the library exposes the WiFi object.
The three NINA-based boards cover most of the tutorial examples. The code in this tutorial uses WiFiNINA, which targets the MKR WiFi 1010 and Nano 33 IoT.
How to install each library
- WiFiNINA and WiFi101 are installed from the Library Manager. Search for the name and click Install.
- WiFiS3 is bundled with the "Arduino UNO R4 Boards" package. Installing the board package gives you the library. You do not install it separately.
- WiFi.h on ESP32 boards comes with the board package ("Arduino ESP32 Boards" for the Nano ESP32, or Espressif's package for generic ESP32 boards).
If an #include line reports "no such file or directory", the library is missing or you have the wrong board selected under Tools > Board.
Radio firmware is a separate version
On boards with a separate radio module, the radio firmware is not the same as your sketch. The module's firmware is flashed independently and has its own version number. A new library release can expect newer radio firmware. That mismatch can show up as odd behavior, missing functions, or failed TLS connections.
You can read the version from a sketch. The Arduino IDE also includes an updater. Open Tools > WiFi101 / WiFiNINA Firmware Updater to check the firmware version and flash a newer one. This tool also manages the root certificates that the radio uses for HTTPS, which a later chapter covers.
The sketch below picks the right header for the board, then reports whether the radio responds and which firmware version it runs.
#if defined(ARDUINO_SAMD_MKR1000)
#include <WiFi101.h>
#elif defined(ARDUINO_UNOR4_WIFI)
#include <WiFiS3.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#else
#include <WiFiNINA.h>
#endif
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 5000) {}
#if defined(ARDUINO_ARCH_ESP32)
Serial.println("Wi-Fi is built into this board's core");
#else
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Wi-Fi module not found");
while (true) {}
}
Serial.print("Radio firmware: ");
Serial.println(WiFi.firmwareVersion());
#endif
}
void loop() {}The ARDUINO_... names are macros that the board package defines when you select that board. They let one sketch compile for several boards. If a macro for your board is not listed here, look it up in the board package's boards.txt file, or print your board's macros with the compiler's verbose output.
The WL_NO_MODULE check matters on the NINA and WINC boards. It returns that value when the library cannot talk to the radio chip. A common cause is a board that the library does not support, or a damaged module. You should always make this check the first step in a Wi-Fi sketch.
What stays the same across libraries
The Arduino team designed these libraries to follow the older WiFi and Ethernet library interfaces. Because of that, the following calls behave the same on WiFiNINA, WiFi101, and WiFiS3:
WiFi.begin(ssid, pass)starts a connection to a WPA/WPA2 network and returns a status code.WiFi.status()returns the current state, such asWL_CONNECTED.WiFi.localIP()returns the address the router assigned.WiFi.RSSI()returns the signal strength in dBm.WiFiClientopens plain TCP connections.WiFiSSLClientopens TLS-encrypted connections.WiFiServeraccepts incoming connections.
Porting a sketch between these boards often means changing one #include line. Differences appear at the edges: how the library handles certificates, which extra functions exist, and how the board's own core handles timing.
Where they differ
- ESP32 boards use a different class for TLS. The ESP32 core calls its TLS client
WiFiClientSecure, notWiFiSSLClient. HTTPS code needs a small change when you move to or from an ESP32 board. - Certificate handling differs. NINA and WINC modules store root certificates in the radio. ESP32 sketches usually pass a certificate to the client in code, or use the core's built-in bundle.
- Some status codes and helper functions exist only in one library. Check the library's reference when a call does not compile.
- Memory and speed vary. The MKR1000 and Uno WiFi Rev2 have limited RAM compared with an ESP32 board. Large HTTP responses or JSON documents can exhaust memory on small boards.
Practical selection criteria
When you choose between boards, compare them on a few points that matter for a connected project:
- Library maturity and support. WiFiNINA boards have the most tutorials and community examples. This helps when you search for an error message.
- Memory. Sketches that build large strings, parse JSON, or run a web server need RAM. Check the board's SRAM figure against your project.
- Logic voltage. The MKR and Nano 33 IoT boards run at 3.3 V, and their pins are not 5 V tolerant. Wiring a 5 V sensor directly can damage them. The Uno WiFi Rev2 and Uno R4 WiFi run at 5 V.
- Form factor and power. The MKR boards have a battery connector. The Nano boards are small and fit tight enclosures. Wi-Fi draws bursts of current, so a weak power supply causes random disconnects.
- Extra connectivity. Some boards also offer Bluetooth Low Energy. The Nano 33 IoT, the MKR WiFi 1010, and the ESP32-based boards do. Choose one of these if the project needs both.
- Cost and availability. Generic ESP32 boards cost less, but you manage the core and its differences yourself.
Common errors at this stage
| Symptom | Likely cause | Fix |
|---|---|---|
| `WiFiNINA.h: No such file or directory` | Library not installed | Install WiFiNINA from the Library Manager |
| `WL_NO_MODULE` at startup | Wrong board selected, or the radio is not responding | Check Tools > Board and update the radio firmware |
| Sketch compiles but the board never sees your network | The network is 5 GHz only | Enable a 2.4 GHz band on the router |
| Old examples fail on a new board | The example targets a different library | Change the include and any TLS class name |
| Firmware version prints as an old value | The radio firmware is behind the library | Run the Firmware Updater |
Exercise
You have an Arduino Uno R4 WiFi. A tutorial sketch starts with #include <WiFiNINA.h> and fails to compile. Which header should you use, and do you need to install a library from the Library Manager?
Show answer
Use #include <WiFiS3.h>. You do not need to install a separate library. WiFiS3 is bundled with the "Arduino UNO R4 Boards" package, so installing that board package provides it. The rest of the sketch, such as WiFi.begin() and WiFiClient, usually works unchanged.
Exercise
A sketch on a MKR WiFi 1010 prints "Wi-Fi module not found" right after upload. Name two things you would check, in order.
Show answer
First, confirm that the selected board under Tools > Board is the MKR WiFi 1010 and that the sketch includes WiFiNINA.h. The library cannot talk to the radio if the board or library does not match. Second, update the radio firmware with the WiFi101 / WiFiNINA Firmware Updater in the IDE. If the error persists after both steps, the module may be damaged.
Exercise
Why can a sketch that compiles for a MKR WiFi 1010 fail to compile for a generic ESP32 board when it uses HTTPS, even though both use a class called WiFi?
Show answer
The ESP32 core names its TLS client WiFiClientSecure, while WiFiNINA uses WiFiSSLClient. The plain WiFi object and WiFiClient match, but the TLS class and the certificate handling differ. Change the class name and supply a certificate or use the core's certificate bundle.