BLE detection help


Im currently running through one of the BLE examples and am wondering if there is a way to shorten the range of detection. In the example im doing i have 2 argon boards, 1 as the main device and 1 that advertises. The main device turns on an LED depending on the other devices signal strength and assigned colour.

I have pasted my code but unsure where or how to shorten the signal detection, i think its something to do with the rssi, currently the device is detected from quite a distance but i’d like to experiment with shortening it if possible.

any advice would be appreciated.

#include "Particle.h"

// This example does not require the cloud so you can run it in manual mode or
// normal cloud-connected mode

SerialLogHandler logHandler(LOG_LEVEL_TRACE);

const size_t SCAN_RESULT_MAX = 30;
int Led1 = D4;

BleScanResult scanResults[SCAN_RESULT_MAX];

void setup() {
    (void)logHandler; // Does nothing, just to eliminate the unused variable warning
    pinMode(Led1, OUTPUT);

void loop() {
    // Only scan for 500 milliseconds
    int count = BLE.scan(scanResults, SCAN_RESULT_MAX);

    uint32_t curColorCode;
    int curRssi = -999;

    for (int ii = 0; ii < count; ii++) {
        uint8_t buf[BLE_MAX_ADV_DATA_LEN];
        size_t len;

        // When getting a specific AD Type, the length returned does not include the length or AD Type so len will be one less
        // than what we put in the beacon code, because that includes the AD Type.
        len = scanResults[ii].advertisingData.get(BleAdvertisingDataType::MANUFACTURER_SPECIFIC_DATA, buf, BLE_MAX_ADV_DATA_LEN);
        if (len == 7) {
            // We have manufacturer-specific advertising data (0xff) and it's 7 bytes (without the AD type)

            // 16-bit: Company ID (0xffff)
            // Byte: Internal packet identifier (0x55)
            // 32-bit: Color code

            if (buf[0] == 0xff && buf[1] == 0xff && buf[2] == 0x55) {
                // Company ID and internal packet identifier match

                uint32_t colorCode;
                memcpy(&colorCode, &buf[3], 4);

      "colorCode: 0x%lx rssi=%d address=%02X:%02X:%02X:%02X:%02X:%02X ",
                        colorCode, scanResults[ii].rssi,
                        scanResults[ii].address[0], scanResults[ii].address[1], scanResults[ii].address[2],
                        scanResults[ii].address[3], scanResults[ii].address[4], scanResults[ii].address[5]);

                if (scanResults[ii].rssi > curRssi) {
                    // Show whatever device has the strongest signal
                    curRssi = scanResults[ii].rssi;
                    curColorCode = colorCode;
                    digitalWrite(Led1, HIGH);
                else { 
                    digitalWrite(Led1, LOW);
    if (curRssi != -999) {
    else {
        digitalWrite(Led1, LOW);

Thank you,


Not entirely sure what you are asking for, but maybe have a look at
BLE.setTxPower() whether this helps your cause.

(sorry reread the post: It’s not time but distance you want to reduce :blush: - updated link)

Thank you I will take a look.

Basically I only want the LED to turn on when the device is within say 2 metres. So I’m assuming this will have something to do with, only turn on when the signal strength is a certain amount. Just figuring out how to set it is my problem :slight_smile:

Appreciate the swift reply!