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());
}
b707
May 30, 2024, 9:43pm
2
Your code has a lot of problems:
Why did you initialize a SoftwareSerial object, and do not use it in the code?
Why did you need a SoftwareSerial at all, if the Mega has a three hardware serials?
What is the comand "ATcommand" ?
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.
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"
system
Closed
November 28, 2024, 5:58am
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.