解决方案。

条件:

1.手机android 商店下载 blueTerm

2.向arduino中载入如下代码:

char val;
;
void setup()
{
  Serial.begin();
  pinMode(ledpin,OUTPUT);
}

void loop()
{
  val=Serial.read();
  if(val=='o')
  {
    digitalWrite(ledpin,HIGH);
    Serial.println("LED ON!");
  }else if(val=='f'){
  digitalWrite(ledpin,LOW);
Serial.println("LED OFF!");
  }
}

3. 将蓝牙模块的RxD链接到arduino的Tx口上,蓝牙的TxD链接到arduino的Rx口上。

4. 打开android的blueTerm ,链接到蓝牙,默认密码1234。

链接上,在手机上输入,o

led灯亮。

键入f

led灭。

挺简单的。

——————————————————————————————————————

如果想把蓝牙放到别的口上,不占用Pin1,2 arduino与计算机默认的串口。

那就用下面的方法,模拟一个serial port, 比如说用Pin6,7 与单片机通讯。

下面的代码做参考使用:

http://arduinobasics.blogspot.com/2013/01/arduino-basics-bluetooth-tutorial.html

/* This project combines the code from a few different sources.
This project was put together by ScottC on the 15/01/2013
http://arduinobasics.blogspot.com/

Bluetooth slave code by Steve Chang - downloaded from :
http://www.seeedstudio.com/wiki/index.php?title=Bluetooth_Shield

Grove Chainable RGB code can be found here :
http://www.seeedstudio.com/wiki/Grove_-_Chainable_RGB_LED#Introduction

*/

#include <SoftwareSerial.h> //Software Serial Port

#define uint8 unsigned char
#define uint16 unsigned int
#define uint32 unsigned long int

#define RxD 6 // This is the pin that the Bluetooth (BT_TX) will transmit to the Arduino (RxD)
#define TxD 7 // This is the pin that the Bluetooth (BT_RX) will receive from the Arduino (TxD)

#define DEBUG_ENABLED 1

; //RGB LED Clock Pin (Digital 9)
; //RGB LED Data Pin (Digital 8)

SoftwareSerial blueToothSerial(RxD,TxD);

/*----------------------SETUP----------------------------*/
void setup() {
 Serial.begin(); // Allow Serial communication via USB cable to computer (if required)
 pinMode(RxD, INPUT); // Setup the Arduino to receive INPUT from the bluetooth shield on Digital Pin 6
 pinMode(TxD, OUTPUT); // Setup the Arduino to send data (OUTPUT) to the bluetooth shield on Digital Pin 7
 pinMode(,OUTPUT); // Use onboard LED if required.
 setupBlueToothConnection(); //Used to initialise the Bluetooth shield

 pinMode(Datapin, OUTPUT); // Setup the RGB LED Data Pin
 pinMode(Clkpin, OUTPUT); // Setup the RGB LED Clock pin

} 

/*----------------------LOOP----------------------------*/
void loop() {
 digitalWrite(,LOW); //Turn off the onboard Arduino LED
 char recvChar;
 ){
 if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
 recvChar = blueToothSerial.read();
 Serial.print(recvChar); // Print the character received to the Serial Monitor (if required)

 //If the character received = 'r' , then change the RGB led to display a RED colour
 if(recvChar=='r'){
 Send32Zero(); // begin
 DataDealWithAndSend(, , ); // first node data
 Send32Zero(); // send to update data
 }

 //If the character received = 'g' , then change the RGB led to display a GREEN colour
 if(recvChar=='g'){
 Send32Zero(); // begin
 DataDealWithAndSend(, , ); // first node data
 Send32Zero(); // send to update data
 }

 //If the character received = 'b' , then change the RGB led to display a BLUE colour
 if(recvChar=='b'){
 Send32Zero(); // begin
 DataDealWithAndSend(, , ); // first node data
 Send32Zero(); // send to update data
 }
 }

 //You can use the following code to deal with any information coming from the Computer (serial monitor)
 if(Serial.available()){
 recvChar = Serial.read();

 //This will send value obtained (recvChar) to the phone. The value will be displayed on the phone.
 blueToothSerial.print(recvChar);
 }
 }
} 

//The following code is necessary to setup the bluetooth shield ------copy and paste----------------
void setupBlueToothConnection()
{
 blueToothSerial.begin(); //Set BluetoothBee BaudRate to default baud rate 38400
 blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
 blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
 blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
 blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
 delay(); // This delay is required.
 blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
 Serial.println("The slave bluetooth is inquirable!");
 delay(); // This delay is required.
 blueToothSerial.flush();
}

//The following code snippets are used update the colour of the RGB LED-----copy and paste------------
void ClkProduce(void){
 digitalWrite(Clkpin, LOW);
 delayMicroseconds();
 digitalWrite(Clkpin, HIGH);
 delayMicroseconds();
}

void Send32Zero(void){
 unsigned char i;
 ; i<; i++){
 digitalWrite(Datapin, LOW);
 ClkProduce();
 }
}

uint8 TakeAntiCode(uint8 dat){
 uint8 tmp = ;
 ){
 tmp |= 0x02;
 }

 ){
 tmp |= 0x01;
 }

 return tmp;
}

// gray data
void DatSend(uint32 dx){
 uint8 i;
 ; i<; i++){
 ){
 digitalWrite(Datapin, HIGH);
 } else {
 digitalWrite(Datapin, LOW);
 }

 dx <<= ;
 ClkProduce();
 }
}

// data processing
void DataDealWithAndSend(uint8 r, uint8 g, uint8 b){
 uint32 dx = ;

 dx |= (uint32); // highest two bits 1,flag bits
 dx |= (uint32)TakeAntiCode(b) << ;
 dx |= (uint32)TakeAntiCode(g) << ;
 dx |= (uint32)TakeAntiCode(r) << ;

 dx |= (uint32)b << ;
 dx |= (uint32)g << ;
 dx |= r;

 DatSend(dx);
}

Please take good notice of the references blow of the link which I give you above.

No third lib required. Only original one.

***********************************************************************

Also here's another project about how to control arduino widgets via bluetooth protocol.

Bluetooth , motor, android, arduino

http://www.instructables.com/id/Arduino-Control-DC-Motor-via-Bluetooth/step3/Arduino-Code/

Arduino 各种模块篇 蓝牙模块 手机蓝牙控制Arduino LED灯的更多相关文章

  1. arduino 蓝牙控制RGB LED灯

    /* 日期:2016.9.2 功能:arduino 蓝牙控制RGB LED灯 元件: 跳线公公头 * 8 rgbled, 220欧电阻 蓝牙模块 接线: 蓝牙模块VCC,GND分别接5V,GND;TX ...

  2. Arduino 各种模块篇 GPRS module 手机模块 短信 电话 上网 for texting, calling, internet

    ---恢复内容开始--- The GPRS shield which I tested is one which looks like this: ---恢复内容结束--- Need to be re ...

  3. Arduino 各种模块篇 摇杆模块

    Arduino的另外几种模块,我们常见的joystick摇杆模块. 用起来很爽,摇杆 有X,Y轴可调 这里有一篇非常想尽的示例代码: http://www.geek-workshop.com/foru ...

  4. Arduino 各种模块篇 震动模块 vibrator module

    The vibrator I got works at the voltage ranging from 3.3V ~ 5.5V I want to make it vibrate variably. ...

  5. Arduino 各种模块篇 震动模块 vibrator

    vibrator is a good thing. it has multi-funtionality . :) Now the  vibrator we choose is the one whic ...

  6. [TPYBoard-Micropython之会python就能做硬件 7] 学习使用蓝牙模块及舵机

    转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi            欢迎加入讨论群 64770604 一.实验器材 1.TPYboard V102板  一块 2 ...

  7. 51单片机 HC05蓝牙模块

    一.注意事项 1.烧写程序时,要把蓝牙tx,rx信号线拔掉,对烧写程序有影响. 2.执行HC05集命令时,均以\r\n结尾.串口中断若选择“发送新行”时,不用添加\r\n.原理相同. 二.准备软硬件 ...

  8. Arduino使用HC05蓝牙模块与手机连接

    Arduino使用HC05蓝牙模块与手机连接 一切都是最好的选择 首先是线路连接,一定不要接错了 Arduino 代码 #include <SoftwareSerial.h> // Pin ...

  9. Arduino蓝牙模块实现通信

    蓝牙参数特点 1.蓝牙核心模块使用HC-06从模块,引出接口包括VCC,GND,TXD,RXD,预留LED状态输出脚,单片机可通过该脚状态判断蓝牙是否已经连接 2.led指示蓝牙连接状态,闪烁表示没有 ...

随机推荐

  1. springframework开源代码导入eclipse

    从毕业到现在已经3个多点年头了,开源框架也用过不少.对于j2ee开发来说,spring框架是是最流行的轻量级可选的框架之一,如果还停留在只会使用,而对源代码不研究是不行的. 话不多说 先从导入代码开始 ...

  2. Code for the Homework2

    第二次作业,最近有点忙,一直没写,先发一下,关节角计算有点问题,后面抽时间改 #include<iostream> #include <Eigen/Dense> #includ ...

  3. linux 配置java环境变量

    修改/etc/profile文件 如果你的计算机仅仅作为开发使用时推荐使用这种方法,因为所有用户的shell都有权使用这些环境变量,可能会给系统带来安全性问题. ·用文本编辑器打开/etc/profi ...

  4. uvalive 4973 Ardenia

    题意:给出空间两条线段,求距离. 注意输出格式! #include<cstdio> #include<cmath> #include<algorithm> usin ...

  5. ZAB协议(转)

    转自:http://www.cnblogs.com/sunddenly/articles/4073157.html Zab协议   一.ZooKeeper概述 ZooKeeper内部有一个in-mem ...

  6. C++中类的大小计算方法总结《网络+总结》

    C++中类的成员函数,静态成员是不占类的大小的.类的大小等于基类的大小+子类个non-static成员变量的大小再+非虚基类大小,如果有多态性还要考虑vptr(可能不止一个)大小,这里成员变量是会被字 ...

  7. BPF漫谈

    源起 最近看到国内两篇文章[1][2]先后翻译了就职于Netflix的性能分析大牛Brendan Gregg于2017年7月31日写的<Golang bcc/BPF Function Traci ...

  8. SignUtil

    最近接的新项目 加密比较多  我就记录下. SignUtil是jnewsdk-mer-1.0.0.jar  com.jnewsdk.util中的一个工具类.由于我没有百度到对应的信息.所以我只能看源码 ...

  9. 值得推荐的五大敏捷PHP开发框架

    各位开发者,对于在HTML中混乱使用PHP的人来说,我们给大家推荐几款PHP敏捷开发的框架,以及它们为什么能够流行. 在我们开始之前,先了解敏捷开发是个什么东东. 敏捷是一种软件开发方法,每次开发计划 ...

  10. python-Levenshtein几个计算字串相似度的函数解析

    linux环境下,没有首先安装python_Levenshtein,用法如下: 重点介绍几个该包中的几个计算字串相似度的几个函数实现. 1. Levenshtein.hamming(str1, str ...