zfjzfj 发表于 2014-7-31 19:58:39

求助关于蓝牙连接小车

我的是arduino uno + L293D + 传感器扩展板 连接了HC-05蓝牙模块
当arduino连接USB的时候 通过笔记本串口工具发送“1”, 程序能正常亮灯。

但是当USB拔掉后, L293D独立供电,通过笔记本BlueSoleil千月软件 连接配对蓝牙蓝牙模块后,生成一个串口COM8,我在笔记本上用串口工具打开COM8,发送“1”, arduino程序未能执行。。 应该是串口没收到信息。。

请教各位,怎么弄




/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
int val;

// the setup routine runs once when you press reset:
void setup() {               
// initialize the digital pin as an output.
pinMode(led, OUTPUT);   
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
val=Serial.read();
if(val == '1')
{
digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(1000);               // wait for a second
digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
delay(1000);               // wait for a second
}
}

沧海笑1122 发表于 2014-8-1 14:26:07

看看笔记本的蓝牙模块和小车的蓝牙模块是否握手成功(两边模块上的指示灯常亮),你需要检查一下蓝牙模块的设置。一是一主一从,二是波特率一致。

49741933o 发表于 2014-8-1 15:02:22

void loop() {
while(Serial.available())//这个建议加上
{
val=Serial.read();
   if(val == '1')
   
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(1000);
这缺了else               // wait for a second
   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   delay(1000);               // wait for a second
   
}
}具体可以参见我的帖子http://www.geek-workshop.com/thread-10487-1-1.html
页: [1]
查看完整版本: 求助关于蓝牙连接小车