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. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,199
    Likes:
    159
    Location:
    morristown,tn
    ONLINE
    The hardware uart on the arduino it to talk to and from your computer and the arduino.
    Next if you use those pins the serial monitor sees what sent out of the arduino so you don't see what your thinking you are seeing.

    The HC-05 comes out of the box set to 38400 baud That can be changed I have mine at 9600

    The Serial.println() send's a line return The Serial.write() doe not send nothing but raw text

    Using software serial let use 2 Uarts the arduino only has one hardware uart and that's for programming as well as serial.

    You hook TX to RX Not TX to TX RX to RX IT"S TX to RX

    Next if the code I posted did not work with 9600 or 38400 you have something hooked up wrong

    I would Like I said hook it up like post #77 now and load the code in post #74 if that code does not work after checking you wiring 5 maybe 10 times
    change 38400 to 9600

    Plus make sure you set the serial monitor to 57600 here shows the monitor Screenshot from 2018-01-21 18-14-28.png
     
  2. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,199
    Likes:
    159
    Location:
    morristown,tn
    ONLINE
    I added output to show what you are getting from the HC-05 and is displayed on serial monitor.
    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
      Serial.begin(57600);
    }
    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
        Serial.write(state);
     }
     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;
     }
    }
    And a video to showing it happen
     
  3. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    can u tell me what arduino version is that
     
  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
    everything works exactly like it shoud thank you a lot. my priblem was that i was puting Serial.println, but when i put Serial.write everything is great.
    what i dont know how to see data one under one.becuse now everithing is in one row.
     
  6. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,199
    Likes:
    159
    Location:
    morristown,tn
    ONLINE
    Like this is easy way
    Code (text):

    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
        Serial.write(state);
        Serial.println("");      // prints another carriage return
     }
    Serial.println(""); // prints another carriage return
     
  7. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    but then it prints like this:
    I

    w
    a
    s

    a
    t
     
  8. dave miyares

    Dave New Member

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

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    and can u tell me how to count clicks per second whit arduino
     
  10. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,199
    Likes:
    159
    Location:
    morristown,tn
    ONLINE
    This works if it's not overly fast.
    The example calculated the time duration of a pulse on pin 7.
    Parameters
    pin: the number of the pin on which you want to read the pulse. (int)

    value: type of pulse to read: either HIGH or LOW. (int)

    timeout (optional): the number of microseconds to wait for the pulse to start; default is one second (unsigned long)

    Returns
    the length of the pulse (in microseconds) or 0 if no pulse started before the timeout (unsigned long)

    As for post 86 if you want the words to show on one line you format the test from the serial.
    the code i posted was the number would show line by line.

    Code (text):



    int pin = 7;
    unsigned long duration;

    void setup()
    {
      pinMode(pin, INPUT);
    }

    void loop()
    {
      duration = pulseIn(pin, HIGH);
    }
     
  11. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,199
    Likes:
    159
    Location:
    morristown,tn
    ONLINE
  12. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    i dont need this type of program. i want to mesure clicks in like a 1sec .
     
  13. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,723
    Likes:
    422
    Location:
    Brisbane Australia
    You could try learning to program.

    Mike.
     
    • Agree Agree x 1
  14. toni.zul

    toni.zul Member

    Joined:
    Jan 20, 2018
    Messages:
    47
    Likes:
    0
    i know how to program, but i dont know all commands.i know about 70% of all commands
     
  15. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,593
    Likes:
    202
    Location:
    Lancashire UK
    ONLINE
    It seems odd that the 70% of commands that you know do not include any of the ones used for these small test programms. Out of interest are you sure that counting pulses per second is going to give you accurate speed readings ? How many pulses per revolution of your wheels do you get and what is the circumference of your wheels ?

    Les.
     
  16. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,199
    Likes:
    159
    Location:
    morristown,tn
    ONLINE
    Guess you don't understand
    this count pulses lot faster then one a second It's use for as you say " measure clicks."
    Code (text):

    int pin = 7;
    unsigned long duration;

    void setup()
    {
      pinMode(pin, INPUT);
    }

    void loop()
    {
      duration = pulseIn(pin, HIGH);
    }
     
    This shows it counting button bounce.
    Screenshot from 2018-01-24 23-59-00.png
     
    Last edited: Jan 24, 2018

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