Reference   Language | Libraries | Comparison | Changes

MKRNB library

The MKR NB library can be installed using the Arduino library manager.

With the Arduino MKR NB 1500 and this library you can connect to the internet over a GSM network. The on board module operates in 4G, using LTE Cat M1 or NB1.

Arduino MKR NB 1500 has a modem that transfers data from a serial port to the GSM network. The modem executes operations via a series of AT commands. The library abstracts low level communications between the modem and SIM card. It relies on the Serial library for communication between the modem and Arduino.

Typically, each individual command is part of a larger series necessary to execute a particular function. The library can also receive information and return it to you when necessary.

To use this library
#include <MKRNB.h>

Library structure

As the library enables multiple types of functionality, there are a number of different classes.

  • The NB class takes care of commands to the radio modem. This handles the connectivity aspects of the module and registers your system in the 4G infrastructure. All of your GSM/GPRS programs will need to include an object of this class to handle the necessary low level communication.

  • Send/receive SMS messages, managed by the NB_SMS class.

  • The GPRSClass is for connecting to the internet.

  • NBClient includes implementations for a client, similar to the Ethernet and WiFi libraries.

  • A number of utility classes such as NBScanner and NBModem

Library compatibility

The library tries to be as compatible as possible with the current Ethernet and WiFi101 library. Porting a program from an Arduino Ethernet or WiFi101 library to an Arduino with the MKR NB 1500 should be fairly easy. While it is not possible to simply run Ethernet or WiFi101 compatible code on the MKR NB 1500 as-is, some minor, library specific, modifications will be necessary, like including the GSM and GPRS specific libraries and getting network configuration settings from your cellular network provider.


There are two groups of examples for the Arduino MKR NB 1500. There are examples to illustrate the possibilities of the board, like how to connect to the internet. There is also set of example tools that you can use to debug the functionality of the library and the hardware at lower level.

  • NB Web Client: Download the content of a website to your Arduino board through GPRS.
  • NB SSL Web Client: Download the content of a website to your Arduino board through GPRS and SSL.
  • GPRS Ping: Use GPRS to retrieve time from NTP
  • GPRSUdpNtpClient :In this example, you will use your MKR NB 1500, to query a Network Time Protocol (NTP) server. In this way, your board can get the time from the Internet.
  • ReceiveSMS:This sketch waits for an SMS message and prints it to the serial monitor. It uses the GSM library of the Arduino GSM Shield and an active SIM card. To operate, the SIM card doesn't need a data plan.
  • SendSMS: This sketch send a SMS message from an Arduino board equipped with a GSM shield. Using the serial monitor of the Arduino Software (IDE), you'll enter the number to connect with, and the text message to send.
  • ChooseRadioAccessTechnology: This sketch allows you to select your preferred Narrowband Radio Access Technology (RAT). You can choose among CAT-M1, NB-IoT or a combination of both.
  • SerialSARAPassthrough: This example demonstrates how to virtually connect together Serial and Serial1. This tutorial can be so loaded on boards that have two different UART interfaces on the 0 and 1 pins and the USB port (like Zero, MKR1000, 101).

For additional information on the Arduino MKR NB 1500, see the Getting Started page and the Arduino MKR NB 1500 hardware page.

Last revision 2019/12/25 by SM

NB class

This class prepares the functions that will communicate with the modem.

NB_SMS class

Facilitates sending and receiving Short Message Service (SMS) messages.

GPRS class

This class is responsible for including the files that are part of the library that involve TCP, UDP and SSL communication.

NBClient and NBSSLClient class

The client class creates clients that can connect to servers and send and receive data.

NBModem class

The NBModem class facilitates diagnostic communication with the modem.

NBScanner class

The NBScanner class provides diagnostic information about the network and carrier.

NBPIN class

The NBPIN class has utilities for communicating with the SIM card.

NBUDP class

The UDP class enables UDP message to be sent and received.

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.