antisycop
antisycop

Reputation: 93

HC-05 ⸮ In Serial Does Not Function

I recently got a HC-05 Bluetooth module for my arduino, but I cannot send or receive data from it. I used a code to turn on or off a led, but after I send a character from the Serial Monitor of my PC, I get ⸮. Also the module does not respond to any AT command. HC-05 ConnectionArduino connection I ran the Serial both in 9600 and 38400 baud but nothing changed. Also I have tried both no line ending and both NL and CR. But is wrong with this module? Here is my code:

/*
Arduino Turn LED On/Off using Serial Commands
Created April 22, 2015
Hammad Tariq, Incubator (Pakistan)

It's a simple sketch which waits for a character on serial
and in case of a desirable character, it turns an LED on/off.

Possible string values:
a (to turn the LED on)
b (tor turn the LED off)
*/

char junk;
String inputString="";

void setup()                    // run once, when the sketch starts
{
 Serial.begin(9600);            // set the baud rate to 9600, same     should be of your Serial Monitor
 pinMode(13, OUTPUT);
}

void loop()
{
  if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); //read the input
      inputString += inChar;        //make a string of the characters     coming on serial
    }
    Serial.println(inputString);
    while (Serial.available() > 0)  
    { junk = Serial.read() ; }      // clear the serial buffer
    if(inputString == "a"){         //in case of 'a' turn the LED on
      digitalWrite(13, HIGH);  
    }else if(inputString == "b"){   //incase of 'b' turn the LED off
      digitalWrite(13, LOW);
    }
    inputString = "";
  }
}

Upvotes: 0

Views: 2558

Answers (2)

anime
anime

Reputation: 118

I will go step by step- The connection Arduino Pins Bluetooth Pins

RX (Pin 0) ———-> TX

TX (Pin 1) ———-> RX

5V ———-> VCC

GND ———-> GND

Connect a LED negative to GND of arduino and positive to pin 13 with a resistance valued between 220Ω – 1KΩ. And your done with the circuit. Note : Don’t Connect RX to RX and TX to TX of Bluetooth to arduinoyou will receive no data , Here TX means Transmit and RX means Receive.

/*
* This program lets you to control a LED on pin 13 of arduino using a bluetooth module
*/
char data = 0;            //Variable for storing received data
void setup()
{
    Serial.begin(9600);   //Sets the baud for serial data transmission                               
    pinMode(13, OUTPUT);  //Sets digital pin 13 as output pin
}
void loop()
{
   if(Serial.available() > 0) // Send data only when you receive data:
   {
      data = Serial.read();   //Read the incoming data & store into data

      Serial.print(data);     //Print Value inside data in Serial monitor

      Serial.print("\n");        

      if(data == '1') // Checks whether value of data is equal to 1

         digitalWrite(13, HIGH);   //If value is 1 then LED turns ON

      else if(data == '0')  //  Checks whether value of data is equal to 0

         digitalWrite(13, LOW);    //If value is 0 then LED turns OFF
   }
}

Link to Connection : https://halckemy.s3.amazonaws.com/uploads/image_file/file/153200/hc-05-LED%20blink%20Circuit.png

NOTE : While uploading the code , remove the TX and RX wires of Bluetooth Module from Arduino, once upload is completed, connect them.

Upvotes: 2

MVSRI
MVSRI

Reputation: 142

    #include <SoftwareSerial.h>

SoftwareSerial hc(2, 3); // RX | TX

void setup()
{
  pinMode(4, OUTPUT);  
  digitalWrite(4, HIGH);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  hc.begin(38400);  // HC-05 default speed in AT command more
}

void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (hc.available())
    Serial.write(hc.read());

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    hc.write(Serial.read());
}

Use this code to test the bluetooth module in command mode.there are two modes in hc-05. one is command mode and other is data mode. Press the button which is on bluetooth module for few sec. then the led Toggles slowly at this point the module is in command mode and in this you can test the AT commands. Note: Open the serial monitor in 9600 baud rate

Upvotes: 1

Related Questions