首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印整数值,Arduino HC-05蓝牙模块

打印整数值,Arduino HC-05蓝牙模块
EN

Stack Overflow用户
提问于 2017-09-29 03:47:47
回答 1查看 1.2K关注 0票数 1

我有一个问题,我已经研究了一段时间了。我有一个Arduino Uno板和一个带有TTL输出的HC-05蓝牙收发器。

这些联系如下:

代码语言:javascript
复制
RX (HC_05)  --> TX (Arduino UNO)

TX (HC_05)  --> RX (Arduino UNO)

GND (HC-05) --> GND (Arduino UNO)

+5V (HC-05) --> +5V (Arduino UNO)

我有以下Arduino代码:

代码语言:javascript
复制
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX

void setup()
{
  Serial.begin(9600);
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
  pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  pinMode(10, INPUT);
  pinMode(11, OUTPUT);
  
  digitalWrite(9, HIGH);
  Serial.println("Enter AT commands:");
  BTSerial.println("Welcome to ARBA-Beat");
}


void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available()) {
    Serial.println(BTSerial.read());
    BTSerial.write(BTSerial.read());
    BTSerial.flush();
  }      
}

我通过蓝牙终端安卓应用程序连接蓝牙模块。一切正常工作(甚至蓝牙模块上的灯)。但是,当我从电话中发送一个字符到Arduino时,我得到以下输出:

发送到蓝牙模块的文本-一个

请帮帮忙

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-11-15 23:26:07

我也有过同样的问题。你试过9600运行HC-05吗?尝试下面的代码(用你的引脚)。我用代码来切换插脚2上的继电器,但是如果你想要的话,你可以使用LED。我使用了同样的蓝牙应用程序,效果很好:

代码语言:javascript
复制
#include <SoftwareSerial.h>
int relay = 2; // Set pin for relay control

SoftwareSerial bleserial(8,9);

// setup the relay output and the bluetooth serial, and the serial monitor (if you want to print the outputs)
void setup() {                
  // set relay pin as output.
  pinMode(relay, OUTPUT); 
  // start bluetooth and serial monitor  
  bleserial.begin(9600);
  Serial.begin(9600);

}

void loop() {

  if(bleserial.available()){

    char char1 = bleserial.read();
    Serial.println(char1);
    // Set protocol that you want to turn on the light bulb, I chose 1 and 0 as on and off, respectively

    if(char1=='1'){
      Serial.println("ON");
      digitalWrite(relay,LOW);
    } else if (char1=='0'){
      digitalWrite(relay,HIGH);
    }
  }

}

如果你想看布线等,请查看我博客上的条目:

https://engineersportal.com/blog/2017/11/15/bluetooth-home-automation-light-bulb-switch-using-an-hc-05-a-relay-and-arduino

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46481518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档