Can Two Arduinos Communicate?
LoRaWAN is an exciting IoT technology that is expanding our communication capabilities. LoRaWAN allows devices to communicate over tens or even hundreds of kilometers (in extreme cases), all without a cell network or a high-powered antenna array. The big tradeoff with this technology is that data rates become severely restricted—in the low kb/s range depending on conditions. While you might not be able to stream a 4k movie or even a low-fi audio clip, LoRaWAN is still an excellent option for intermittent sensor data spread over a wide geographic area.
Now, helped along by Arduino’s MKR WAN 1300 LoRaWAN board, this technology is increasingly available for experimentation. Soon you’ll be able to accomplish exciting tasks such as:
- Starting your IoT coffee maker from miles away
- Verifying that your garage door is down without backing up
- Reading from a sensor array
One way to get started with LoRaWAN is with an internet gateway that already exists, like The Things Network (TTN), or by installing one yourself. An internet gateway lets you get your data to the cloud for usage anywhere, but what about something simpler? Can you set up point-to-point communication between two MKR WAN boards as the first step towards LoRaWAN exploration?
The good news is that point-to-point communication is pretty simple, though figuring out the steps can be tricky. Let’s walk through how to get one-way communication going between two of these boards.
Arduino Communication Setup & Tools
You’ll need to obtain the following hardware:
- Two micro-USB cables
- One pair of antennas
The proper antennas often come sold along with the boards. Now follow these steps:
1. If you don’t have it already, install the Arduino IDE.
2. Install the MKR series of boards by pulling up boards-boards manager and searching for “mkr.” The first option will be Arduino SAMD Boards (32-bit ARM Cortex-M0+) by Arduino, and the description will list the MKR WAN 1300 among others. The installation will take some time once started.
3. Install the MKRWAN library, along with the LoRa library by Sandeep Mistry.
Installing Arduino LoRaWAN
Once you have your hardware ready to go, follow these steps to install and run your Arduino LoRaWAN:
1. Physically attach an antenna to both MKR WAN boards.
2. Open two instances of the Arduino IDE via a desktop or Start menu shortcut. Opening both separately (not through the file-new dialog) allows you to manipulate two serial ports at the same time. Doing so will make the process much easier.
3. Open the sketch MKRWANFWUpdate_standalone from File-Examples-MKRWAN in each IDE instance and send the software to your boards to update each one. Note that if your board isn’t set as an Arduino MKR WAN 1300, the library may show up in the “INCOMPATIBLE” example section. If you select the proper board under Tools-Board, you’ll see a message that says: “Examples from Custom Libraries.”
4. Navigate back to File-Examples, then LoRa. Under this section, load “LoRaSender” onto one board, then “LoRaReceiver” to the other.
5. Start a serial monitor on both ports, and you’ll see the transmitter board sending a packet every five seconds. The receiver serial port—if everything works properly—will show it receiving these the packet with a Received Signal Strength Indication (RSSI) number to show how well the pair is communicating.
Congratulations, you’ve achieved LoRaWAN transmission!
LoRaWAN Range Testing
Honestly, sending a message between two nodes in the same room and connected to the same computer can feel like a real accomplishment. But the industry-wide excitement around LoRa is anchored in its long-range communication capabilities.
To test these capabilities, I came up with a slight modification to the stock LoRaReceiver code. In addition to spitting out a short message and RSSI value when it receives a transmission, the MKR WAN’s onboard LED lights up. Using your operable sender, simply plug it into a portable USB battery and watch it blink away if there’s a signal present!
With this blinking device in-hand, I set out on a series of tests to evaluate signal strength. My testing showed that LoRaWAN range is impressive. Even a proper setup, though, there is no guarantee of kilometer after kilometer of range in less-than-ideal conditions.
Test 1: Automobile. Leaving the transmitter broadcasting inside my house, I left the garage in a car with the receiver blinking. As I arrived at my destination one kilometer away “as the crow flies,” and through a variety of obstructions, the light was no longer blinking. Perhaps my computer shut down, or I made some other error? Once I arrived back at my house, however, the blinking started up again, which means that I was indeed out of range.
Test 2: Bicycle. I left the transmitter in the same room and headed out on a bicycle to see if my car’s metal shell affected the range was. Through some obstructions, transmission faded out at around 300 meters. The verdict? Definitely better than Wi-Fi, but not exactly world-changing.
Test 3: Transmitter outside. For my final test, I put the transmitter outside. Without the walls of my garage blocking the signal, I was able to get a bit more range in one direction, maybe 350 meters. Down another street, the transmission held up to around 300 meters, but as the street curved into an area where there was no longer a clear line-of-sight, transmission quickly stopped.
Based on my testing, LoRaWAN can offer an impressive range, especially compared to Wi-Fi. On the other hand, like all radio transmissions, having a clear line-of-sight between transmitter and receiver is critical. Additionally, the signal here isn’t set up for the situation, and there’s no feedback. Therefore, the setup doesn’t take advantage of many options available within the LoRaWAN umbrella for increased range. This article gives guidance on how to achieve a simple “hello world” for working with LoRaWAN, but you can take it much further. Use this article as a jumping-off point to optimize the transmission for your own application