Continue to Site

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.

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

dont know how to use bluetooth module hc-05

Status
Not open for further replies.
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
 
I added output to show what you are getting from the HC-05 and is displayed on serial monitor.
Code:
#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
 
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.
 
Like this is easy way
Code:
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
 
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:
int pin = 7;
unsigned long duration;

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

void loop()
{
  duration = pulseIn(pin, HIGH);
}
 
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.
 
Guess you don't understand
this count pulses lot faster then one a second It's use for as you say " measure clicks."
Code:
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:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top