Different Values Not printing Simultaneously on the Serial monitor

Hello people!
I am doing some stuff for a project and the problem, I am facing is as follows.
So, I am trying to Interface a DHT11 and a NEO 6m module with Arduino Uno

. When I print the values on the Serial Monitor, The location parameters and the Temperature parameters should be printed simultaneously, Instead, they are not as you can see in the Screen Shot attached below, I want them to get printed simultaneously and I am not able to :frowning:
please Help.

Here is the code I am running :

#include "DHT.h"
#define Type DHT11 
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
int Rtxp = 4;
int Txp = 3;
TinyGPSPlus Gps;
int Gbaud = 9600;
SoftwareSerial ss(Rtxp,Txp);
int SenPin = 2; 
DHT HT (SenPin , Type );
int dt = 2000;
float H;
float TempC;
float TempF;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  ss.begin(Gbaud);
  HT.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
     
          H = HT.readHumidity();
  TempC = HT.readTemperature();
  TempF = HT.readTemperature(true);
  Serial.print("Humidity :");
  Serial.print(H);  
  Serial.print("Temperature C  :");
  Serial.print(TempC);
  Serial.print("Temperature F  :");
  Serial.println(TempF);
      delay(250);
    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(true);
  }
  }
  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);
    delay(250);
  }
  else
  {
    Serial.print(F("INVALID"));
    delay(250);
  }

  
  Serial.println();
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like
  delay(250);

could be the problem as it is positioned between the 2 sets of print statements

I Have tried changing it as you stated, but It did not work :confused:
I am trying to get these values printed one by one consecutively clearly it is not working.

#include "DHT.h"
#define Type DHT11 
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
int Rtxp = 4;
int Txp = 3;
TinyGPSPlus Gps;
int Gbaud = 9600;
SoftwareSerial ss(Rtxp,Txp);
int SenPin = 2; 
DHT HT (SenPin , Type );
int dt = 2000;
float H;
float TempC;
float TempF;
float Lati;
float Longi;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  ss.begin(Gbaud);
  HT.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
     
   H = HT.readHumidity();
  TempC = HT.readTemperature();
  TempF = HT.readTemperature(true);
  Serial.print("Humidity :");
  Serial.print(H);  
  Serial.print("Temperature C  :");
  Serial.print(TempC);
  Serial.print("Temperature F  :");
  Serial.println(TempF);
    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(true);
  }
    
  
  }
  delay(250);
}


  
  void displayInfo()
{
  Serial.print(F("Location: ")); 
  if (Gps.location.isValid())
  {
    Lati = (Gps.location.lat());
     Longi = (Gps.location.lng());
     Serial.print (Lati);
      Serial.print(F(",")); 
     Serial.print(Longi);
  
  }
  else
  {
    Serial.print(F("INVALID"));
    
  }

  
  Serial.println();
}

  
  

@saad_abdullaj
The problem is that you print Temp and Hum in each time as running the loop(), but Location only when data is available from GPS.
Because GPS outputs it data more rarely than termometer - printing are not simultaneous.
As a solution try to move Temp and Hum printing inside the

if (Gps.location.isValid())

condition block

1 Like

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

1 Like

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