HC-06 works on its own, but not with sensors

Hi,
I want to connect several sensors with an HC-06 toprint the values via Bluetooth on my phone. The HC-06 worked with this little test sketch and I could see "TEST" on my phone's display:

#include <SoftwareSerial.h>
SoftwareSerial BT(10, 11); //TX 10 RX 11

void setup()  
{
BT.begin(9600);
}

void loop() 
{
BT.println("TEST");
delay(1000);
}

However, when I put this sketch together with my sensors (same wiring), I do not get anything on my phone. Also no error messages, Bluetooth connection works, Serial Monitor with the same print orders works. Can anyone help?

//NJarpa
//Arduino Data Logger with 2 DS18B20 and sample rate control(every 1 min)
//You must have a datalogger shield(RTC and SD card) mounted
// DS18B20 Pinout (Wires)
//Black   = Ground
//Blue    = Signal (Pin 2):  (Normal power mode with 3.3K to 4.7K resistor to +5 or 3.3 )
//Red     = +5 or +3.3 V

#include <Wire.h>                //Libraries we need
#include "RTClib.h"
#include <OneWire.h>           
#include <DallasTemperature.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_Sensor.h> ///BME280
#include <Adafruit_BME280.h> ///BME280
Adafruit_BME280 bme; ///BME280
#include <BH1750.h> ///BH1750
BH1750 lightMeter; ///BH1750
#include <dht.h> ///DHT21A
dht DHT; ///DHT21A
#include <SoftwareSerial.h> ///HC06
SoftwareSerial BT(10, 11); ///TX 10 RX 11, HC06

#define ONE_WIRE_BUS_PIN 2              // The pin that we are using for sensors

#define DHT21A_PIN 3 ///DHT21A
float humA;  //Stores humidity value
float tempA; //Stores temperature value ///DHT21A

#define DHT21B_PIN 5 ///DHT21B
float humB;  //Stores humidity value
float tempB; //Stores temperature value ///DHT21B

byte lastMinute = 0xFF; //Initialize to an impossible value, for sampling every minute






OneWire oneWire(ONE_WIRE_BUS_PIN);     // Setup oneWire
DallasTemperature sensors(&oneWire);   //  oneWire to Dallas Temperature.
RTC_DS1307 RTC;                        // define the Real Time Clock object

const int chipSelect = 4;              //CS pin of your data logger shield.Maybe not yours!!
File Logfile;                          //Name of the file

// Assign the addresses of your  temp sensors.
//Every sensor has it own address.You must use 1 wire adress finder.

DeviceAddress Probe01 = { 0x28, 0x7E, 0xA5, 0x77, 0x91, 0x08, 0x02, 0x13 }; //inox2
DeviceAddress Probe02 = { 0x28, 0xAA, 0x21, 0x9E, 0x13, 0x13, 0x02, 0xE7 }; //Inox1
DeviceAddress Probe03 = { 0x28, 0xAA, 0x5E, 0xA8, 0x13, 0x13, 0x02, 0xA4 };
DeviceAddress Probe04 = { 0x28, 0xAA, 0xA9, 0xA5, 0x13, 0x13, 0x02, 0xCE };
//DeviceAddress Probe05 = { 0x28, 0x7E, 0xA5, 0x77, 0x91, 0x08, 0x02, 0x13 }; //uncomment for further DS18B20 sensor


void setup()
{
  //pinMode(10 , OUTPUT);           //For some data logger shields.Uncomment if you need
  
SD.begin(chipSelect);            //Initialize the libraries
Wire.begin();
RTC.begin();
sensors.begin();
lightMeter.begin(); ///BH1750
bme.begin(0x76); ///BME280
BT.begin(9600); ///HC06
  
  // set the resolution to 9 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 9);
  sensors.setResolution(Probe02, 9);
  sensors.setResolution(Probe03, 9);
  sensors.setResolution(Probe04, 9);
  //sensors.setResolution(Probe05, 9); //uncomment for further DS18B20 sensor
  
Logfile=SD.open("Logfile.csv",FILE_WRITE);               //Open and write once, just for headers
//Logfile.println(" Date/Time         Temp1   Temp2   Temp3    Temp4    Temp5   Hum5");    //Print headers(not saved yet) //////////
Logfile.close();                                        //Print saved

}

//----------Temp Variable------------//
void printTemperature(DeviceAddress deviceAddress)
{
   float tempC = sensors.getTempC(deviceAddress);
 
   Logfile.print(tempC);
   Logfile.print(" C;");
   Logfile.print(" ");
   Serial.print(tempC);
   Serial.print(" C;");
   Serial.print(" ");
   BT.print(tempC);
   BT.print(" C;");
   BT.print(" ");
   
}

void loop()
{
Serial.begin(9600); ///SERIAL MONITOR

 DateTime now = RTC.now();        // Clock call
 now = RTC.now();                 

//if(now.second()==00){          //Sample every minute
if(now.minute() != lastMinute) {
lastMinute = now.minute();
 
 Logfile=SD.open("Logfile.csv",FILE_WRITE);  // Print date and time    

Logfile.println();
Logfile.print(now.year(), DEC);
Logfile.print("/");
Logfile.print(now.month(), DEC);
Logfile.print("/");
Logfile.print(now.day(), DEC);
Logfile.print(" ");
Logfile.print(now.hour(), DEC);
Logfile.print(":");
Logfile.print(now.minute(), DEC);
Logfile.print(":");
Logfile.print(now.second(), DEC);
Logfile.print(";  ");              //Space beween date/time and temp1
Logfile.close();                  //Save date and time
Serial.println();
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
Serial.print(";  ");              //Space beween date/time and temp1


sensors.requestTemperatures(); // Command all devices on bus to read temperature 
Logfile=SD.open("Logfile.csv",FILE_WRITE); 
  
 Logfile.print(" Temp1: ");             //Print temp1
 Serial.print(" Temp1: ");
 BT.print(" Temp1: ");
 printTemperature(Probe01);
 Logfile.print(" Temp2: ");             //Print temp2
 Serial.print(" Temp2: ");
 BT.print(" Temp2: ");
 printTemperature(Probe02);
 Logfile.print(" Temp3: ");             //Print temp3
 Serial.print(" Temp3: ");
 BT.print(" Temp3: ");
 printTemperature(Probe03);
 Logfile.print(" Temp4: ");             //Print temp4
 Serial.print(" Temp4: ");
 BT.print(" Temp4: ");
 printTemperature(Probe04);
 //Logfile.print(" Temp5: ");             //uncomment for further DS18B20 sensor //Print temp5
 //Serial.print(" Temp5: ");
 //printTemperature(Probe05);

  int chkA = DHT.read21(DHT21A_PIN); ///DHT21A
    //Read data and store it to variables hum and temp
    humA = DHT.humidity;
    tempA= DHT.temperature;
    Logfile.print(" Hum6: ");
    Logfile.print(humA);
    Logfile.print(" %; Temp6: ");
    Logfile.print(tempA);
    Logfile.print(" C;");
    Serial.print(" Hum6: ");
    Serial.print(humA);
    Serial.print(" %; Temp6: ");
    Serial.print(tempA);
    Serial.print(" C;"); ///DHT21A

    int chkB = DHT.read21(DHT21B_PIN); ///DHT21B
    //Read data and store it to variables hum and temp
    humB = DHT.humidity;
    tempB= DHT.temperature; 
    Logfile.print(" Hum7: ");
    Logfile.print(humB);
    Logfile.print(" %; Temp7: ");
    Logfile.print(tempB);
    Logfile.print(" C;");
    Serial.print(" Hum7: ");
    Serial.print(humB);
    Serial.print(" %; Temp7: ");
    Serial.print(tempB);
    Serial.print(" C;"); ///DHT21B

    uint16_t lux = lightMeter.readLightLevel(); ///BH1750
  Logfile.print(" Light: ");
  Logfile.print(lux);
  Logfile.print(" lx;");
  Serial.print(" Light: ");
  Serial.print(lux);
  Serial.print(" lx;"); ///BH1750

    Logfile.print("Temp8: "); ///BME280
    Logfile.print(bme.readTemperature());
    Logfile.print(" C;");
    Logfile.print(" Pr: ");
    Logfile.print(bme.readPressure() / 100.0F);
    Logfile.print(" hPa;");
    Logfile.print(" Hum8: ");
    Logfile.print(bme.readHumidity());
    Logfile.println(" %;");
    Serial.print(" Temp8: ");
    Serial.print(bme.readTemperature());
    Serial.print(" C;");
    Serial.print(" Pr: ");
    Serial.print(bme.readPressure() / 100.0F);
    Serial.print(" hPa;");
    Serial.print(" Hum8: ");
    Serial.print(bme.readHumidity());
    Serial.println(" %;"); ///BME280
    BT.println(" %;");


 
    
 Logfile.close();                //Print saved
 }
 
delay(1000);                        //One data per second
}

The SD card is communicated with using SPI. Check out which pins that uses, and do NOT use them for ANY other purpose.

PaulS:
The SD card is communicated with using SPI. Check out which pins that uses, and do NOT use them for ANY other purpose.

Yes, the chip select of the SD Card is Pin 4, which is left free. So, no problem there.

phytopia:
Yes, the chip select of the SD Card is Pin 4, which is left free. So, no problem there.

But the SPI pins are 10, 11, 12, and 13. 10 defines the Arduino as master or slave, and the other three are use to send data from the master to the slave and to get data from the slave at the clorrect clock speed.

PaulS:
But the SPI pins are 10, 11, 12, and 13. 10 defines the Arduino as master or slave, and the other three are use to send data from the master to the slave and to get data from the slave at the clorrect clock speed.

Ok, so which pins can I use for the HC-06 instead of 10 and 11?

phytopia:
Ok, so which pins can I use for the HC-06 instead of 10 and 11?

Any pins that you (or code you are using) doesn't already use.

It would appear that you are using 0, 1, 2, 3, 4, 5, 10, 11, 12, 13, A4, and A5 plus whatever pins the light meter and the BME280 are using.

I changed the pins from 10 and 11 to 6 and 7. It works now, thank you!

Just to help me understand:
How do I know which pins are used and which ones are free? I didn't find anything about the pins 10 and 11 being used in my sketch.

Read the datasheet :wink:

Or do a search for arduino yourboard pinout
E.g. arduino uno pinout. You might find some incorrect ones, but the datasheet can help to verify.