无法从Arduino接收数据到MIT发明家应用程序

huangapple go评论58阅读模式
英文:

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");
    }
               
  }                            
}

enter image description here

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 &lt;SoftwareSerial.h&gt;
    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() &gt; 0) {
            while (btm.available() &gt; 0) {
              c = btm.read();
              Serial.print(c);
        }
      }
    }

//----------------------------------------------------------------  

huangapple
  • 本文由 发表于 2023年3月7日 10:36:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657574.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定