The integration of Arduino microcontrollers into the Internet of Things (IoT) ecosystem opens up endless possibilities for automation and remote control for developers. WiFi connection It allows you to transmit sensor data to cloud storage, control your smart home from your smartphone, and receive up-to-date information from the network in real time. However, standard Arduino boards, such as the Uno or Nano, do not have a built-in wireless module, requiring additional hardware.
In this article, we will examine the connection process in detail. Arduino To connect to a wireless network, we'll look at popular modules and analyze typical mistakes that beginners encounter. A critical condition for stable operation is the presence of a module that supports 802.11 b/g/n standards, since the old WEP security protocols are no longer supported by default by modern routers. You will learn how to set up a connection, send HTTP requests, and create simple web servers directly on the microcontroller.
Before you start coding, you need to decide on the hardware for your project. The market offers a variety of solutions, from simple adapters to powerful single-board computers. The choice of a specific device will depend on your project's requirements, budget, and available PCB space.
Selecting equipment for wireless communications
The first step in creating an IoT device is choosing the right communication module. Classic boards Arduino Uno or Mega require connecting an external WiFi module via a UART interface (serial port). The most popular and affordable solution remains a module ESP8266 (for example, in the NodeMCU or Wemos D1 Mini version), which can work as a standalone controller or as a modem for Arduino.
A more modern alternative is a chip ESP32, which offers not only WiFi but also Bluetooth, and has significantly more processing power and GPIO pins. If you're using official Arduino boards, such as Arduino MKR WiFi 1010 or Arduino Nano 33 IoT, the wireless module is already built into the design, which simplifies assembly, but increases the cost of the project.
⚠️ Important: When choosing the ESP8266 module, ensure your power supply is capable of delivering at least 500 mA. When connected to a WiFi router, the module draws peak current, which can cause the Arduino to reboot if you're using a weak USB port or a poor-quality cable.
A comparison of the key features of popular network connection solutions is presented in the table below. This will help you quickly navigate the technical differences.
| Module/Board | Protocols | Supply voltage | Difficulty of setup |
|---|---|---|---|
| ESP8266 (NodeMCU) | WiFi 802.11 b/g/n | 3.3 V | Low |
| ESP32 DevKit | WiFi + Bluetooth | 3.3 V | Average |
| Arduino MKR WiFi 1010 | WiFi + BLE | 3.3 V / 5 V | Low |
| ESP-01 + Arduino Uno | WiFi 802.11 b/g/n | 3.3 V | High |
For beginning developers, the optimal choice would be a board based on ESP8266 or The ESP32 is programmable via the Arduino IDE. This allows for familiar syntax and a comprehensive library base, eliminating the complexities of matching voltage levels between the 5V Arduino and the 3.3V module.
Installing the required libraries and drivers
After preparing the hardware, you need to configure the software environment. The standard Arduino IDE doesn't always include all the necessary tools for working with WiFi by default, especially if you're using third-party boards. To work with the ESP8266 and ESP32, you'll need to add the repository URLs to the IDE settings via the menu. File → Preferences.
In the "Additional Boards Manager URLs" field, you need to paste the link to the board manager of the corresponding manufacturer. After that, in the board manager (Tools → Board → Boards Manager) new positions will appear. Find esp8266 or esp32 and install the latest stable version. This process will download the compiler and core libraries for working with the hardware.
☑️ Preparing the development environment
It's also important to install drivers for the USB-UART converter, which is built into most development boards. These are usually chips CH340, CP2102 or FT232Without the correct driver, the computer simply won't see the connected device in the list of ports.
To simplify working with network protocols, it is recommended to install the library WiFiManagerIt allows you to configure WiFi parameters (SSID and password) via a web interface without recompiling code, which is extremely convenient when deploying devices in different locations.
Wiring diagram and physical installation
If you're using a board like the NodeMCU or ESP32 DevKit, no additional connections are required for basic operation—simply connecting the device via USB. However, if you're connecting a separate module (such as the ESP-01) to a classic Arduino Uno, care must be taken with voltage levels.
The Arduino's UART interface logic level is 5 volts, while ESP modules operate at 3.3 volts. Directly connecting the Arduino's TX line to the module's RX line can damage the WiFi chip. To match the levels, use a resistor-based voltage divider or a dedicated converter.
- 🔌 Connect the module's VCC to a 3.3V source (not 5V!).
- 🔌 Connect the GND of the module to the GND of the Arduino.
- 🔌 Connect the TX of the module to the RX of the Arduino (pin 0 or SoftwareSerial).
- 🔌 Connect the RX of the module to the TX of the Arduino via a voltage divider.
The "AT command" mode is often used for testing the connection. In this mode, the module acts as a transparent bridge, transmitting data between the computer and the WiFi router. This allows you to check the module's functionality before uploading the main sketch.
⚠️ Please note: Router settings and web interfaces are frequently updated by manufacturers. The location of menu items for setting up a static IP or MAC address filtering may differ from that described in the manuals. Always consult the latest documentation for your router model.
Writing Code: Connecting to the Network
Let's look at a basic code example for connecting to a WiFi network. We'll use the standard library. WiFi.h (for ESP32/Arduino MKR) or ESP8266WiFi.h (for ESP8266). The algorithm is simple: initialization, connection attempt, and status check.
#include<WiFi.h> // or ESP8266WiFi.hconst char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected!");
}
In this code snippet we create a loop while, which is waiting for a successful connection. Dots displayed in the Serial Monitor indicate the progress of the connection attempt. If a connection isn't established within a certain amount of time, the device may go to sleep or restart.
It's important to keep passwords and SSIDs secure. Hardcoding passwords directly into the code is not recommended for industrial projects. It's better to use mechanisms that store data in non-volatile memory (SPIFFS or EEPROM) or configure the device on first startup.
Why might the connection fail?
There are several possible causes: an incorrect password, a weak signal (RSSI below -85 dBm), the router only operating in 5 GHz mode (the ESP8266 only supports 2.4 GHz), or MAC address filtering enabled on the router. Check the logs via Serial Monitor to determine the error.
Working with HTTP requests and the web server
One of the most popular tasks is creating a web server on Arduino. This allows you to control GPIO pins or read sensor readings from a browser on any device on the same network. Library WebServer (for ESP) or WiFiServer takes over the processing of incoming TCP connections.
When creating a server, you need to define handlers for different URLs. For example, a request /ledon will turn on the LED, and /ledoff — Disable. The server's response is generated as an HTML page, which is displayed in the client's browser.
Additionally, Arduino can act as a client, sending data to external services such as ThingSpeak, Blynk or Telegram BotHTTP POST or GET requests are used for this. Data can be transmitted in JSON format, a standard for the modern IoT.
To send data to a remote server, a library is often used. HTTPClientIt simplifies the formation of request headers and bodies. Below is an example of sending a temperature to the server.
if (WiFi.status() == WL_CONNECTED) {HTTPClient http;
http.begin("http://example.com/api/data");
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.POST("{\"temp\": 25.5}");
http.end();
}
Optimization and energy consumption
When operating on battery power, power consumption becomes critical. The WiFi module consumes significant current, especially when transmitting packets. For battery-powered devices, deep sleep algorithms must be implemented.Deep Sleep).
In Deep Sleep mode, the microcontroller turns off most peripherals and the radio module, consuming microamps of current. The device wakes up on a timer or external interrupt, quickly sends accumulated data, and then goes back to sleep. This allows the battery to last for months or even years.
- 🔋 Use interrupts to wake up instead of polling buttons.
- 🔋 Minimize connection time to your WiFi router.
- 🔋 Disable unused peripheral modules (SPI, I2C) programmatically.
It's also worth considering that if you have a large number of devices on the same network, you may need to configure a DHCP server on your router or use static IP addresses to avoid conflicts and exhaustion of the address pool.
Frequently Asked Questions (FAQ)
Is it possible to connect an Arduino Uno directly to WiFi without additional modules?
No, the classic Arduino Uno does not have a built-in WiFi module. You will need to purchase an additional shield or an external module (e.g., ESP-01 or HC-05 with an adapter) that connects via the UART interface.
What is the default password for ESP8266 hotspot?
The password depends on the firmware. If you use the WiFiManager library, the module will create an access point named "ESPxxxx" upon first launch and will not require a password to access the settings. Otherwise, the password will be specified in the documentation for the specific library.
Why can't Arduino see my 5GHz WiFi network?
Most budget modules (ESP8266, ESP32 in the basic configuration) only operate in the 2.4 GHz band. Make sure your router broadcasts the 2.4 GHz network and your devices are within range.
How to increase the WiFi signal range for Arduino?
To increase the range, you can use an external antenna (if the module has a connector), install a WiFi repeater closer to the device, or use modules with a more sensitive receiver. Reducing airborne noise also helps.