Connecting devices to the Internet is a key requirement in IoT and embedded systems. The Arduino Uno WiFi board simplifies this process by including a built-in WiFi module, eliminating the need for additional external hardware. This makes it an excellent choice for developers looking to create connected projects quickly and efficiently.
This article will guide you through setting up your Arduino Uno Wifi board and demonstrate how to connect it to a Wi-Fi network. With its onboard Wi-Fi module, this board is ideal for prototyping IoT applications such as smart home devices, remote sensor monitoring, and basic web-based control systems.
By the end of this tutorial, you’ll learn:
- The key features of the Arduino Uno WiFi and its onboard WiFi capabilities.
- How to set up your development environment and connect the board to a WiFi network.
- Troubleshoot common issues.
Main Features of Arduino Uno WiFi board
For this project, I will use the Arduino Uno WiFi Rev 2 board. The Arduino Uno WiFi Rev 2 simplifies IoT projects by integrating an onboard WiFi module, removing the need for external components like shields or modules.
The board is powered by the ATmega4809 microcontroller, which provides performance and versatility for various applications. It also includes a Cryptochip, ensuring secure communication for projects that handle sensitive data. Fully compatible with the Arduino IDE, the Uno WiFi Rev 2 is easy to program without requiring additional setup. Its compact and robust design makes it suitable for DIY and professional use, particularly in embedded and space-constrained projects.
Choosing the correct Arduino Uno WiFi library
Choosing the right library for your development board is crucial when working on WiFi-enabled projects. A compatible library ensures integration with the board’s hardware, simplifies development, and enables access to the board’s full range of features. Using an unsuitable library can lead to unstable connections, reduced performance, or an inability to utilize essential capabilities. For the Arduino Uno WiFi Rev 2, selecting the proper library is especially important because of the unique architecture of its onboard NINA-W102 WiFi module.
After considering the available options, it becomes clear that the WiFiNINA library is the ideal and only fully supported choice for the Arduino Uno WiFi Rev 2. This library is designed to work with the NINA-W102 module, ensuring reliable performance and compatibility. By using WiFiNINA, developers gain access to features such as secure data transmission through SSL/TLS, the ability to scan for and connect to WiFi networks, and support for client-server communication. Additionally, the library is maintained and updated by Arduino, offering consistent support and compatibility with the latest tools and environments.
Setting up the Arduino Uno WiFi project
After this introduction, here’s how to prepare and connect the board to your development environment.
First, connect the Arduino Uno WiFi Rev 2 board to your computer using a USB cable. The USB connection powers the board and enables programming through the Arduino IDE. Ensure you have the latest version of the Arduino IDE installed on your computer, as this will include the necessary drivers for the Uno Rev 2. You can find the newest version here.
Next, open the Arduino IDE and install the required WiFi library. Navigate to the library manager, search for the “WiFiNINA” library (Figure 2), and click Install.
When the installation is completed, we can verify the connection between the board and the computer. Select the correct board and port in the Arduino IDE through the selector provided on the upper side of the window, as shown in Figure 3. At this stage, your Arduino is ready for programming. The setup process is complete, and you can move on to create a first test project.
Connecting Arduino Uno Rev 2 to the WiFi network
Once the Arduino Uno Rev 2 is set up, the next step is to connect it to a WiFi network. This process involves writing a simple sketch. We can start writing our code using Arduino IDE’s code editor.
Start by including the necessary library in your sketch:
#include <WiFiNINA.h>
Define the network credentials:
const char* ssid = "Your_Network_Name";
const char* password = "Your_Network_Password";
In the setup()
function, initialize the Serial Monitor and attempt to connect to the WiFi network:
void setup() {
Serial.begin(9600);
// Wait for Serial Monitor to open
while (!Serial);
Serial.print("Connecting to WiFi...");
int status = WiFi.begin(ssid, password);
while (status != WL_CONNECTED) {
delay(1000);
Serial.print(".");
status = WiFi.status();
}
Serial.println("\nConnected!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
The loop()
function can remain empty for now, as the primary goal is to establish a WiFi connection:
void loop() {
// Leave this empty for now
}
Uploading the Arduino Uno WiFi Sketch
The first sample code is complete, and we can now test the sketch. To visualize the program’s output, we can open the serial monitor by clicking on Tools->Serial monitor.
Now, click on the Upload button (red square in Figure 4) to run the sketch. The code will then be compiled and run.
Once the program runs, we can observe the output on the serial monitor:
As per Figure 5, the Arduino board can connect, showing also the assigned IP address.
With the Arduino board connected to WiFi, we can move to the next step, implementing a practical use case to demonstrate the board’s capabilities.
Extended the Arduino WiFi project with time monitoring
In the previous chapter, we created a basic sketch to connect the Arduino to WiFi. Now, let’s extend it by adding a functionality to read and display the current time. To achieve this, we will use the WiFi.getTime()
method that fetches and returns the time from an NTP (Network Time Protocol) server. To incorporate the time-reading functionality, we will add the following snippet to the loop()
function in the existing sketch:
void loop() {
// Check if the WiFi is connected
if (WiFi.status() == WL_CONNECTED)
{
// Get the current time
time_t currentTime = WiFi.getTime();
if (currentTime != 0) {
// Adjusting unix offset for time.h library
currentTime -= UNIX_OFFSET;
// Convert and display the time
Serial.print("Current time: ");
Serial.println(ctime(¤tTime));
}
} else {
Serial.println("WiFi not connected.");
}
// Add a delay before the next time read
delay(2000); // Check every 10 seconds
}
The code monitors the WiFi connection status using WiFi.status()
within the loop()
function. If the connection status equals WL_CONNECTED
, the method WiFi.getTime()
is called to fetch the current time from an NTP server. The time is stored in the variable currentTime
. If currentTime
is non-zero (indicating a successful fetch), a specific offset is removed (UNIX_OFFSET), and then it is converted into a human-readable string using the ctime()
function and output to the Serial Monitor via Serial.println()
.
We can then upload the sketch to the Arduino Board. Once done, we can check the serial monitor to observe the following output:
Troubleshooting
Even with its user-friendly design and robust capabilities, you might encounter issues using the Arduino Uno WiFi Rev 2. Below are three common problems and their solutions to help you troubleshoot effectively.
Arduino can’t connect to WiFi
Problem: The board fails to connect to the WiFi network, and the Serial Monitor shows repeated attempts without success.
Possible Causes:
- Incorrect SSID or password.
- Weak WiFi signal.
Solution:
- Double-check the SSID and password in your sketch for accuracy.
- Ensure your WiFi router is broadcasting on a 2.4 GHz network, as the NINA-W102 module does not support 5 GHz bands.
- Move the board closer to the router to improve the signal strength.
- Restart both the router and the Arduino board, and try reconnecting.
Arduino WiFi Sketch Fails to Upload
Problem: The Arduino IDE shows an error when uploading a sketch to the board.
Possible Causes:
- Incorrect board or port selection.
- A conflicting driver or software issue.
- The board is not in bootloader mode.
Solution:
- Verify that the correct board (Arduino Uno WiFi Rev 2) and COM port are selected in the Arduino IDE under Tools > Board and Tools > Port.
- Ensure the board is properly connected via USB. If the problem persists, try a different USB cable or port.
- Press the reset button on the board to ensure it is in bootloader mode before uploading the sketch.
- Update the Arduino IDE and ensure all required drivers and libraries are installed.
WiFiNINA Firmware Version Mismatch
Problem: The Serial Monitor displays a firmware version mismatch error when using WiFiNINA functions.
Possible Causes:
- The WiFiNINA firmware on the board is outdated or incompatible with the library version.
Solution:
- Update the firmware on the NINA-W102 module using the Arduino IDE. Go to Tools > WiFi101/WiFiNINA Firmware Updater, follow the instructions to select your board, and update the firmware.
- Make sure your WiFiNINA library is up-to-date by using the Library Manager in the Arduino IDE.
Conclusion
The Arduino Uno WiFi board is a versatile and powerful development board equipped with onboard WiFi to simplify IoT projects and reduce hardware complexity. Its integration of a reliable WiFi module, secure communication capabilities, and compatibility with the Arduino IDE makes it ideal for beginners and experienced developers.
In this guide, we explored how to set up and connect the board to a WiFi network, discussed the importance of selecting the right library, and highlighted the WiFiNINA library as the definitive choice for leveraging the board’s full potential. Additionally, we covered practical applications and troubleshooting tips to ensure a smooth development experience.
Whether you are building smart home devices, remote monitoring systems, or other IoT applications, the Arduino Uno WiFi provides a solid foundation for innovation. Following the steps outlined in this guide and experimenting with your ideas, you can create robust and secure connected solutions tailored to your needs.
Now, it’s time to put your knowledge into action. Start your next IoT project with the Arduino Uno WiFi and explore its endless possibilities. If you have questions or want to share your experiences, please comment here in the comment section or contact me through the contact form.