1

Hi I am working on a project in which I am supposed to tell if a person is running/standing/walking and going upstairs/downstairs or he is on straight road. The person will carry a arduino uno module to which gps,bluetooth and altitude sensor is attached. Also I am trying to send my phone his speed and current altitude he is experiencing using HC-05 bluetooth module. I am sure that there is no problem with altitude sensor. Also I must note that my gps module(GY_NE06MV2) is not acting proper when it comes to speed of the person. I believe this is because I experimented in my house and not outside. The problem is that I cannot see speed and altitude data on bluetooth terminal app"ArduTooth" on my phone. It is just like a blank space which should have been my data. I am presenting my code which is not very long and I hope you could help me get through this.

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

TinyGPSPlus gps; //gps object to be used
SoftwareSerial BTserial(10, 11); //bluetooth serial connection
SoftwareSerial gps_serial(4,3); //gps serial connection
Adafruit_BME280 bme; //altitude measuring sensor object

#define SEALEVELPRESSURE_HPA (1011) //sea level pressure in Turkey/Eskisehir

double speed = 0; //speed of a moving body
double current_altitude = 0;
double previous_altitude = 0;

void setup() {
Serial.begin(115200); // serial connection to computer
BTserial.begin(9600);
gps_serial.begin(9600);
bme.begin(0x76);

delay(3000);

previous_altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);

}

void loop() {
//data from gps device is fed to gps object  
while (gps_serial.available() > 0){
    gps.encode(gps_serial.read());
}

if(gps.speed.isValid()){
speed = gps.speed.kmph();
BTserial.write(speed); // this is where the problem-1 is, this data is not shown on mobile phone 
bluetooth terminal application
BTserial.write(",");

  if(speed <= 5 && speed > 0.5){
    BTserial.write("walking");
    BTserial.write(","); 
  }
  if(speed <= 0.5){
    BTserial.write("standing");
    BTserial.write(",");
  }
  if(speed > 5){
    BTserial.write("running");
    BTserial.write(","); 
  }

  }else{
    BTserial.write("m.s.n.n"); //stands for "moving status not known"
    BTserial.write(",");  
  }

current_altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
BTserial.write(current_altitude); //this is where problem-2 is, this data also is not displayed 
on phone
BTserial.write(",");
//this part determines either the body goes upstairs or downstairs or he is on straight road
if(current_altitude - previous_altitude >= 0.7){
  BTserial.write("going ups.");
  previous_altitude = current_altitude;  
}
if(previous_altitude - current_altitude >= 0.7){
  BTserial.write("going downs.");
  previous_altitude = current_altitude; 
}
if((current_altitude - previous_altitude <= 0.3) || (previous_altitude - current_altitude <= 
0.3)){
  BTserial.write("on s.r");
  previous_altitude = current_altitude;  
}
BTserial.write(";");

delay(1000);

}

I must note that purpose of BTserial.write(","); is that every seperate entry sent to phone via bluetooth must be seperated by ",".

2
  • 1
    Have you verified, that your serial bluetooth connection is working? I mean without all the other code. Also you are using the write method, which is mostly used for binary data. I guess that you want to transmit ASCII encoded dara, thus you need to use print() for the altitute variable transmit
    – chrisl
    Aug 19, 2020 at 17:32
  • Bluetooth module is working fine I guaranteed that. I will try that thanks. Also can you tell me about gps module which makes me sad as it does not give speed. I believe it is because I am at home doing experiments. I am using tinygps++ library and its functions for that
    – EEstudent
    Aug 19, 2020 at 17:34

2 Answers 2

1

You can convert you double data to string type.this trick may help. And you also can just sent a byte for different positions and decode them in app.

0

SoftwareSerial is a very badly behaved library. It blocks interrupts while sending or receiving bytes. Using it with whatever depends on interrupts is asking for trouble. Using two instances of SoftwareSerial concurrently is doubly asking for trouble. It is very likely that they are interfering with one another, as each one blocks interrupts for an unreasonably long time, and each one relies on interrupts for detecting incoming data.

You don't seem to be using the hardware serial interface (Serial), which is a shame, as it is the only serial port you have that works really well. I suggest you try to use this interface for one of your devices (maybe the GPS), and a single software interface for the other one.

Or, better yet, use Serial for both. The transmit and receive parts of a serial port are fairly independent, save for the fact that they work at the same speed. You could use the transmit part for the Bluetooth module and the receive part for the GPS. This should ensure reliable communication with both devices, without ever blocking interrupts for too long.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.