Receiving data from Bluetooth module HC-05

Hello! I am creating a project for Arduino Uno with connected sensors:

  • Temperature Sensor - Waterproof (DS18B20)

  • Gravity: Analog pH Sensor/Meter Kit V2

The aim of the project is to collect data from the environment (pH value and Temperature). The project was also enriched with the Bluetooth HC-05 module.

I would like to collect data by the sensors, and next send to the "Serial Bluetooth Terminal" app and display automatically (devices pair easily; Smartphone + HC-05). How should I modify my code to make it works.

Additionally, I can say, that the data is displayed correctly in the "Serial Monitor" of the Arduino IDE on my computer.

I would be very grateful for all the tips.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SoftwareSerial.h>            //Bluetooth
SoftwareSerial BluetoothSerial(0, 1);           // RX | TX
#define BT_SERIAL_TX 1
#define BT_SERIAL_RX 0

#define SensorPin 1                    //pH meter Analog output to Arduino Analog Input 1

#define ONE_WIRE_BUS 2                 // Data wire is plugged into digital pin 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS);         // Setup a oneWire instance to communicate with any OneWire device
DallasTemperature sensors(&oneWire);   // Pass oneWire reference to DallasTemperature library

unsigned long int avgValue;            //Store the average value of the sensor feedback
float b;
int buf[10],temp;

void setup()
{
  BluetoothSerial.begin(9600);         //BT baud rate
  delay(1000);
  
  //Temperature Sensor
  sensors.begin();                      // Start up the library
  Serial.begin(9600);
  
  //pH Sensor
  pinMode(13,OUTPUT);  
  Serial.begin(9600);  

}
void loop()
{
  {// Send the command to get temperatures
  sensors.requestTemperatures(); 

  //print the temperature in Celsius
  Serial.print("T: ");
  Serial.print(sensors.getTempCByIndex(0));
  Serial.println(" C ");

  //print Temp. in BT
  BluetoothSerial.print("T: ");
  BluetoothSerial.print(sensors.getTempCByIndex(0));
  BluetoothSerial.println(" C ");
  
  }
  //pH loop
  
  for(int i=0;i<10;i++)                //Get 10 sample value from the sensor for smooth the value
  { 
    buf[i]=analogRead(SensorPin);
    delay(10);
  }
  for(int i=0;i<9;i++)                //sort the analog from small to large
  {
    for(int j=i+1;j<10;j++)
    {
      if(buf[i]>buf[j])
      {
        temp=buf[i];
        buf[i]=buf[j];
        buf[j]=temp;
      }
    }
  }
  avgValue=0;
  for(int i=2;i<8;i++)                      //take the average value of 6 center sample
    avgValue+=buf[i];
  float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
  phValue=3.5*phValue;                      //convert the millivolt into pH value 
  Serial.print("pH:");  
  Serial.print(phValue,2);
  Serial.println(" ");
  digitalWrite(13, HIGH);       
  delay(500);
  digitalWrite(13, LOW); 
  //delay(500); //od temp.

  BluetoothSerial.print("pH:");
  BluetoothSerial.print(phValue,2);
  BluetoothSerial.println(" ");
}

don't use pin 0 and 1, they are for the the Serial port and thus the terminal
use other pins

and use the defines you have....

#define BT_SERIAL_TX 1
#define BT_SERIAL_RX 0

If that is the case, that is all the code you need. Get rid of all that software serial stuff, particularly since it is all wrong, connect Bluetooth to pins 0,1, and you're done.

Just make sure you have Bluetooth disconnected when you upload your programme.

Reply #2 is also misleading nonsense. There is no need to define any serial pins, Arduino already knows what pins 0,1 are for, it is clearly written on the PCB.

For this purpose, and since you are using HC-05, you might find Cetin's "Bluetooth Graphics Terminal" more useful.

it's not nonsense.

I'd accept language barrier or the possibility I did not express myself very clearly

what I meant is that if OP wants to use Software Serial so that s/he keeps the Serial line for upload and debugging, then instead of doing

#include <SoftwareSerial.h>            //Bluetooth
SoftwareSerial BluetoothSerial(0, 1);           // RX | TX
#define BT_SERIAL_TX 1
#define BT_SERIAL_RX 0

if would be better to have the #define before the instantiation and use them

#include <SoftwareSerial.h>            //Bluetooth
#define BT_SERIAL_TX 2
#define BT_SERIAL_RX 3
SoftwareSerial BluetoothSerial(BT_SERIAL_RX, BT_SERIAL_TX);           // RX | TX

ie use the label instead of a magic number.

hope it makes more sense now. :slight_smile:

You are dead right about that - to the point where it is totally misleading.

next time I'll write it in French :slight_smile: