【发布时间】:2019-04-18 09:21:50
【问题描述】:
我想用 5 伏 Arduino pro mini 驱动一个执行器,它是由手机的蓝牙信号控制的。
电路细节:
1)Arduino Promini 5 伏 2) Hc05蓝牙模块 3)5伏执行器 我直接给 Arduino pro mini 的 RAW 引脚供电 11.8 伏。
当它接收到 1 或 0 时,它无法控制执行器,并且在将执行器的数据引脚与 arduino pro-mini 的引脚 13 连接后,闪光灯持续闪烁
但以上相同的操作完全由 Arduino Uno Board 完成。那么有没有可能通过蓝牙信号使用arduino promini控制执行器。我使用 Arduino pro mini 而不是 Arduino Uno 的原因是它占用的空间更少。
Arduino 代码:
#include<SoftwareSerial.h>
SoftwareSerial BT(2, 3);
#include <Servo.h>
Servo myservo;
int ServoPin =13;
void setup()
{
Serial.begin(9600);
myservo.attach(ServoPin);
pinMode(ServoPin, OUTPUT);
digitalWrite(ServoPin, LOW);
myservo.write(40);
// set digital pin to control as an output
pinMode(9, OUTPUT);
// set the data rate for the SoftwareSerial port
BT.begin(9600);
// Send test message to other device
BT.println("Hello from Arduino");
}
char a; // stores incoming character from other device
void loop()
{
if (BT.available())// if text arrived in from BT serial...
{
a=(BT.read());
Serial.println(a);
if (a=='1')
{
digitalWrite(9, HIGH);
BT.println(" You have to turn oN the LED/servo| I got the command : 1 ") ;
Serial.println("I got the command :");
Serial .println(a);
myservo.write(180);
a=' ';
}
else if (a=='0')
{
myservo.write(40);
digitalWrite(9, LOW);
BT.println(" You have to turn Off the LED!/servo| I got the command :0");
Serial.println("I got the command :");
Serial .println(a);
a=' ';
}
}
}
【问题讨论】:
标签: arduino arduino-ide