Hi,
I have been following this tutorial: Bluetooth Proximity Detection | FireBeetle ESP32 - YouTube
and have got my circuit and code running as shown (please see attached image of my circuit)
I have tried to modify the code to get a buzzer to vary its volume depending on the distance from the circuit. I am using a Firebeetle ESP32 chip and a bluetooth tag.
I am still very new to coding so I apologise if this seems a stupid way of doing it...
Here is my current code and it verifies with no problems:
#include <BLEAdvertisedDevice.h>
#include <BLEDevice.h>
#include <BLEScan.h>
int rssi;
// const int IO2 = 2;
const int IO5 = 5; //(No resistor, Loudest)
const int IO13 = 13; //(1k resistor, Medium noise level)
const int IO10 = 10; //(5k resistor, Quietest)
const int CUTOFF = -60;
void setup() {
// pinMode(IO2, OUTPUT);
pinMode(IO5, OUTPUT); //Loudest
pinMode(IO13, OUTPUT); // Medium
pinMode(IO10, OUTPUT); // Quietest
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;
// }
}
if (rssi >= -60 && rssi < -50)
{
digitalWrite (IO5,HIGH);
}
else if (rssi >= -50 && rssi < -40)
{
digitalWrite (IO13,HIGH);
}
else if (rssi >= -40)
{
digitalWrite (IO10,HIGH);
}
}
}
If i have missed any information from here please dont hesitate to ask.