A Guide to Getting Started with Arduino Nano 33 BLE Sense

Tinyml kenyaTinyml kenya
8 min read

If you are thinking about deploying a machine learning or an Artificial intelligence project on the Edge, the Arduino Nano 33 BLE Sense is a great device to start with.

The Arduino Nano 33 BLE Sense combines a tiny form factor, different environment sensors and the possibility to run AI using TinyML and TensorFlow™ Lite. Whether you are looking at creating your first embedded ML application or you want to use Bluetooth® Low Energy to connect your project to your phone, the Nano 33 BLE Sense will make that journey easy. In this article, I will guide you on how to get your Arduino Nano 33 BLE sense up and running and also learn about some of its cool features.

This board can be programmed using a micropython, an implementation of python or, C/C++ using a standard API which is also known as the Arduino Programming Language which we will be using . If you are interested in using micropython, you can read all about it here.

Sensors and important parts

Arduino Nano 33 BLE 1. Inertial Measurement Unit (IMU).
2. Color, Brightness, Proximity and Gesture sensor.
3. The Temperature and Humidity (HTS221) sensor.
4. The Barometric Pressure (LPS22HB) Sensor.
5. The Microphone.
6. The Processor

1. Inertial Measurement Unit (IMU)

The Inertial Measurement Unit (IMU) is a LSM9DS1 chip that comes integrated in the board. It features a 3-axis accelerometer, 3-axis gyroscope and 3-axis magnetometer hence making it a 9-axis IMU. This combination of sensors allows the LSM9DS1 to measure linear acceleration, angular velocity, and magnetic field strength in 3D space.I have done some really cool projects with this ,you can read more about it in the Documentation. IMU

2. Color, brightness, proximity and gesture sensor

The Gesture sensor is the APDS9960 module.This module uses a combination of infrared and visible light sensors to detect hand gestures and proximity, which can be used for touchless control of electronic devices. It also includes a color sensor, which can be used for applications such as color matching and identification. The ambient light sensor is used to adjust the brightness of the display based on the surrounding light level. This is one of the sensors that makes the Arduino Nano 33 BLE unique and exciting. you can read more about it in the Documentation.

3. The Temperature and Humidity (HTS221) sensor

The HTS221 is a digital humidity and temperature sensor that is commonly used in various applications. It is a small and low-power sensor that provides accurate measurements of relative humidity and temperature.The sensor is commonly used in a variety of applications, such as weather stations, HVAC systems, and industrial process control. Although if you are using the Arduino Nano 33 BLE Sense Lite the HTS221 sensor is messing although it is included in the list of sensors by the manufacturer, I came to learn about this after being stranded for days , this forum cleared things up. Use the image below to check for the sensor. You can also read more on the sensor from the Documentation HTS221


4. The Barometric Pressure (LPS22HB) Sensor

The LPS22HB is a MEMS (micro-electromechanical system) pressure sensor that is commonly used in various applications. It is a high-resolution digital sensor that provides accurate measurements of atmospheric pressure, and is capable of measuring both temperature and pressure..A popular application of a barometric sensor, apart from GPS and forecasting short term changes in the weather, is the altitude detection according to the atmospheric pressure. Your can read more on the sensor from the Documentation.

5. The Microphone

The MP34DT05 microphone on the board uses a micro-electromechanical system (MEMS) sensing element to convert sound waves into electrical signals. The microphone has a small form factor and is compatible with a range of electronics, including smartphones, tablets, and other portable devices.The MP34DT05 microphone is designed for use in a variety of applications, such as voice recognition, acoustic measurements, and audio recording. I have been able to make cool TinyMl projects with this microphone , you can check out this tutorial by TinyML kenya . You can learn more about the microphone in the Documentation.

6. The Processor

This has to be the most exciting part of the Arduino nano 33 BLE , since its the reason you can run a machine learning model on such a small board and also equips the board with it's bluetooth capabilities.
The processor is called a nRF52840 from Nordic Semiconductors, a 32-bit ARM® Cortex®-M4 CPU running at 64 MHz. The nRF52840 is a powerful microcontroller unit (MCU) that is commonly used in wireless communication and Internet of Things (IoT) applications. It is based on the ARM Cortex-M4F processor and is equipped with a range of features that make it ideal for wireless connectivity. There is alot to be said about this processor so you can read a pdf on it here . a nRF52840

Setting up

Step 1: Install Arduino Nano 33 BLE Sense on board manager

1. Open your Arduino IDE, if you haven't installed it you can install it here.
2. Navigate to Tools > Board > Board Manager.
3. When the board manager opens search for Arduino Mbed OS Nano Boards and install it.
tutri

Step 2: Installing libraries for sensors on the board

1. In your Arduino IDE navigate to Sketch>Include library > Manage libraries, this will open the library Manager
2. Now search for Arduino_APDS9960 and click install (gesture sensor library).
3. Do the same for Arduino_HTS221 , Arduino_LSM9DS1 and ArduinoBLE. This is for the temprature & humidity, IMU and bluetooth libraries respectively.
Tutorial gif

Step 3: Uploading code

1. Now we are going to upload a code to the board , this code will target the gesture sensor , where the sensor will alert us through the serial monitor on simple gestures such as LEFT , RIGHT , UP and DOWN .
Here is the code you can copy it to your IDE as its

#include  <Arduino_APDS9960.h>

void setup() {
  // put your setup code here, to run once:

//intialize the serial monitor
Serial.begin(115200);

////intializing the APDS9960 sensor and include an error message incase it fails
 while (!Serial);
  if (!APDS.begin()) {
    Serial.println("Error initializing APDS9960 sensor!");
  }
Serial.println("Session ON");
}

void loop() {
  // put your main code here, to run repeatedly:



// Read gesture data
  if (APDS.gestureAvailable()) {
    // a gesture was detected, read and print to serial monitor
    int gesture = APDS.readGesture();
    switch (gesture) {
      case GESTURE_UP:
        Serial.println("Detected UP gesture");
        break;
      case GESTURE_DOWN:
        Serial.println("Detected DOWN gesture");
        break;
      case GESTURE_LEFT:
        Serial.println("Detected LEFT gesture");
        break;
      case GESTURE_RIGHT:
        Serial.println("Detected RIGHT gesture");
        break;
      default:
        break;
    }
  }

  delay(500); // wait for half a second before reading again
}

2.Now connect the Arduino nano 33 BLE to your computer using USB cable and save your sketch.
3.Before uploading the code ist select theboard .
select board

4.Then select the port.

Select port

5.Finally upload the code , this might take sometime so be patient.

upload

6. Open the serial monitor and set the baud rate to 115200 (which i found to work best with this board) .

serial monitor

Here are some code samples for that you should try out.

Getting x,y,z readings from the IMU
#include <Arduino_LSM9DS1.h>

void setup() {
  // put your setup code here, to run once:

//initializing the serial monitor
Serial.begin(115200);

//intializing the IMU and include an error message incase it fails
if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }

}

void loop() {
  // put your main code here, to run repeatedly:
float x, y, z;

  // Read accelerometer data
  if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(x, y, z);
    Serial.print("Accelerometer: ");
    Serial.print(x);
    Serial.print(", ");
    Serial.print(y);
    Serial.print(", ");
    Serial.println(z);
  }

  // Read gyroscope data
  if (IMU.gyroscopeAvailable()) {
    IMU.readGyroscope(x, y, z);
    Serial.print("Gyroscope: ");
    Serial.print(x);
    Serial.print(", ");
    Serial.print(y);
    Serial.print(", ");
    Serial.println(z);
  }

  // Read magnetometer data
  if (IMU.magneticFieldAvailable()) {
    IMU.readMagneticField(x, y, z);
    Serial.print("Magnetometer: ");
    Serial.print(x);
    Serial.print(", ");
    Serial.print(y);
    Serial.print(", ");
    Serial.println(z);
  }
//you can comment out the delay for slow readings 
//delay(1000); 
}
Getting Barometer readings
#include <Arduino_LPS22HB.h>

void setup() {
  Serial.begin(115200);
  while (!Serial);

  if (!BARO.begin()) {
    Serial.println("Failed to initialize pressure sensor!");
    while (1);
  }
}

void loop() {
  // read the sensor value
  float pressure = BARO.readPressure();

  // print the sensor value
  Serial.print("Pressure = ");
  Serial.print(pressure);
  Serial.println(" kPa");

  float temperature = BARO.readTemperature();

  // print the sensor value
  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.println(" C");

  // print an empty line
  Serial.println();

  // wait 1 second to print again
  delay(1000);
}
Getting Humidty and temprature readings
#include <Arduino_HTS221.h>

void setup() {
  Serial.begin(115200);
  while (!Serial);

  if (!HTS.begin()) {
    Serial.println("Failed to initialize humidity temperature sensor!");
    while (1);
  }
}

void loop() {
  // read all the sensor values
  float temperature = HTS.readTemperature();
  float humidity    = HTS.readHumidity();

  // print each of the sensor values
  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Humidity    = ");
  Serial.print(humidity);
  Serial.println(" %");

  // print an empty line
  Serial.println();

  // wait 1 second to print again
  delay(1000);
}

Conclusion

The Arduino Nano 33 BLE Sense is an ideal board for anyone looking to innovate or experiment with machine learn on edge and IoT. The possibilties to what can be made with board is only limited by your imagination .

“The advance of technology is based on making it fit in so that you don't really even notice it, so it's part of everyday life.”

Bill Gates, Co-founder of Microsoft

I hope this guide was helpfull to you and you also enjoyed reading it as I did making it .
This tutorial was made by Ryan kiprotich

13
Subscribe to my newsletter

Read articles from Tinyml kenya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tinyml kenya
Tinyml kenya