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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.