1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

dont know how to use bluetooth module hc-05

Discussion in 'Arduino' started by toni.zul, Jan 20, 2018.

  1. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    and i need whay how to decode it
     
  2. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    i tred this code and it doidnt worked.
    i use this code
    void setup() {
    Serial.begin(38400); // im not sure for this
    }
    void loop() {
    if(Serial.available() > 0){
    Serial.println(Serial.read());
    }
    }
    and it prints ascii code.
    int led=13;
    int state;
    void setup() {
    pinMode(led,OUTPUT);
    Serial.begin(38400); // im not sure for this
    }
    void loop() {
    if(Serial.available() > 0){
    state=Serial.read();
    }
    if (state == 48){
    digitalWrite(led,LOW);
    }
    if (state == 49){
    digitalWrite(led,HIGH);
    }
    Serial.println(state);
    }
    i used this code and everything is ok.
    but when i want to do something more comlex i cant becuse ascii code
     
  3. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    Tty this
    AS is and say what happens
    Code (text):

    #define rxPin 2
    #define txPin 3
    #define ledPin 7
    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(rxPin, txPin);
    int state = 0;
    void setup() {
      pinMode(rxPin, INPUT);
      pinMode(txPin, OUTPUT);
      pinMode(ledPin, OUTPUT);
      digitalWrite(ledPin, LOW);
      mySerial.begin(9600); // Default communication rate of the Bluetooth module
    }
    void loop() {
      if(mySerial.available() > 0){ // Checks whether data is comming from the serial port
        state = mySerial.read(); // Reads the data from the serial port
     }
     if (state == '0') {
      digitalWrite(ledPin, LOW); // Turn LED OFF
      mySerial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
      state = 0;
     }
     else if (state == '1') {
      digitalWrite(ledPin, HIGH);
      mySerial.println("LED: ON");;
      state = 0;
     }
    }
     
    don't change it Use just as is
     
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  5. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    doesent work
     
  6. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    You type a 1 send it the led comes on you type a 0 send that led goes off if your using a bluetooth terminal
    and using the stuff I showed you.

    Now your HC-05 maybe set to use 38400 that depends on how you messed with it.
     
  7. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    That doesn't tell me nothing did you hook it up like i posted in post 26 ???

    That code works only for that way

    If you hooked it up like that and used the code I posted your HC-05 maybe still set for 38400
     
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  9. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    You then change this one line
    mySerial.begin(9600);

    to

    mySerial.begin(38400);
     
  10. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    If one of those don't work you have sent at commands and changed your HC-05 settings and it will need to be resetup
     
  11. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    this code works as i sayd
    int led=13;
    int state;
    void setup() {
    pinMode(led,OUTPUT);
    Serial.begin(38400); // im not sure for this
    }
    void loop() {
    if(Serial.available() > 0){
    state=Serial.read();
    }
    if (state == 48){
    digitalWrite(led,LOW);
    }
    if (state == 49){
    digitalWrite(led,HIGH);
    }
    Serial.println(state);
    }
    becuse 48 ascii code means 0 and 49 means 1
     
  12. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    why you always want to add this to code
    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(rxPin, txPin);
    why just don use built in tx rx
     
  13. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    SoftwareSerial mySerial does what you want

    Using the hardware serial formats for the serial monitor adds a lot o problems like what your asking
    your not using the bluetooth serial right if your not getting it to work sending a 1 or 0
    your setting are wrong but it hard to see that cus you post little or nothing to go with.
     
    Last edited: Jan 21, 2018
  14. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,592
    Likes:
    202
    Location:
    Lancashire UK
    If you change the line Serial.println(Serial.read());
    to Serial.write(Serial.read()); It might do what you want. (I have a very poor understanding of the syntax of "C" programming)

    Les.
     
  15. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    be80be i dont know what u want to get with your program.
     
  16. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    Try this
    Code (text):

    #include <SoftwareSerial.h>
    SoftwareSerial mySerial(2, 3); // RX, TX
    void setup() {
      // Open serial communications and wait for port to open:
      Serial.begin(57600);
        mySerial.begin(38400);
      }
    void loop() { // run over and over
      if (mySerial.available()) {
        Serial.write(mySerial.read());
      }
      if (Serial.available()) {
        mySerial.write(Serial.read());
      }
    }
     
    It let's you talk from PC to phone both ways
    and should work try it out
     
  17. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    Serial.write(Serial.read()); is the right way but with this your just talking from the pc to atmega .
    My code lets you talk PC to atmega to bluetooth to phone which is what you need to under stand first.
    How to do
     
  18. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    can i do it whit 1.0.5 arduino version and shud i connect tx-tx and rx-rx or rx-tx tx-rx
     
  19. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    [​IMG]

    I clearly show how
     
  20. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    nothing led is not turning on is serial monitor i dont read anything. i will try whit new version.
     
  21. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    i instoled new version and nothing is happening even my old progrms dont work
     
  22. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,592
    Likes:
    202
    Location:
    Lancashire UK
    Just changing things at random (The IDE version) is just confusing things. You don't seem to be making any attempt to undestand the things you are being told. The fact that you are still asking the TX-Rx / TX - TX question shows that you are not reading the replies to your questions. The answer to that question depends on which configuration you are using. Also when you say that something is working or not working you are not telling us the exact configuration. I am getting near the point of giving up on trying to help you.

    Les.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice