HC-05 Bluetooth module gives weird value for ADXLL335 accelerometer

Hi, when I am using only ADXL335 with the UNO, I am getting constant value of output (zeros and occasional 0.01s ) for the accelerometer when it is in stable mode as intended. But, when I use the HC-05 module to get the sensor reading wirelessly, I am getting slightly spiking values as below when it should be all zero or occasional 0.01s


My coding is as below:


//***************************************************************************************************************
// Specify data type and pin for ADXL335 accelerometers
//***************************************************************************************************************
int z1pin = A1; // Specify pin for x-axis acceleration of ADXL335 accelerometer 1


int z1value; // Read the analog output of ADXL335 accelerometer 1 from pin A0

void setup()
{

  Serial.begin(9600); // Begin serial monitor
  Serial.println("CLEARDATA"); // Automatically clear previous data when rerecord the sensor value in PLX-DAQ software
  Serial.println("LABEL,Time,Timer,Date,Raw1,Acc1");
  Serial.println("RESETTIMER"); // Automatically reset the time when rerecord the sensor value in PLX-DAQ software


}
void loop() {



  //***************************************************************************************************************
  // Read raw x,y, and z-axis acceleration of ADXL335 accelerometer 1 to 8 in G unit
  //***************************************************************************************************************
  for (int sample = 0; sample <= 179; sample++) {
    for (int rate = 0; rate <= 9; rate++) {
      z1value = analogRead(z1pin);                    // Read values from x-pin & measures acceleration in X direction
      int z1 = map(z1value, 262, 605, -100, 100);     // Map the extreme ends analog values from -100 to 100. Need to replace the 564 value with your values from calibration
      float z1g = (float)z1 / (-100.00);          // Convert the mapped value into acceleration in terms of "g". Have to minus one since minimum acceleration for x-axis in this case is 1g
      float Acc1 = (abs(z1g - 1) );

      Serial.print("DATA,TIME,TIMER,");
      //Serial.print("GROUND");
      // Serial.print(",");
      Serial.print(z1value);
      Serial.print(",");
      Serial.println(Acc1);
      delay (110);
    }
  }
}

My connection is as below:


Any help would be great. Thanks

Put the HC05 on a software serial port and use the hardware serial to view progrsm output and debugging information on serial monitor. Only one thing should be connected to each serial port. Haveing the HC05 and serial monitor connected to Serial at the same time can cause problems.

Thank you. I added the software serial code and changed the BT module connections too. But, the serial monitor is blank. This is the code now,


//***************************************************************************************************************
// Specify data type and pin for ADXL335 accelerometers
//***************************************************************************************************************
#include <SoftwareSerial.h>

#define rxPin 10
#define txPin 11

// Set up a new SoftwareSerial object
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
int z1pin = A1; // Specify pin for x-axis acceleration of ADXL335 accelerometer 1

int z1value; // Read the analog output of ADXL335 accelerometer 1 from pin A0

void setup()
{
  mySerial.begin(9600);
  Serial.begin(9600); // Begin serial monitor
  Serial.println("CLEARDATA"); // Automatically clear previous data when rerecord the sensor value in PLX-DAQ software
  Serial.println("LABEL,Time,Timer,Date,Raw1,Acc1");
  Serial.println("RESETTIMER"); // Automatically reset the time when rerecord the sensor value in PLX-DAQ software


}
void loop() {
}
//***************************************************************************************************************
// Read raw x,y, and z-axis acceleration of ADXL335 accelerometer 1 to 8 in G unit
//***************************************************************************************************************
for (int sample = 0; sample <= 179; sample++) {
  for (int rate = 0; rate <= 9; rate++) {
    z1value = analogRead(z1pin);                    // Read values from x-pin & measures acceleration in X direction
    int z1 = map(z1value, 0, 1023, -100, 100);     // Map the extreme ends analog values from -100 to 100. Need to replace the 564 value with your values from calibration
    float z1g = (float)z1 / (-100.00);          // Convert the mapped value into acceleration in terms of "g". Have to minus one since minimum acceleration for x-axis in this case is 1g
    float Acc1 = ((z1g - 1) );


    Serial.print("DATA,TIME,TIMER,");
    //Serial.print("GROUND");
    // Serial.print(",");
    Serial.print(z1value);
    Serial.print(",");
    Serial.println(Acc1);
    delay (110);
  }
}
}

When do you write with the software serial port?

What is the HC05 talking to?

Bluetooth does not make data up, it simply passes on what it is given. At the moment it isn't being given anything as you are not printing to the software serial port, and therefore will get no result. You would be better off with your original code, as you have already demonstrated where the problem is. Hardware serial sends OK to the monitor, but not via Bluetooth, so Bluetooth is either the problem, or the cause of it. Since there is something getting through to what appears to be a spreadsheet, the wiring must be kosher, and I can hardly see where Bluetooth itself can be the problem.

It is quite OK to have Bluetooth and the monitor on hardware serial, it just means you cannot send from the monitor, you only get to see what is going on. The former is of no interest to you anyway, and the latter can be really useful right now.

It is not clear that you sent data to serial monitor and Bluetooth simultaneously. If that was not the case, I suggest you do so now - with your original code. If you get different readings on your monitor and spreadsheet, that will be quite interesting.

You appear to be using PLX, which impresses me, as it is the first time I have seen that done via Bluetooth, but you might humour us by using a plain-vanilla terminal instead.

What is your power supply?

I looked on how to add software serial added the some lines at the top and the setup. I think I might have done it wrongly.

I don't get it. It is sending data to my laptop via the bluetooth on my laptop.

Yes, I don't need to send data to the HC05, I just want to receive the reading of the sensor on the serial monitor wirelessly.

I selected the HC05's port (COM 6 as wired would be COM3) before checking the readings on serial monitor. I could not get the readings simultaneously at both the PLX and serial monitor as it shows the Port is busy. when either one is using it.

Sorry, the PLX was added to collect long amount of data and analyse them easily. I will try removing the PLX and run just with serial monitor.

For the HC05 and ADXL335 the supply is from 5V pin of UNO and the UNO is connected to laptop's port. Tried connecting them separately to a powerbank but still the same.

Yes, I understand your intentions (basic data-logging), hence my comment. I'm not sure what is going on with the communications, but I was unclear anyway. I meant simultaneous by cable to a PC, and via Bluetooth to a phone. etc. You might try that

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.