Recently had issues with HC-06 AND Arduino UNO. Turned out that the last module was not working, this module keeps flashing and it appeared in the Bluetooth list. I'm trying to work with some AT commands but for some reason this doesn't work. This module is brand new (ZS-040). enter image description here
#include <SoftwareSerial.h>
SoftwareSerial btSerial(2, 3); // RX, TX
/*
* Connect pin 2 Arduino to pin TX HC-06
* Connect pin 3 Arduino to pin RX HC-06
*/
void setup() {
Serial.begin(9600);
Serial.println("Enter AT commands:");
btSerial.begin(9600);
}
void loop()
{
if (btSerial.available())
Serial.write(btSerial.read());
if (Serial.available())
btSerial.write(Serial.read());
}
I uploaded the code, went into Serial Monitor. When I type a command, I get no reply. I opened "Arduino Bluetooth" app,connected to my phone and when I type something in the terminal on my phone I see the text on my PC's Serial Monitor screen. Any ideas what I should do next? Could it be something to do with the RX pin? Should I use voltage divider? I have 1k and 2k Ohm resistors, how should I connect them if that's the solution?
-
you did not say what happens if you type in the serial monitor after sending data from the phone to the serial monitorjsotola– jsotola2020年01月09日 22:42:04 +00:00Commented Jan 9, 2020 at 22:42
-
i.imgur.com/cGkbeFz.gifv I can send data from the phone but not in the PC. I also got this reply from another platform but still not sure what I should do next. I need instructions, I'm new to all of this. Thanks.Janar– Janar2020年01月10日 14:49:16 +00:00Commented Jan 10, 2020 at 14:49
-
the other reply: i.imgur.com/KLACLDD.pngJanar– Janar2020年01月10日 14:49:29 +00:00Commented Jan 10, 2020 at 14:49
-
Tried changing bt modules baud rate, that didn't workJanar– Janar2020年01月10日 14:51:41 +00:00Commented Jan 10, 2020 at 14:51
-
SOLVED: Read this guide (chenthedesignmaker.com/…), tried changing "No line ending" to "Both NL & CR". Now when I type AT command I get the reply OK and when I type on my phone I see the text in serial monitor (PC).Janar– Janar2020年01月10日 15:04:52 +00:00Commented Jan 10, 2020 at 15:04
1 Answer 1
Use a macro like this to send AT commands:
#include <SoftwareSerial.h> SoftwareSerial btSerial(2, 3); // RX, TX /* * Connect pin 2 Arduino to pin TX HC-06 * Connect pin 3 Arduino to pin RX HC-06 */ void setup() { Serial.begin(9600); Serial.println("Enter AT commands:"); btSerial.begin(9600); } void loop() { if (btSerial.available()) Serial.write(btSerial.read()); if (Serial.available()) btSerial.write(Serial.read()); delay(1000); //btSerial.print("AT+PIN4321"); //btSerial.print("AT+NAMEAlibaba"); //btSerial.print("AT+BAUD4"); }
You may have another port set on the HC 06 instead of 9600, like I had. If so, try this code with all the possible port numbers and changing something like the password, and everytime you run the code - go check if it worked, this way you will find in wich port number you have your module.
good luck