Connecting the Arduino MKR WAN to The Things Network using LoRaWAN Part 1

Note: In the instructions that follow, the terms MKR WAN 1300 and MKR WAN 1310 are used interchangeably (as we initially started with the 1300). The boards are very similar, though they have different battery connections.

Setting up the Arduino MKR WAN

We will begin by connecting your radio transmitter device (the Arduino) to The Things Network (TTN). For this purpose, we will use the Arduino MKR WAN 1310 board, which features a built-in LoRaWAN radio transmitter.

LoRaWAN, developed by Semtech, is a long-range radio technology that enables Internet of Things (IoT) sensors to send data to remote locations. The radio network we will utilize is The Things Network (TTN), which is free to use for testing purposes. WAN stands for Wide Area Network.

Before proceeding, ensure you are within range of a TTN gateway. If not, your device will not function. Check coverage using this link. While proximity to a gateway is not required, if you are more than a mile away, you might consider setting up your own gateway using this guide.

Aims

  • Identify the Device EUI (Extended Unique Identifier) of your Arduino MKR WAN, as TTN uses this ID to recognize the device sending data.
  • Create an account on The Things Network (TTN).
  • Establish a connection between the Arduino MKR WAN and your TTN account.
  • Send a message to TTN. These messages, known as 'Payloads,' are transmitted in hexadecimal code (base 16).
  • Log in to your TTN account and decode the payload into plain text.

Research

Arduino MKR WAN

Equipment

My shopping list included the following items:

The illustration shows the Arduino MKR WAN 1300 with its connected antenna. The two components are supplied separately. The connector at the end of the antenna wire snaps onto a fitting on the Arduino. It is a firm fit, so you may need to apply some pressure to secure it.

Procedure

Note: In the instructions that follow, the terms MKR WAN 1300 and MKR WAN 1310 are used interchangeably (as we initially started with the 1300). The boards are very similar, though they have different battery connections.

Install the Arduino IDE (Integrated Development Environment)

In order to program the Arduino, you must first download and install the Arduino IDE (integrated development environment) onto your computer.

There are now two versions of the IDE, the original IDE Version 1, and the new Version 2. Version 2 has more features than Version 1. If you have ever used Microsoft’s Visual Studio Code, you will be familiar with the layout of Version 2.

Both versions are available on this page.

Arduino IDE

For Windows users, select the 'Windows 10 and newer' option. For instance, if you are using Windows 10, the file you need might be named ‘arduino-1.8.9-windows.exe’. Note that if you opt for Version 2, the screenshots in this tutorial may appear slightly different.

Once the download is complete, double-click the .exe file and follow the installation instructions. Upon successful installation, you should see this interface when you open the IDE.


Installing the Arduino Drivers and Libraries

To program the Arduino for Internet of Things (IoT) applications, it is necessary to download a driver for the MKR WAN board and some libraries. Libraries consist of blocks of pre-built code that can be used in your scripts.

Install Boards Manager

Installing the driver:

Open the Arduino IDE that you have just installed.

Navigate to Tools > Board > Board Manager.

Click on 'Boards Manager' to open it.


Install Boards

Search for Arduino SAMD boards (32-bits ARM Cortex M0+) (using the search box in the top right of the Boards Manager window) and install it.

Manage Libraries

Installing the Library:

Open the Arduino Library Manager by going to Tools > Manage Libraries.


Install Library

Look for the MKRWAN library.

Use the search box in the top right corner of the Library Manager window to find the MKRWAN library and install it. (it is already installed in this screenshot.)


Connecting the MKR WAN 1310 to Your Computer

Connect MKR WAN to computer

To begin, you'll need a micro USB cable. Connect the micro end to your Arduino and the USB end to your computer.

Once the MKR WAN 1310 is powered, a green LED will illuminate (note: the picture shows a 1300). The MKR WAN board includes its own LoRa module running dedicated firmware. Our initial task is to update this firmware to ensure we are operating the latest version.

We can achieve this by uploading a sketch to the MKR WAN, which will then transfer the updated firmware to the LoRa module.

Update Firmware Sketch

In Arduino terminology, a ‘sketch’ refers to a computer program. It's the code unit uploaded to and executed on an Arduino board, typically using the file extension ‘ino’, such as ‘myfile.ino’ (the last three letters of Arduino).

After installing the MKRWAN library, you can locate the update sketch by navigating to File > Examples > MKRWAN > MKRWANFWUpdate_standalone (you may need to scroll down the list).


Update Firmware

Click on this sketch, and it will open in a new window. Expand the window if necessary. You should see a display similar to the this one.

Before proceeding with the sketch upload, ensure that the correct board and port are selected. 

Select Board

Connect the MKR WAN to Your Computer. Ensure the MKR WAN is plugged in via a micro USB cable, otherwise, the port number will not be detectable.

Select the MKR WAN Board: Navigate to Tools > Board > Arduino SAMD boards (32-bits ARM Cortex M0+) > Arduino MKR WAN 1310 (or 1300 if you have one), and select it.




Arduino IDE

Select the Port Number: Navigate to Tools > Port, and select the active serial port through which your computer will communicate with the MKR WAN 1300. In the example provided, it is port COM7, but it may differ in your case.


Tip: Occasionally, you may find that the port number is greyed out in the Tools menu and cannot be selected. If this occurs, follow these steps:
 
  1. Click the Reset button twice in quick succession. The Reset button is the blue button located in the middle of the board, just in front of the battery connector.
  2. This action will put the board into bootloader mode, where the operating system is loaded.
  3. Restart the Arduino IDE. This should resolve the issue, enabling you to select the port number.
Serial Monitor

Before uploading the sketch, it is important to familiarize yourself with the serial monitor, which is a pop-up window that displays the output from the sketch while it is running.

To open the serial monitor, click on the small magnifying glass in the top right-hand corner of the IDE. Hovering over this button will display the words ‘serial monitor.’

To upload the sketch, click on the right-hand arrow in the top left of the IDE (next to the ‘tick’). Hovering over this button will display the word ‘upload.’ When you are ready, upload the sketch by clicking the ‘upload’ button. The sketch will run automatically once it is uploaded.

Compile Sketch

Before the sketch can be uploaded to the Arduino, it must be compiled. This process converts the sketch into machine code, which the Arduino processor then executes. Compiling the sketch may take a few minutes, depending on the complexity of the sketch and the speed of your computer. Arduino code is based on the ‘C’ programming language.

At the foot of the IDE, you will see a bar reporting the progress of the compilation. Once complete, the ‘Compiling sketch’ message changes to ‘Uploading’ and then ‘Upload Complete,’ assuming there are no issues. This progress bar is known as the ‘text console,’ as opposed to the ‘text editor,’ which is the window above where you write your code.

Languages such as Python and JavaScript are interpreted languages, meaning they are compiled each time they are used, requiring a Python or JavaScript interpreter. While interpreted languages can be easier to program, they run more slowly than compiled languages due to this extra interpretation step. For more information, you can refer to this article here.

Serial Monitor Running

Click on the ‘serial monitor’ button to observe the progress of the update. This will open in a new window. You should see lines of text scrolling through the monitor as the update proceeds.

When the scrolling stops, the update is complete. You can close the serial monitor by clicking the cross in the top right-hand corner of the window.

With the update complete, we can now proceed to connect your MKR WAN to the internet using the LoRaWAN network. Click here for the next steps.

© Copyright 2025 Dr Dulcamara - All Rights Reserved