Level up your TinyML skills

The Ultimate Guide to Arduino Indoor Positioning

Localize people and objects as they move around your office, building or store with the power of Machine Learning

Arduino Indoor Positioning

Locating people and objects as they move around a known environment is a common problem in many scenarios:

  • you are a store-owner and you want to track customers as they move around the aisles while shopping
  • you manage a smart factory and want to know at any time where your employees and lifters are located
  • you are a creative willing to make the environment react to people walking around
  • you are a robotics enthusiast who wants to implement a basic navigation system for his robot

A few commercial solutions exists on the market, but they require you to invest thousands of dollars in proprietary technology.

This project will show you how you can implement your own indoor positioning system using open source Arduino hardware and free software with a minimal economic commitment, without writing any code!

What is Indoor Positioning?

As stated from Wikipedia, an Indoor Positioning System is a network of devices used to locate objects where GPS is not an option.

In the context of this project, Indoor Positioning refers to the ability of a device (an Arduino board) to recognize in which room/zone it is in a known environment .

For example: if you map your house, it can tell that you're in the kitchen, or in the bedroom, but it won't tell you how far from the front door you are.

This is not a GPS-like navigation system that can track your exact position as you move around a place! It gives you a rough idea.

How does it work?

To implement an Indoor positiong system you need a number of hotspots (or repeaters) that emit a radio signal. Your device will hear the strength of these signals and use a Machine Learning model to detect in which location it currently is.

The system stays independent from the kind of radio you use. It can work with:

For the purpose of this project, we'll use WiFi because:

  1. you can find several Arduino boards equipped with WiFi
  2. if you live in an urban area, there are chances you are already surrounded by hotspots

How accurate is Indoor Positioning?

It's hard to assess how accurate such an Indoor Positioning System can be.

It depends on a variety of factors:

  • which kind of radio you use
  • how many Access Points you have nearby
  • how far they are from your location
  • how they are distributed
  • how wide your location is
  • if you have walls or obstacles in between

Out of the box, you can expect a resolution of few meters.

Since the cost of hotspots can be as low as a few dollars (if you choose the ESP32s, for example), you can always add as much hotspots as your project requires to get the accuracy you need.



Now that the theory is done, let's move to the practice!

Prepare your environment

There is a single strict requirement to follow this project: an Arduino WiFi board and a basic knowledge on how to use it (load a sketch, open the Serial monitor).

You can find many on the market: any will do the job. Below you can find a few examples.

Part List

Arduino MKR WiFi 1010
Arduino MKR WiFi 1010
x 1
Arduino Nano 33 IoT
Arduino Nano 33 IoT
x 1
Esp32
Esp32
x 1

If you live in a rural area or you want to map your own location, you will need a few more boards to act as hotspots, too. Then place them around homogeneously.

Before continuing, please install the EloquentArduino library version 2.1.3 or above in the Arduino IDE. Install EloquentArduino library version 2.1.3 in Arduino IDE

Your own WiFi Indoor Positioning System in 3 Easy Steps

If you were to implement a WiFi indoor positioning system by yourself, it would require a good level of knowledge in both Arduino development and Machine Learning. We worked hard to remove as much friction as possible from the process and make it beginner-friendly, so don't be afraid.

You only need to follow these 3 steps to succeed:

  1. Load the scanner sketch on your board and move into each room/zone you want to detect to record the visible hotspots
  2. Train a Machine Learning model in the cloud to distinguish each room/zone
  3. Deploy the trained model to your Arduino board and start detecting

You will be able to later customize the resulting sketch as per your needs, but for the moment we'll start as simple as possible and just print the location you are in to the Serial monitor.

Step 1: Map your Location

First step to implement your own WiFi Indoor Positioning System is to map the location you want to "navigate".

By mapping we mean you will walk around all the places you want to be able to detect, with the purpose to characterize each location. Each location will be defined by a set of Hotspot+RSSI pairs, so we need to record these sets in as many points as possible to create a robust model.

What does RSSI mean? It stands for Received Signal Strength Indication and is a number indicating how strong a received signal is. The stronger the signal, the higher the RSSI.

Load the following sketch on your board.

 /**
 * WiFi scanner example
 * Print WiFi hotspots with their RSSI in Json format
 *
 * Enter the name of the location to start scanning
 * Enter 'stop' to stop the scanning
 */

// replace with WiFiNINA.h if you use a different board
#include "WiFi.h"

#include "eloquent.h"
#include "eloquent/networking/wifi/WifiScanner.h"


String location;


void setup() {
    Serial.begin(115200);
    delay(2000);
    Serial.println("Instructions:");
    Serial.println("\tEnter the name of the location to start scanning");
    Serial.println("\tEnter 'stop' to stop scanning");

    // you can identify networks either by MAC address
    wifiScanner.identifyByMAC();
    // or SSID (default)
    wifiScanner.identifyBySSID();
}

void loop() {
    // await user to input his current location or "stop" to abort scanning
    if (Serial.available()) {
        location = Serial.readStringUntil('\n');
    }

    // if a location is set, perform scan
    if (location != "" && location != "stop") {
        Serial.print(location);
        Serial.print(": ");
        wifiScanner.scan();
        wifiScanner.printAsJson(Serial);
        delay(2000);
    }
}
 

The sketch is a WiFi scanner that prints to the Serial monitor the visible networks along with their RSSI in a format that is suitable for further processing.

For every location you want to be able to recognize, position yourself in the center and enter the name of the location. The detected hotspots will appear on the Serial monitor.

Start moving around, go to the corners of the room / space, walk along the walls, then go back to the center.

At this point enter "stop" to stop the scanning. You should record at least 10-15 lines for each location.

Repeat the process for each room/space you want to map.

When you're done, you will have a text similar to the following on your Serial Monitor.

Living room: {"Hotspot001": 2, "Hotspot002": 3}
Living room: {"Hotspot001": 2, "Hotspot002": 3}
Living room: {"Hotspot001": 2, "Hotspot002": 3}
Kitchen: {"Hotspot003": 2, "Hotspot002": 10}
Kitchen: {"Hotspot003": 2, "Hotspot002": 11}
Kitchen: {"Hotspot003": 2, "Hotspot002": 9}
Bed room: {"Hotspot003": 2, "Hotspot002": 3, "Hotspot001": 5}
Bed room: {"Hotspot003": 2, "Hotspot002": 1, "Hotspot001": 4}
Bed room: {"Hotspot003": 1, "Hotspot002": 3, "Hotspot001": 5}

Step 2: Train a Machine Learning Model in the Cloud

This is probably the easiest step of the whole process.

Once you have mapped all your locations, paste the contents of the Serial monitor into the textarea below. If you don't see any complaint about syntax errors, hit the Train model button et voilà!

Train model
powered by AWS Lambda
max 3 requests/minute

Step 3: Deploy & Customize

You now have a Machine Learning model able to detect where you're located based on the nearby WiFi access points.

Seems too good to be true?

Test by yourself: copy-paste the code above into an Arduino sketch and hit Upload.

Then start moving around the space you mapped and watch the predictions appear on the Serial monitor.

The given sketch showcases a couple constructs you can integrate in your own sketch:

  • one gives you the detected location as string
  • the other checks for a specific location

How exactly you will take advantage of this functionality depends on the project you want to implement.


As you can see, it is easier than ever to leverage the power of Machine Learning in the cloud to implement your own WiFi Indoor Positioning System with Arduino compatible boards.

Were you able to follow the tutorial step by step?

Did you succeded implementing your own camera Wifi indoor positioning with Arduino?

Drop me a line if you're having trouble or you think your businees will benefit from such a technology.

Visit the Github project page for the full code.

Use BLE instead of WiFi

Notify me via email when BLE version is ready

We use Mailchimp as our marketing platform. By submitting this form, you acknowledge that the information you provided will be transferred to Mailchimp for processing in accordance with their terms of use. We will use your email to send you updates relevant to this website.

Having troubles? Ask a question

Need a one to one call? Book now!

© Copyright 2022 Eloquent Arduino. All Rights Reserved.