I recently ordered an HC-06 Bluetooth module for my Arduino Uno, and after watching this video, and many others, I still have been having many issues figuring out how to get it to work, and some questions for how the code receives and reads serial data from my phone.
I assume this wiring is correct, right?
- Rx> Tx
- Tx> Rx
- Gnd> Gnd
- Vcc> 3.3V
When I sent a command over the Bluetooth terminal app I have, the serial monitor displays that command over and over, I assume that is correct also?
How do I read the serial input? I've been using
if(Serial.available() > 0) phoneInput = (char) Serial.read();
and then displaying the value of phoneInput to the serial monitor, but for some reason I can't seem to have it control anything properly (in this case an LED)
What datatype is the Serial.read() returning to my variable before I cast char on to it?
I get errors uploading the code to the board (avrdude: stk500_recv(): programmer is not responding), until I remove the pin connected to the Rx on the arduino, is there a cleaner solution to uploading the board without unplugging wires?
-
I had follow this tutorial and problem fixed: Tutorial Configure HC-06 Bluetooth Module using AT CommandNguyen Van Quoc– Nguyen Van Quoc2018年05月30日 13:47:13 +00:00Commented May 30, 2018 at 13:47
1 Answer 1
I assume this wiring is correct, right?
Rx > Tx Tx > Rx Gnd > Gnd Vcc > 3.3V
Almost. The Arduino's TX should be reduced to 3.3V using a 10k/20k potential divider.
How do I read the serial input? I've been using
if(Serial.available() > 0) phoneInput = (char) Serial.read();
You should read and digest this.
What datatype is the Serial.read() returning to my variable before I cast char on to it?
An integer. It holds either 0-255 representing the ASCII code for a character, or -1 if there is nothing in the buffer to read.
I get errors uploading the code to the board (avrdude: stk500_recv(): programmer is not responding), until I remove the pin connected to the Rx on the arduino, is there a cleaner solution to uploading the board without unplugging wires?
That will be because you are using pins 0/1 to communicate with the bluetooth which you can't do because those are used to communicate with the PC.
-
I'm away from my computer so I can't test your answers, but thanks so much, your answers were super helpful, but I do have one question; If I shouldn't use pins 0 and 1 as Rx and Tx, what pins should I use?Zelkins– Zelkins2017年02月18日 14:42:16 +00:00Commented Feb 18, 2017 at 14:42
-
1Anything else - I assume you're using
SoftwareSerial
- that library is designed to use any pin except 0/1. You useSerial
for pins 0/1. There seems to be a number of tutorials (videos?) around that show SoftwareSerial being incorrectly used with pins 0/1.Majenko– Majenko2017年02月18日 14:44:23 +00:00Commented Feb 18, 2017 at 14:44