I am trying to build a weather station and to access its data through mobile SMS/Text messages using GPRS sim 900, but I don't know how to combine the codes of DHT22 and BMP180 into a single sketch. The separate sketches are as follows:

For DHT

#include "DHT.h"
#include <Adafruit_Sensor.h>
#include <SoftwareSerial.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

float t;
float h;
float pf;
float pi;

SoftwareSerial SIM900(7, 8);
char incomingChar;
void setup() {
  dht.begin();
  Serial.begin(19200); 
  SIM900.begin(19200);
  delay(20000);
  Serial.print("SIM900 ready...");
  SIM900.print("AT+CMGF=1\r"); 
  delay(100); 
  SIM900.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
}
void loop(){
  if (SMSRequest()){
    if(readData()){
      delay(10);
      SIM900.println("AT + CMGS = \"+923039058801\"");
      delay(100);
      String dataMessage = ("Temperature: " + String(t) + "*C " + " Humidity: " + String(h) + "%");
      SIM900.print(dataMessage);
      delay(100);
      SIM900.println((char)26); 
      delay(100);
      SIM900.println();
      delay(5000);  
    }
  }
  delay(10); 
}
boolean readData() {
  h = dht.readHumidity();
  t = dht.readTemperature();
  t = dht.computeHeatIndex(t,h,false);
  pi = pressure.startPressure(3);
  pf= pressure.getPressure(P,T);


  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return false;
  }
  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.print(" *C ");
  return true;
}

boolean SMSRequest() {
  if(SIM900.available() >0) {
    incomingChar=SIM900.read();
    if(incomingChar=='s') {
      delay(10);
      Serial.print(incomingChar);
      incomingChar=SIM900.read();
      if(incomingChar =='t') {
        delay(10);
        Serial.print(incomingChar);
        incomingChar=SIM900.read();
        if(incomingChar=='a') {
          delay(10);
          Serial.print(incomingChar);
          incomingChar=SIM900.read();
          if(incomingChar=='t') {
            delay(10);
            Serial.print(incomingChar);
            incomingChar=SIM900.read();
            if(incomingChar=='e') {
              delay(10);
              Serial.print(incomingChar);
              Serial.print("...Request Received \n");
              return true;
            }
          }
        }
      }
    }
  }
  return false;
}

For BMP180:

#include <SFE_BMP180.h>
#include <Wire.h>
SFE_BMP180 pressure;

void setup()
{
  Serial.begin(9600);
  Serial.println("REBOOT");
  if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {
    Serial.println("BMP180 init fail\n\n");
    while(1);
    }
}

void loop()
{
  char status;
  double T,P;  
  Serial.println();
  status = pressure.startTemperature();
  if (status != 0)
  {
    delay(status);
      status = pressure.startPressure(3);
      if (status != 0)
      {
        delay(status);

        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          // Print out the measurement:
          Serial.print("absolute pressure: ");
          Serial.print(P,2);
          Serial.print(" mb, ");
        }
        else Serial.println("error retrieving pressure measurement\n");
      }
      else Serial.println("error starting pressure measurement\n");
    }
  delay(5000);  // Pause for 5 seconds.
}

closed as too broad by Rudy, Greenonline, sempaiscuba, gre_gor, per1234 Dec 3 at 22:13

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    What exactly was your problem with combining them? Just do both measurements serially and only use delay(), when its really necessary, since it's just busy waiting. For how to do timed things without delays refer to the BlinkWithoutDelay example of the Arduino IDE – chrisl Dec 3 at 20:29

Browse other questions tagged or ask your own question.