Menu

📰
0

Esp32 proximity sensor code help

Reddit r/arduino·u/Fast-Albatross1848·about 1 month ago
#mUyL5qvZ
#best#esp32#include#bledevice#cutoff#article
Reading 0:00
15s threshold

I am having trouble getting this code to work on my esp32 devkit called 1965-ESP32-DEVKITM-1-ND could someone give me steps that should allow it to work

#include 
#include 
#include 


const int PIN = 2;
const int CUTOFF = -60;


void setup() {
  pinMode(PIN, OUTPUT);
  BLEDevice::init("");
}


void loop() {
  BLEScan *scan = BLEDevice::getScan();
  scan->setActiveScan(true);
  BLEScanResults results = scan->start(1);
  int best = CUTOFF;
  for (int i = 0; i < results.getCount(); i++) {
    BLEAdvertisedDevice device = results.getDevice(i);
    int rssi = device.getRSSI();
    if (rssi > best) {
      best = rssi;
    }
  }
  digitalWrite(PIN, best > CUTOFF ? HIGH : LOW);
}
Read More