Hey,
recently I startet working with the Arduino UNO. So far so good.
After 1 Day of getting the Arduino with the HC05 to receive AT-Commands I have a problem.
Setup:
- Arduino UNO
- HC 05
Wired:
HC05 GND => UNO GND
HC05 VCC => UNO Digital Pin 10
HC05 TXD => UNO Digital Pin 11
HC05 RXD => Breadboard => 1k Resistor => UNO Digital Pin 12
Breadboard => 2k Resistor => UNO GND
Why the VCC On UNO?
Because its easier to get to the AT-Mode. Just press Reset Arduino Button and HC05 Button instead of plugging out/in wires.
Code:
#include <SoftwareSerial.h>
// Define Pins
#define HC_Power 10
#define HC_RX 12
#define HC_TX 11
// Define BT-Serial
SoftwareSerial btSerial(HC_TX, HC_RX); // TX | RX => von HC05 (From Arduino its other way round)
void setup() {
// Start Debugging to Computer via USB-Serial
Serial.begin(9600);
Serial.println("Los geht's");
Serial.println("To get into AT-Mode restart Arduino while Pressing HC05 Button.");
// Start Bluetooth Connection
btSerial.begin(38400);
// Pin Stuff
pinMode(13,OUTPUT);
// Activate Power for HC05
pinMode(HC_Power, OUTPUT);
delay(500);
digitalWrite(HC_Power, HIGH);
Serial.println("Bluetooth Module activated!");
}
int data = 0;
void loop() { // run over and over
// Read Data from HC05
if (btSerial.available()) {
data = btSerial.read();
Serial.println(data);
if(data == '1'){
digitalWrite(13,HIGH);
btSerial.println("LED ON");
}
else if (data == '0'){
digitalWrite(13,LOW);
btSerial.println("LED OFF");
}
}
// Send Data to HC05
if (Serial.available()) {
btSerial.write(Serial.read());
}
}
What works:
I can send AT-Commands to the Uno via USB from Serial Monitor. I can rename the HC05 and stuff like that.
I can connect to the HC05 and send Data via Bluetooth Terminal Android App.
What doesnt work?
Shortly: The Data that I Send.
Sending Data from Serial Monitor to Android is weird. Sending any letter there displays an y with 2 dots above it in the Android App.
Sending Data from the Android App to the uno doesnt activate the LED or give the correct output. Sending an 0 gives me a few lines (0, 128, 120, 0, 128, 120, ), sending a 1 gives me following (120, 128, 120, 0, 128, 120). I think it has something to do with the Sending/Receiving, Bytes and that stuff. But every Tutorial i find looks like: Send a 0, check if data equals Char of 0 and then do stuff. So Why doesnt my Code work?
Thanks for answering
Dear
RPGFabi