MKR IoT Carrier Cheat Sheet

Learn how to set up the MKR IoT Carrier, get a quick overview of the compatible boards, components, and the library.

The Arduino MKR IoT Carrier
The Arduino MKR IoT Carrier

The Arduino® MKR IoT Carrier is equipped with different sensors, actuators and with a display to leave you free to focus on prototyping and programming your next IoT projects. The carrier does not come equipped with a microcontroller, meaning it only works in combination with an Arduino board. The MKR IoT Carrier comes equipped with 5 RGB LEDs, 5 capacitive touch buttons, a colored display, IMU and a variety of quality sensors. It also features a battery holder for a 18650 Li-Ion battery, SD card holder and Grove connectors.

Compatible Boards

The MKR family of boards share a common pinout, meaning that they can all be easily connected to the MKR IoT Carrier. Here is a list of the MKR boards:

The MKR family boards offer different features that can be useful for your projects. You can browse through the boards and pick the one that is most compatible for your project.

Assembly

The chosen Arduino MKR board needs to be mounted on top of the MKR IoT Carrier and connected to a computer. The board can be connected as shown in the image below, matching the pin numbers on the board to the ones on the carrier.

Mounting board on the MKR IoT Carrier
Mounting board on the MKR IoT Carrier

Datasheet

The full datasheet is available as a downloadable PDF from the link below:

Arduino IoT Cloud

The MKR IoT Carrier can be controlled through the Arduino IoT Cloud, a cloud service that allows us to create IoT applications in just minutes, if combined with an Arduino IoT Cloud compatible board. Here's a list of the Arduino MKR family boards that are compatible with the Arduino IoT Cloud:

Note: The MKR GSM 1400 and MKR NB 1500 require a SIM card to connect to the Cloud, as they communicate over the mobile networks. The MKR WAN 1300 and 1310 board requires a Arduino PRO Gateway LoRa to connect to the cloud.

If you need help to get started, you can go through the Arduino IoT Cloud tutorial.

Pinout

The pinout for MKR IoT Carrier
The pinout for MKR IoT Carrier

To see the full pinout, you can download the PDF from the link below.

Grove Connectors

Grove connectors on the MKR IoT Carrier
Grove connectors on the MKR IoT Carrier

The MKR IoT Carrier comes with three grove connectors (2 analog and 1 I2C) that enables us to easily connect external sensors. The type of the connector is labeled clearly on the back of the carrier.

Carrier Library

To program the MKR IoT Carrier, the Arduino_MKRIoTCarrier library needs to be included. This library allows us to control and read all the components of the MKR IoT Carrier. Setting up the MKRIoTCarrier library requires an addition of few code lines in the initialization and setup. Practically speaking, the code used in the initialization and setup is rarely changed, and it is required in every sketch.

Initialization

In the initialization (the very top) of every sketch, the MKRIoTCarrier library needs to be included, which includes the individual libraries of the components mounted onto the carrier.

Next, an object, which is always named

carrier
needs to be added.

1#include <Arduino_MKRIoTCarrier.h>
2MKRIoTCarrier carrier;

Setup

Inside the

setup()
of every sketch that created, 2 lines of code needs to added:

The boolean

CARRIER_CASE
refers to the plastic casing in the kit, and the capacitive buttons on the carrier. It is set to
true
when the plastic casing is used, and to
false
when not. This is not mandatory, as it is set to
false
by default.

The

carrier.begin();
command is essential to initializing the carrier and must be added.

1CARRIER_CASE = false;
2 carrier.begin();

Humidity & Temperature Sensor

The HTS221 Humidity Sensor on the MKR IoT Carrier
The HTS221 Humidity Sensor on the MKR IoT Carrier

The HTS221 Humidity Sensor is mounted on the top side of the carrier under the display, marked with a drop icon. The sensor uses capacitive sensing with a humidity sensing range of 0-100% and accuracy of ± 3.5% rH (20 to +80% rH), and a temperature sensing range of -40 to 120° C, with an accuracy of ± 0.5 °C,15 to +40 °C. The sensor uses a low power consumption (2μA at 1 Hz sampling rate) and connects to the mounted Arduino MKR board through a I2C interface.

Code

The ArduinoHTS221 library is included in the MKRIoTCarrier, meaning that it does not need to include it separately. The values from the temperature and humidity sensors can be stored in float variables as shown below.

1float temperature = carrier.Env.readTemperature();
2float humidity = carrier.Env.readHumidity();

The following methods can be used to get the temperature and humidity values:

1carrier.Env.readTemperature();

Returns temperature value in Celsius.

1carrier.Env.readHumidity();

Returns relative humidity (rH) in percentage.

Pressure Sensor

The LPS22HBTR Pressure Sensor on the MKR IoT Carrier
The LPS22HBTR Pressure Sensor on the MKR IoT Carrier

The LPS22HBTR Pressure Sensor is mounted on the top side of the carrier under the display, marked with a meter icon. The sensor measures absolute pressure range of 260 to 1260 hPa (0.25 to 1.24 atm) and connects to the mounted Arduino MKR board through a I2C interface.

Code

The ArduinoLPS22HB library is included in the MKRIoTCarrier, meaning that it does not need to include it separately. The values from the pressure sensor can be stored in float variables as shown below.

1float pressure = carrier.Pressure.readPressure();

The following methods can be used to get the pressure values:

1carrier.Pressure.readPressure();

Returns pressure value in Kilopascal (kPa).

IMU Accelerometer & Gyroscope Sensors

The IMU on the MKR IoT Carrier
The IMU on the MKR IoT Carrier

The LSM6DSOXTR from STM is an IMU (Inertial Measurement Unit) that features a 3D digital accelerometer and a 3D digital gyroscope. It features among many other things, a machine learning core, which is useful for any motion detection projects, such as free fall, step detector, step counter, pedometer. The unit is placed underneath the MKR IoT Carrier's display, connects to the mounted Arduino MKR board through an I2C interface, and acquires Low power consumption (0.55mA max).

Code

To access the data from the LSM6DSOX module, the MKRIoTCarrier library needs to be included. The carrier's library includes the Arduino_LSM6DS3 and functions similarly. The 3-axis values from the accelerometer and gyroscope sensors can be stored in float variables as shown below:

1float x, y, z;
2
3void loop(){
4 if (carrier.IMUmodule.accelerationAvailable())
5 {
6 carrier.IMUmodule.readAcceleration(x, y, z);
7 Serial.println(x);
8 }
9}

The following methods can be used to detect movement:

1carrier.IMUmodule.accelerationAvailable();

Returns 0 if no new acceleration data sample is available, 1 if new acceleration data sample is available.

1carrier.IMUmodule.readAcceleration(x, y, z);

Allows as to access the acceleration data on the three axis (x, y & z).

RGB and Gesture Sensor

The APDS-9660 sensor on the MKR IoT Carrier
The APDS-9660 sensor on the MKR IoT Carrier

The MKR IoT Carrier contains a Broadcom APDS-9660 RGB and Gesture sensors, situated under the display and marked with a bulb icon. The sensor is useful for ambient light and RGB color sensing, proximity sensing, and gesture detection.

Code

The ArduinoAPDS9960 library is included in the MKRIoTCarrier, meaning that it does not need to include it separately. The color values from the RGB sensor can be stored in int variables as shown below.

The

carrier.Light.readColor(r, g, b);
method can be used to detect colors.

The if statement

if (r >= 135 && g >= 135 && b >= 135)
in the code below checks if the color detected ranges from light gray to white, but the numbers assigned to red (r), green (g) and blue (b) can be customized to any desired color.

1int r, g, b;
2
3 void loop(){
4
5 if (carrier.Light.colorAvailable()){
6 carrier.Light.readColor(r, g, b); //read rgb color values
7
8 // check if color/light is bright enough
9 if (r >= 135 && g >= 135 && b >= 135){
10 Serial.print("White color detected");
11 }
12 }
13 }

The following methods can be used to detect gesture:

1carrier.Light.gestureAvailable();

Checks the availability of the gesture sensor.

1carrier.Light.readGesture();

Confirms which gesture is being detected, and returns UP, DOWN, RIGHT or LEFT.

The code example below shows the gesture value in a fixed width integer

uint8_t
variable, and the if statement checks
if (gesture == UP)
. To detect movements in other directions, UP can be replaced with DOWN, RIGHT or LEFT.

1void loop(){
2
3 if (carrier.Light.gestureAvailable())
4 {
5 uint8_t gesture = carrier.Light.readGesture(); // a variable to store the type of gesture read by the light sensor
6 Serial.print("Gesture: ");
7
8 // when gesture is UP
9 if (gesture == UP)
10 {
11 Serial.println("UP");
12 }
13 }

Relays

The relays on the MKR IoT Carrier
The relays on the MKR IoT Carrier

The MKR IoT Carrier is equipped with two 5V Coil voltage KEMET EE2-5NU-L relays, located on the back side of the carrier. The relays are non-latching with a COM (common), NO (Normally open) and NC (normally closed) contacts, and can take up a max of 2A Current and 24 V of input each.

The connections between a high power circuit and the relays will be done through these connectors.

The relays connectors
The relays connectors

Once the cables are introduced inside the connectors, they will automatically be locked inside. To unlock a cable and remove it from the connector, a tool is needed to be inserted through the top square hole (it can be a flat screwdriver, a hard piece of plastic, etc.).

The L1 and L2 LEDs indicators
The L1 and L2 LEDs indicators

The L1 and L2 LEDs on the carrier are visual indicators of the state of the relays. If the LED is ON, it means that the COM and the NO terminal of the relay are connected, and if the LED is OFF it means that COM and NC are connected.

Code

The

carrier.RelayX.open();
and
carrier.RelayX.close();
methods can be used to control the relays, and
carrier.RelayX.getStatus();
to read the status of the relays.

Swap to the Normally Open (NO) circuit of relay 1 (turns it on):

1carrier.Relay1.open();

Swap to the Normally Closed (NC) circuit of relay 2 (turns it off), default mode on power off:

1carrier.Relay2.close();

Bool, returns the status LOW means NC and HIGH means NO:

1carrier.Relay2.getStatus();

Peripherals

Display

The MKR IoT Carrier's display
The MKR IoT Carrier's display

The screen on the MKR IoT Carrier is a rounded 1.3” TFT display, with a 240 x 240 resolution and a diameter of 36 x 40 mm.

Code

The display is controlled through the Adafruit-ST7735-Library, which is included in the carrier's library, meaning that it does not need to be added it separately.

Below are some methods to configure the MKR IoT Carrier's display, these include basic configurations, background and text colors, font size, position of the cursor and a loading animation.

1carrier.display.fillScreen(color);

This method sets the color of the background of the display using hex codes.

1carrier.display.setRotation(0);

This method sets the angle of the screen, 0 is the starting position with no rotation.The screen can only be rotated 90, 180 or 270 degrees by replacing the 0 with 1, 2 or 3.

1display.print("text");

This method will print the text inside the string at the current cursor position.

1carrier.display.drawBitmap(x, y, bitmap_visual, w, h, color);

This method displays a bitmap visual on the carrier's screen. The values x & y values are the top left coordinates where the visual is drawn, w & h are the width and height of the visual. The data for the bitmap_visual graphic can be stored as a byte array and used as the

bitmap_visual
.

1carrier.display.setTextColor(color);

This method sets the color of the text using hex codes.

1carrier.display.setTextSize(number);

This method sets the text size. 2 is an average text size since it is visible, but not too small, 3 is a bit larger.

1carrier.display.setCursor(x, y);

This method is very important, as it indicates where on the printing starts on the display. It is indicated by pixels, so, if 0, 0 are used for example, it will start printing in the top left corner.

Buttons

The MKR IoT Carrier's buttons
The MKR IoT Carrier's buttons

The carrier has five capacitive qTouch buttons on its top side, numbered from 00 to 04. The buttons are sensitive to direct touch and detect wireless touch.

Code

The Button class can be controlled using the following methods:

1Buttons.update();

Reads the state of the pads and save them to be used in the different types of touch events.

1Buttons.getTouch(TOUCHX);

Get if the pad is getting touched, true until it gets released.

1Buttons.onTouchDown(TOUCHX);

Get when have been a touch down.

1Buttons.onTouchUp(TOUCHX);

Get when the button has been released.

1Buttons.onTouchChange(TOUCHX);

Get both, touched and released.

TOUCH0
,
TOUCH1
,
TOUCH2
,
TOUCH3
,
TOUCH4
can be used to access each individual button. The code example below shows how the status of a button can be checked.

1void loop(){
2 // updates buttons status
3 carrier.Buttons.update();
4
5 // Checks if button 00 is touched
6 if (carrier.Buttons.onTouchDown(TOUCH0))
7 {
8 Serial.print("Button 0 pressed down");
9 }
10 }

LEDs

The LEDs on the MKR IoT Carrier
The LEDs on the MKR IoT Carrier

The MKR IoT Carrier comes with 5 digital RGB LEDs placed on the top side of the carrier in front of the buttons.

Code

The LEDs are controlled with the Adafruit’s DotStar library, which is included in the

MKRIoTCarrier
library.

The

carrier.leds.show();
method is necessary for updating the new state of the LEDs and needs to be called after any change of the state of the LEDs (turning on & off or change of color).

Here are some of the useful methods used to control the LEDs on the MKR IoT Carrier:

1carrier.leds.setPixelColor(index, green, red, blue);

Sets the color of the index’s LED.

1carrier.leds.setBrightness(0-255)

Set the overall brightness, from 0 (no brightness) to 255 (maximum brightness).

1carrier.leds.clear()

Clear the buffer of the LEDs.

1carrier.leds.fill(color, firstLedToCount, count);

Fill X amount of the LEDs with the same color.

1uint32_t myColor = carrier.leds.Color(green, red, blue)

Saves a custom color.

The code example below shows how to light up all 5 LEDs with our customized color.

1#include <Arduino_MKRIoTCarrier.h>
2MKRIoTCarrier carrier;
3
4uint32_t myCustomColor = carrier.leds.Color(255,100,50);
5
6void setup(){
7 CARRIER_CASE = false;
8 carrier.begin();
9 carrier.leds.fill(myCustomColor, 0, 5);
10 carrier.leds.show();
11}

Buzzer

The buzzer on the MKR IoT Carrier
The buzzer on the MKR IoT Carrier

The MKR IoT Carrier is equipped with a sound buzzer on the bottom side of the carrier, under the MKR board.

Code

The buzzer can be controlled with the following methods:

1carrier.Buzzer.sound(freq)

Equivalent to tone(), it will make the tone with the selected frequency.

1carrier.Buzzer.noSound()

Equivalent to noTone(), it will stop the tone signal.

Memory

The MKR IoT Carrier contains a SD Card slot that accepts a Micro SD, which allows for three times the amount of data storage locally.

Code

The memory can be used with the SD library commands that is already included in the

MKRIoTCarrier
library

The SD class initialized in the main

carrier.begin()
. In order to save our data on a specific file, the method
SD.open("file-name", FILE_WRITE))
can be used. The code below demonstrates how to save data on a file on a SD card.

1#include <Arduino_MKRIoTCarrier.h>
2MKRIoTCarrier carrier;
3
4File myFile;
5
6setup(){
7 CARRIER_CASE = false;
8 carrier.begin(); //SD card initialized here
9
10 myFile = SD.open("test.txt", FILE_WRITE);
11}

Power

JST battery connector on the MKR IoT Carrier.
JST battery connector on the MKR IoT Carrier.

The MKR IoT Carrier can be either powered through a USB cable connected to the mounted MKR board, or through a battery. The battery used should be a LI-ION 18650 3.7 v battery, which can be mounted to the carrier via the battery holder on the bottom side.

A cable with JST connectors on both ends are needed to connect the MKR IoT Carrier and the MKR board. The Battery can then be recharged via a USB connection through the MKR Board (Runs up to 48h with a 3.7v 2500mAh).

Tutorial Toolbox

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.