Go Down

Topic: HC-05 bluetooth module , Pairing. BUT not working properly. (Read 672 times) previous topic - next topic

lucas-ignaz

              Hi guys!, i need help with my bluetooth module; it's an "HC-05 (zs-040) " i used it on a few projects before, it worked perfectly, but as i tried to use it with another project, it started pairing with my phone, like usual, but it's not displaying anything on the "blue term" app, nor respond to other apps i used it with, before.

          in short the problem is: it's paired, but it doesn't execute anything else written on the sketch.

      i spent a lot of time checking my wiring, but still, nothing, im still trying to work on it now, any suggestions?


  Any help would be appreciated. Thanks in advance.

Nick_Pyner

Pairing means just that.
If you can pair, which has nothing to do with Arduino, about all that can go wrong is
1. Your code, apparently secret.
2. Your wiring, apparently kosher.
3. You haven't made the connection in BlueTerm.

purplepanda

I am able to pair my bluetooth with my computer, but when I check the ports, there is no information being recieved.

Since i am using the USB to power for right now when I use the USB port I am able to read the sensor data, so I would have thought that the bluetooth would allow me to read the same data from the ports connected to the bluetooth.

I was wondering what the problem could be?

Instead of using a voltage divider, I connected directly to 3.3V on arduino.

This is my arduino code

#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>

SoftwareSerial BTserial(0, 1); // RX | TX
 
char c = ' ';
#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);
 
void setup()
{
    Serial.begin(9600);
    sensors.begin();
    Serial.println("Communication Established");
    //Serial.println("Remember to select Both NL & CR in the serial monitor");
 
    // HC-05 default serial speed for Command mode is 9600
    BTserial.begin(9600); 
}

 
void loop()
{
  // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  sensors.requestTemperatures();
 
  Serial.print("Celsius temperature: ");
  Serial.print(sensors.getTempCByIndex(0));
  Serial.print(" - Fahrenheit temperature: ");
  Serial.println(sensors.getTempFByIndex(0));
 
  delay(1000);
 
    // Keep reading from HC-05 and send to Arduino Serial Monitor
    if (BTserial.available())
    { 
        c = BTserial.read();
        Serial.write(c);
    }
 
}



Because the problem seemed to be with the bluetooth, I tried to test just the bluetooth with the example from how to mechanics.

using the below as my arduino code
#define ledPin 7
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;
 }
}


and using the below as code for processing ide
import processing.serial.*;
Serial myPort;
String ledStatus="LED: OFF";

void setup(){
  size(450, 500);
  myPort = new Serial(this, "COM4", 38400); // Starts the serial communication
  myPort.bufferUntil('\n'); // Defines up to which character the data from the serial port will be read. The character '\n' or 'New Line'
}
void serialEvent (Serial myPort){ // Checks for available data in the Serial Port
  ledStatus = myPort.readStringUntil('\n');
}

void draw(){
  background(237, 240, 241);
  fill(20, 160, 133); // Green Color
  stroke(33);
  strokeWeight(1);
  rect(50, 100, 150, 50, 10);  // Turn ON Button
  rect(250, 100, 150, 50, 10); // Turn OFF Button
  fill(255);
 
  textSize(32);
  text("Turn ON",60, 135);
  text("Turn OFF", 255, 135);
  textSize(24);
  fill(33);
  text("Status:", 180, 200);
  textSize(30);
  textSize(16);
    text(ledStatus, 155, 240); // Prints the string comming from the Arduino
 
  // If the button "Turn ON" is pressed
  if(mousePressed && mouseX>50 && mouseX<200 && mouseY>100 && mouseY<150){
    myPort.write('1'); // Sends the character '1' and that will turn on the LED
    // Highlighs the buttons in red color when pressed
    stroke(255,0,0);
    strokeWeight(2);
    noFill();
    rect(50, 100, 150, 50, 10);
  }
  // If the button "Turn OFF" is pressed
  if(mousePressed && mouseX>250 && mouseX<400 && mouseY>100 && mouseY<150){
    myPort.write('0'); // Sends the character '0' and that will turn on the LED
    stroke(255,0,0);
    strokeWeight(2);
    noFill();
    rect(250, 100, 150, 50, 10);
  }
}


This is not working either. There is no change when I manually turn LED on and off. It shows as off no matter what. Which means that it is not reading because the default is off.


I am desperately hoping you can help me find a solution.

Go Up