问题描述
我的工作与Android和Arduino的一个项目,我试图找出如何在Arduino的一面说,如果蓝牙连接与否。
I'm working on a project with Android and Arduino and am trying to figure out how on the Arduino side to tell if the Bluetooth is connected or not.
我使用的是其中的一个<一href=\"http://www.ebay.com/itm/290859124600?ssPageName=STRK%3aMEWNX%3aIT&_trksid=p3984.m1497.l2649\"相对=nofollow>蓝牙模块进行连接。我知道我可以通过Android的发送命令,但我想有连接时的动作自动发生,而不必运行在Android如果可能的话。
I'm using one of these Bluetooth Modules to connect. I know I can send a command through Android, but I'm trying to have an action happen automatically when they connect and not have to run a background application on the Android if possible.
推荐答案
使用所提供的模块的闲来无事的你不能:注意模块有四个接口:
Using the module supplied and nothing else you cannot: notice the module has four connectors:
- 电源(VCC)
- 接地
- 的Tx(发送)
- RX(接收)
鉴于这种接口,以确定蓝牙模块配对是否是送东西到配对的设备,并让它在如你的Arduino知道它已连接的方式作出反应的唯一途径。举例来说,如果你的Android程序总是与回应你好!,当它接收一个字符串
喂?
,然后通过seingin 喂?
您的Arduino会知道它与你的Android手机/平板电脑配对。你的Arduino可以轮询(发送审讯字符串)每分钟(或每五秒钟),看它是否与您的设备配对。
Given this interface the only way to determine whether the bluetooth module is paired is to send something to the paired device and have it respond in such as way that your Arduino knows that it is connected. For instance, if your Android program always responds with "Hi there!"
when it receives a string "Hello?"
, then by seingin "Hello?"
your Arduino will know that it is paired with your Android phone/tablet. Your Arduino could poll (send the interrogation string) every minute (or every five seconds) to see if it is paired with your device.
有一个更好的方式,但它需要你做一些焊接。如果您的模块是HC-03 / - 基于HC-05,那么PIO9销的配对指示灯(见数据表这里)。你可以将该引脚连接到一个Arduino输入引脚和阅读水平:读取数字 1
将指示装置配对,而读取数字 0
将表明,事实并非如此。这是可能的,虽然不是肯定的,那你的模块的引脚标记状态
正是这种一针,即表示配对状态。不幸。该引脚没有连接到头,所以你必须电线焊接在correctponding垫将其连接到您的Arduino。应该通过在电压模式万用表连接至焊盘第一测试和测量在成对和非成对状态垫和接地之间的电势。如果这是响应对状态引脚那么你是金色的。这可能是它指示电源(如HC-三月五日 PIO8
whilc上闪烁时)。如果事实证明,在状态
引脚不配对的状态,那么你应该从你的供应商索取数据表,并用它来寻找状态LED连接:一个是可能的存在。一旦你找到了正确的垫,再次使用电压表验证其功能。然后焊接电线到连接,并从你的Arduino阅读。
There is a better way, but it will require some soldering on your part. If your module is HC-03/HC-05-based, then the PIO9 pin is the "paired indicator LED" (see datasheet here). You could connect that pin to an Arduino input pin and read the level: reading digital 1
will indicate that the device is paired, while reading digital 0
will indicate that it is not. It is possible, though not certain, that the pin on your module labeled STATE
is exactly this kind of a pin, i.e. it indicates the paired status. Unfortunately. this pin it isn't connected to the header, so you'll have to solder a wire to the correctponding pad to connect it to your Arduino. You should test it first by connecting a multimeter in voltage mode to that pad and measure the potential between that pad and ground in paired and non-paired state. If this is the pin that responds to the paired state then you are golden. It might be that it indicates power (like the HC-03/05 PIO8
whilc blinks when on). If it turns out that the STATE
pin is not the pairing status, then you should request a datasheet from your supplier, and use that to find the status LED connection: one is likely to exist. Once you found the correct pad, verify its function using the voltmeter again. Then solder a wire to that connection and read it from your Arduino.
重要提示:请确保您的Arduino的从不的拿出数码 1
连接到Arduino的引脚上蓝牙模块状态引脚:这些Bluetooth蓝牙模块电压为3.3V运行,并连接任何不受保护的引脚5V将是破坏性的。 VCC和TXD引脚是你买的模块中的电压偏移,但LED /状态行可能不会再有了。因此,如果连接到蓝牙模块上的身份的Arduino的引脚配置为输出和你 digitalWrite(HIGH)
来,你很可能会损坏蓝牙模块。
IMPORTANT: Make sure that your Arduino never puts out a digital 1
on the Arduino pin connected to the bluetooth module status pin: these bluetooth modules run on 3.3V, and connecting any unprotected pins to 5V will be damaging. The Vcc and Txd pins are voltage shifted in the module you bought, but the LED/Status lines are likely not to be. So if the Arduino pin connected to "status" on your Bluetooth module is configured as output and you digitalWrite(HIGH)
to it, you will likely damage the Bluetooth module.
这篇关于什么时候蓝牙模块的Arduino连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!