Im using a Mega following this tutorial:
and Ive set it up as they described, here is the picture:
but all I get is a red blinking light from the hc05. Im using their code except that I modified the LED pin from 7 to 13 so Im just looking at the Mega's onboard LED. But the issue remains that blinking red led. Im using a 1.2kΩ and a 2.2Ω resistor for the divider and I checked and it is indeed 3.20V at the divider:
#define ledPin 13
int state = 0;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
if (state == '0') {
digitalWrite(ledPin, LOW); // Turn LED OFF
Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
state = 0;
} else if (state == '1') {
digitalWrite(ledPin, HIGH);
Serial.println("LED: ON");;
state = 0;
}
}
...
I found a post on this forum:
https://forum.arduino.cc/index.php?topic=338984.0
that sent me here:
http://www.martyncurrey.com/arduino-with-hc-05-bluetooth-module-at-mode/
My red LED is blinking about 1x per second
where is says to hold the button switch while powering the module and let go as soon as the LED comes on, but the LED never comes on if I power it up with the button held.
While it is not the cause of your perceived problem, you will be amazed how helpful it can be to know what you have in your hand. The bluetooth module you show is not an HC-05, I'm betting it is an HM-10.
Marciokoko:
but all I get is a red blinking light from the hc05.
What you get is exactly what you should expect. Irrespective of the type of module, the flashing LED means "power on, ready to connect". That is all.
The code looks like junk. You will be better off getting advice from somebody who actually knows what he is doing.
http://www.martyncurrey.com/hm-10-bluetooth-4ble-modules/
OOOHHH!!!! I pulled the module from the wrong bag! Thanks for catching that! Ill finish the project with the ble module. Thanks...especially for the "somebody who actually knows what he is doing" bit 
Ok im still not getting a response from the hm10 vía the serial monitor. Ive been able to Connect to the hm10 module from the BLE scanner apps on my iPhone and Androis but vía the mega on pins 18/19 (using the 1/2k divider) I don't get any response to AT commands.
This is the code im using:
//#define ledPin 13
//char c = ' ';
//void setup() {
// pinMode(ledPin, OUTPUT);
// digitalWrite(ledPin, LOW);
// Serial.begin(115200); // Default communication rate of the Bluetooth module
//}
//
//void loop() {
// if(Serial.available()){ // Checks whether data is comming from the serial port
// c = Serial.read();
// Serial.write(c);
// }
//
//}
///////////////////////////////////////////////////////////////////////////////
//void setup() {
// Serial.begin(9600);
// // If the baudrate of the HM-10 module has been updated,
// // you may need to change 9600 by another value
// // Once you have found the correct baudrate,
// // you can update it using AT+BAUDx command
// // e.g. AT+BAUD0 for 9600 bauds
// Serial1.begin(9600);
//}
//
//void loop() {
// char c;
// if (Serial.available()) {
// c = Serial.read();
// Serial1.println(c);
// }
// if (Serial1.available()) {
// c = Serial1.read();
// Serial.println(c);
// }
//}
///////////////////////////////////////////////////////////////////////////////
char c=' ';
boolean NL = true;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
Serial.println("BTserial started at 9600");
}
void loop(){
// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (Serial1.available()){
c = Serial1.read();
Serial.write(c);
}
// Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available()){
c = Serial.read();
// do not send line end characters to the HM-10
if (c!=10 & c!=13 ) {
Serial1.write(c);
}
// Echo the user input to the main window.
// If there is a new line print the ">" character.
if (NL) { Serial.print("\r\n>"); NL = false; }
Serial.write(c);
if (c==10) { NL = true; }
}
}
In case anyone else runs into this, the correct answer is that AT commands have to be sent from within code like so:
char c=' ';
boolean NL = true;
int ledpin=13; // led on D13 will show blink on / off
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
Serial.println("BTserial started at 9600");
pinMode(ledpin, OUTPUT);
Serial1.write("AT\r\n");
Serial1.write("AT+NAME\r\n");
}
void loop(){
// Read BT Write Serial Monitor
if (Serial1.available()){
c = Serial1.read();
Serial.write(c);
if(c=='1'){ // if number 1 pressed ....
digitalWrite(ledpin,HIGH);
Serial.println("Got 1 so LED On D13 ON!");
}
}
// Serial Monitor Write BT
if (Serial.available()){
c = Serial.read();
// do not send line end characters to the HM-10
if (c!=10 & c!=13 ) {
Serial1.write(c);
}
// Echo the user input to the main window.
// If there is a new line print the ">" character.
if (NL) { Serial.print("\r\n>"); NL = false; }
Serial.write(c);
if (c==10) { NL = true; }
}
}