英文:
Can't Receive data from Arduino to MIT inventor app
问题
我正在为学校的物联网项目工作,但我在使用蓝牙模块将数据从Arduino发送到我的MIT应用程序时遇到问题。任何帮助将不胜感激。
char Incoming_value = 0;
void setup()
{
Serial.begin(9600);
pinMode(12, OUTPUT);
}
void loop()
{
if(Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print(Incoming_value);
Serial.print("\n");
if(Incoming_value == '1'){
digitalWrite(12, HIGH);
delay(10000);
Serial.println("5");
}
}
}
修复接收Arduino使用蓝牙模块发送的数据的问题。
英文:
I'm working on an IOT project for school, but I'm having trouble seeing my data from the Arduino using Bluetooth module to my MIT apps. Any help would be greatly appreciated.
char Incoming_value = 0;
void setup()
{
Serial.begin(9600);
pinMode(12, OUTPUT);
}
void loop()
{
if(Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print(Incoming_value);
Serial.print("\n");
if(Incoming_value == '1'){
digitalWrite(12, HIGH);
delay(10000);
Serial.println("5");
}
}
}
fixing for receiving data from Arduino using Bluetooth module
答案1
得分: 0
if you are connecting a Bluetooth module to the arduino board, use SoftwareSerial.
here is a working example :
#include <SoftwareSerial.h>
SoftwareSerial btm(3, 2); // pin D3 and pin D2 as Rx and Tx
char c;
void setup() {
btm.begin(9600);
Serial.begin(9600);
}
void loop() {
if (btm.available() > 0) {
while (btm.available() > 0) {
c = btm.read();
Serial.print(c);
}
}
}
英文:
if you are connecting a Bluetooth module to the arduino board,use SoftwareSerial.
here is a working example :
//----------------------------------------------------------------
#include <SoftwareSerial.h>
SoftwareSerial btm(3, 2); // pin D3 and pin D2 as Rx and Tx
char c;
void setup() {
btm.begin(9600);
Serial.begin(9600);
}
void loop() {
if (btm.available() > 0) {
while (btm.available() > 0) {
c = btm.read();
Serial.print(c);
}
}
}
//----------------------------------------------------------------
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论