今天小编带来是创客Hamid Sheibani的项目:钥匙寻找器。使用了XIAO nRF52840开发板,与钥匙串结合,让你告别日常寻找钥匙的烦恼!
背景故事
该设备利用低功耗蓝牙(BLE)技术,与智能手机同步,通过蜂鸣器和LED灯帮助用户轻松找到遗失的钥匙。本文将探讨这款基于XIAO nRF52840模块的智能钥匙定位器的开发过程,并展示其核心功能。
材料清单
硬件
Seeed XIAO BLE nRF52840 Sense × 1
蜂鸣器 × 1
LED × 1
软件
nRF Connect SDK
Seeed Fusion
核心组件及作用
这款智能钥匙寻找器的核心是XIAO NRF52840模块,这是一款小巧强大的开发板,内置ARM Cortex-M4处理器,专为低功耗蓝牙(BLE)通信而设计。其功能的实现离不开以下关键组件:
蜂鸣器:通过发出独特声音,帮助钥匙主人快速找到钥匙
LED灯:在昏暗环境下,LED灯发出亮光,让丢失的钥匙轻松现身。
按钮:这实用的组件负责在找到钥匙后关闭蜂鸣器和LED灯。
硬件配置
通过XIAO nRF52840的通用输入输出(GPIO)引脚连接到蜂鸣器、LED灯和按钮。
程序逻辑与Arduino IDE
Arduino IDE:通过功能强大的Arduino集成开发环境(IDE),固件程序得以实现,重点开发稳定的BLE功能,实现与智能手机的无缝通信。
BLE同步:通过nRF Connect应用,钥匙定位器与智能手机建立BLE连接,搭建指令传输的桥梁。
指令执行:固件程序的核心是接收智能手机信号后精准执行指令,从而激活蜂鸣器和LED灯,引导用户找到钥匙。
高效电源管理:为了延长电池寿命,固件集成了智能省电机制,在设备空闲时切换到低功耗模式。
以下是可参考的Arduino代码:
#includeBLEService KeyFinderService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth Low Energy KeyFinder Service // Bluetooth Low Energy Key Finder Characteristic - custom 128-bit UUID, read and writable by central BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); const int ledPin = LED_BUILTIN; // pin to use for the LED void setup() { Serial.begin(115200); // set LED pin to output mode pinMode(ledPin, OUTPUT); pinMode(D6, OUTPUT); pinMode(D5, OUTPUT); pinMode(D7, INPUT); // begin initialization if (!BLE.begin()) { Serial.println("starting Bluetooth Low Energy module failed!"); while (1); } // set advertised local name and service UUID: BLE.setLocalName("KeyFinder"); BLE.setAdvertisedService(KeyFinderService); // add the characteristic to the service KeyFinderService.addCharacteristic(switchCharacteristic); // add service BLE.addService(KeyFinderService); // set the initial value for the characeristic: switchCharacteristic.writeValue(0); // start advertising BLE.advertise(); Serial.println("BLE Key Finder Peripheral"); } void loop() { // listen for Bluetooth Low Energy peripherals to connect: BLEDevice central = BLE.central(); // if a central is connected to peripheral: if (central) { Serial.print("Connected to central: "); // print the central's MAC address: Serial.println(central.address()); // while the central is still connected to peripheral: while (central.connected()) { if (switchCharacteristic.written()) { if (switchCharacteristic.value()) { Serial.println("LED on"); digitalWrite(ledPin, LOW); // changed from HIGH to LOW digitalWrite(D5, HIGH); while(1) { tone(D6, 500, 500); delay(1000); if(digitalRead(D7) == 0) { Serial.println(F("LED off")); digitalWrite(ledPin, HIGH); // changed from LOW to HIGH digitalWrite(D5, LOW); digitalWrite(D6, LOW); break; } } } } } // when the central disconnects, print it out: Serial.print(F("Disconnected from central: ")); Serial.println(central.address()); } }
操作流程
BLE配对:通过nRF Connect应用,智能手机能够检测到钥匙定位器的存在,并建立BLE连接,打开了一个无缝的通信通道。
指令传输:智能手机传输预设的指令,激活蜂鸣器和LED灯,提供定位钥匙的提示。
轻松发现:用户只需跟随听得见的提示音和LED灯的引导,便能快速高效地找到钥匙,告别忙乱的寻找过程。
优势与实际应用场景
量身定制的用户体验:可定制的固件使用户能够根据个人偏好调整声音和灯光模式。
适应性强的设计:该设备具备未来扩展的潜力,可以集成更多传感器,保持灵活与适应性。
紧急援助:除了作为钥匙寻找器,这款设备还能在关键时刻作为SOS信号灯,提供紧急求助功能。
结论
这款基于XIAO nRF52840模块的钥匙寻找器,通过BLE连接,优雅地弥合了日常物品与智能解决方案之间的差距,展示了技术的纯粹魅力。
全部0条评论
快来发表一下你的评论吧 !