I am using Arduino Nano 33 BLE.
I connected the board to my laptop and uploaded a sketch for ble.
Using nRF Connect app, the arduino board can be scanned and connected.
But the problem is the next. After I disconnected the board from my laptop and used other power such as phone charger, my arduino board can't be scanned by nRF Connect although the led turned on, so power is supplied well.
I want to make a portable product with BLE, so this is the problem unless there is a really small computer.
What should I do to solve this problem?
For reference, here's my ble code.
#include <ArduinoBLE.h>
int x, y, z;
BLEService customService("180C");
BLEIntCharacteristic ble_x("6eea5885-ed94-4731-b81a-00eb60d93b50", BLERead | BLENotify);
BLEIntCharacteristic ble_y("03d0cffe-bd7f-4d17-ba39-86e57adb5ddd", BLERead | BLENotify);
BLEIntCharacteristic ble_z("c8411116-479e-4bc7-a216-1e3c22d32809", BLERead | BLENotify);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while(!Serial){;}
if (!BLE.begin()){
Serial.println("BLE failed to Initiate");
delay(500);
while (1) {;}
}
BLE.setLocalName("Arduino Environment Joystick");
BLE.setAdvertisedService(customService);
customService.addCharacteristic(ble_x);
customService.addCharacteristic(ble_y);
customService.addCharacteristic(ble_z);
BLE.addService(customService);
BLE.advertise();
Serial.println("Bluetooth devic is now active, waiting for connections...");
}
void loop() {
// put your main code here, to run repeatedly:
BLEDevice central = BLE.central();
if (central)
{
Serial.print("Connected to central : ");
Serial.println(central.address());
while(central.connected())
{
delay(200);
x=analogRead(A0);
y=analogRead(A1);
z=digitalRead(5);
ble_x.writeValue(x);
ble_y.writeValue(y);
ble_z.writeValue(z);
Serial.println("Reading Sensors");
Serial.println("x : "+ String(x));
Serial.println("y : "+String(y));
Serial.println("z : "+String(z));
delay(500);
}
}
Serial.print("Disconnected from central: "+central.address());
}