Arduino mega bluetooth

hello I am facing this problem with arduino mega while using it with the bluetooth module.is there any solution? the output is question marks

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(18, 19);   //bluetooth module Tx:Digital 2 Rx:Digital 3
char c;
void setup() {
  Serial.begin(9600);
  Serial1.begin(38400);
  Serial.println("ATcommand");  //ATcommand Start
}

void loop() {
  if (Serial1.available()){
      c = Serial1.read();
      Serial.println(c);
      delay(100);
  }
    
  if (Serial.available())
    Serial1.write(Serial.read());
}

Your code has a lot of problems:

  1. Why did you initialize a SoftwareSerial object, and do not use it in the code?

  2. Why did you need a SoftwareSerial at all, if the Mega has a three hardware serials?

  3. What is the comand "ATcommand" ?

  1. Why do you echange the data between Serial and Serial1 in two different ways ?

Thanks for replying to my post.
Can you give me the right code for arduino mega with Bluetooth module Hc-06 with documentation so I can understand how it works.

This is a really demanding question.
You should show some own effort
https://www.google.com/search?q=arduino+mega+2560+bluetooth+HC06+tutorial

yes, you are right. I have done it on the Arduino uno R3 and it worked correctly. I have reworked it on the mega board and finally I have received signals from the Bluetooth module, but the signals are question marks and null operator.

char Incoming_value=0;
int LED = 13;
void setup() {
Serial.begin(9600);
Serial.print("SETUP!");
Serial3.begin(38400);
pinMode(LED,OUTPUT);

}

void loop() {
  if(Serial3.available()>0)
  {Incoming_value=Serial3.read();
  Serial.print(Incoming_value);
  Serial.print("\n");

  if(Incoming_value=='1')
    digitalWrite(LED,HIGH);
   else if(Incoming_value=='0')
   digitalWrite(LED,LOW); 
    
    }
}

Man it is the same with your new posting. Too small own effort.
too less information.
Help us help you by giving detailed information.

If you look back at what happened:
You tried to be quick by posting quick.

All that happened was more than a day passed by but still no solution.

Sounds like wrong baudrate.

Without more details everything is just guessing

  • checked to use exact that IO-pins that are serial3 on an arduino mega 2560?

  • does the bluetooth-module use 3.3V or 5V?

  • are you using an original arduino mega or a clone?

  • does the bluetooth-module use 38400 baud as default?

So answer the questions and post the code that "worked correctly on the arduino"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.