Baud rates conflicting with sensors

I'm running 5 different sensors on Ardunio UNO. These sensors are gyroscope, GPS, micradar and temperature sensor. However, the baud rates of GPS and Micradar sensors are different and neither of them returns the result to the serial screen. How can I fix this?

#include <SoftwareSerial.h>                                  
#include "Arduino.h"
#include <Wire.h>
#include <60ghzbreathheart.h>                                           
#include <Adafruit_MLX90614.h>
#include <ADXL345.h>
#include <TinyGPSPlus.h>
#include <SPI.h>

#define MRx_Pin A0
#define MTx_Pin A1
#define RX    4                
#define TX    3  
int rxPin = 10;                                        
int txPin = 11;                                          

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
ADXL345 acc;
TinyGPSPlus gps;


SoftwareSerial ss(RX, TX);
SoftwareSerial esp(rxPin, txPin);
SoftwareSerial mySerial = SoftwareSerial(MRx_Pin, MTx_Pin);
BreathHeart_60GHz radar = BreathHeart_60GHz(&mySerial);

int accX, accY, accZ;
void setup() {
  Serial.begin(115200);
  Serial.println("Started");
  if (!mlx.begin()) {
    Serial.println("Error connecting to MLX sensor. Check wiring.");
    while (1);
  }

  //delay(1000);
  ss.begin(9600); //GPS
  mySerial.begin(115200); //MICRADAR
  

}
void loop() {
  readTemperature();
  readGPS();
  readRadar();
  readAccelerometer();
  sendDataToThingSpeak();
  //delay(1000);
  void readTemperature() {
  float temperature = mlx.readObjectTempC();
  Serial.print("Temperature: ");
  Serial.println(temperature);
}

void readGPS() 
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(false);
  }
}

void displayInfo()
{
  Serial.print(F("Location: ")); 
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.println();
}



void readRadar() {
  radar.Breath_Heart();           //Breath and heartbeat information output
  if(radar.sensor_report != 0x00){
    switch(radar.sensor_report){
      case HEARTRATEVAL:
        Serial.print("Sensor monitored the current heart rate value is: ");
        Serial.println(radar.heart_rate, DEC);
        Serial.println("----------------------------");
        break;
      case HEARTRATEWAVE:  //Valid only when real-time data transfer mode is on
        Serial.print("The heart rate waveform(Sine wave) -- point 1: ");
        Serial.print(radar.heart_point_1);
        Serial.print(", point 2 : ");
        Serial.print(radar.heart_point_2);
        Serial.print(", point 3 : ");
        Serial.print(radar.heart_point_3);
        Serial.print(", point 4 : ");
        Serial.print(radar.heart_point_4);
        Serial.print(", point 5 : ");
        Serial.println(radar.heart_point_5);
        Serial.println("----------------------------");
        break;
      case BREATHNOR:
        Serial.println("Sensor detects current breath rate is normal.");
        Serial.println("----------------------------");
        break;
      case BREATHRAPID:
        Serial.println("Sensor detects current breath rate is too fast.");
        Serial.println("----------------------------");
        break;
      case BREATHSLOW:
        Serial.println("Sensor detects current breath rate is too slow.");
        Serial.println("----------------------------");
        break;
      case BREATHNONE:
        Serial.println("There is no breathing information yet, please wait...");
        Serial.println("----------------------------");
        break;
      case BREATHVAL:
        Serial.print("Sensor monitored the current breath rate value is: ");
        Serial.println(radar.breath_rate, DEC);
        Serial.println("----------------------------");
        break;
      case BREATHWAVE:  //Valid only when real-time data transfer mode is on
        Serial.print("The breath rate waveform(Sine wave) -- point 1: ");
        Serial.print(radar.breath_point_1);
        Serial.print(", point 2 : ");
        Serial.print(radar.breath_point_2);
        Serial.print(", point 3 : ");
        Serial.print(radar.breath_point_3);
        Serial.print(", point 4 : ");
        Serial.print(radar.breath_point_4);
        Serial.print(", point 5 : ");
        Serial.println(radar.breath_point_5);
        Serial.println("----------------------------");
        break;
    }
  } 
  
  delay(200);                       //Add time delay to avoid program jam
}

void readAccelerometer() {
  acc.readAccel(&accX, &accY, &accZ);
  Serial.print("AccX: ");
  Serial.println(accX);
  Serial.print("AccY: ");
  Serial.println(accY);
  Serial.print("AccZ: ");
  Serial.println(accZ);
}

void sendDataToThingSpeak() {
  String veri = "GET https://api.thingspeak.com/update?api_key=PMA6WK5Z4DZAA8PI";
  veri += "&field1=";
  veri += String(mlx.readObjectTempC());
  /*
  veri += "&field2=";
  veri += String(latitude);
  veri += "&field3=";
  veri += String(longitude);
  */
  veri += "&field4=";
  veri += String(accX);
  veri += "&field5=";
  veri += String(accY);
  veri += "&field6=";
  veri += String(accZ);
  veri += "&field7=";
  veri += String(radar.heart_rate);
  veri += "&field8=";
  veri += String(radar.breath_rate);
  esp.print("AT+CIPSEND=");
  esp.println(veri.length() + 2);
  delay(2000);
  if (esp.find(">")) {
    esp.print(veri);
    Serial.println(veri);
    Serial.println("Veri gonderildi.");
    delay(1000);
  }
  Serial.println("Baglantı Kapatildi.");
  esp.println("AT+CIPCLOSE");
  delay(1000);
}

}

Welcome to the forum

Thank you for trying to use code tags. Unfortunately you used the apostrophe rather than the backtick character. I have corrected your post

This is the easiest way to tidy up the code and add the code tags

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Your code seems to be incomplete; where are all the functions that you call from loop()?

Using multiple SoftwareSerials is usually a recipe for disaster. Only one SoftwareSetial instance can listen at a time.

Advice would be to use a board that has multiple UARTs (e.g. Mega) r can be configured as such (e.g. Nano Every)

1 Like

This may help: SC16IS752 I2C-SPI to Dual Channel UART Converter Module
CJMCU SC16IS752 I2C-SPI to Dual Channel UART Converter Module Each module will give you two additional serial channels. SPI requires 3 connections common to all modules and an additional CS\ Chip Select connection. This will allow you to match the bauds to the peripherals. These have a 64 byte FIFO (First In First Out) buffer so that will give you time to do things while data is coming in from a sensor.

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