DHT11 and DHT22 one arduino

Hi , i am making a project where i want to use a DTH11 to measure external temperature and a DHT22 to measure internal temperature and then save the data in a sd card , is it possible ?

this is my program right now , what i changes i need to do ?

#include "DHT.h"//include library code - Adafrut DHT sensor library
#include <SPI.h> //include library code -for the SD card module
#include <SD.h> //include library code - for the SD card
//***********************************************************
#define DHTPIN 6 //DHT sensor connected to this pin
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);//initialize DHT sensor
// change this to match your SD shield or module;
// Arduino Ethernet shield and modules: pin 4
// Data loggin SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;
File myFile;//create a file to store the data
//************************************************************
void setup() {
Serial.begin(9600);//initialize serial communiation at 9600 bps
dht.begin();//initializing the DHT sensor
Serial.print("Initializing SD card...");//setup for the SD card
if(!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
myFile=SD.open("DATA.txt", FILE_WRITE);//opens file
if (myFile) { //if the file opened ok, writes to it
Serial.println("File opened ok");
myFile.println("Humidade %, Temperatura ºC");//prints the headings for our data
}
myFile.close();
}
//************************************************************
void loggingHumidity() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// Read the humidity value in percent from the DHT sensor
float h = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(h)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
//debugging purposes
Serial.print("Humidade: ");
Serial.print(h);
Serial.print(" %\t");

myFile = SD.open("DATA.txt", FILE_WRITE);
if (myFile) {
Serial.println("open with success");
myFile.print(h);
myFile.print(","); //Move to next column using a ","
}
myFile.close();
}
//***********************************************************
void loggingTemperature() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
//float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(t) /|| isnan(f)/) {
Serial.println("Failed to read from DHT sensor!");
return;
}
//debugging purposes
Serial.print("Temperatura: ");
Serial.print(t);
Serial.println(" *C");
//Serial.print(f);
//Serial.println(" *F\t");

myFile = SD.open("DATA.txt", FILE_WRITE);
if (myFile) {
Serial.println("open with success");
myFile.print(t);
myFile.print(","); //Move to next column using a ","
myFile.println(); //End of Row move to next row
}
myFile.close();
}
//***********************************************************
void loop() {
loggingHumidity();
loggingTemperature();
delay(2000);//sets 2 seconds delay between measurements
}

is it possible ?

Yes, some of us could do it.

this is my program right now , what i changes i need to do ?

Whatever changes are necessary to make what the program actually does the same as what you want the program to do.

You completely failed to explain what that code actually does, or how it differs from what you want it to do.

Hi , so the program right now just takes the measurements from the DHT11 and saves them on a as SDcard so i can see it later on excel .

I want to keep it that way but just add also the measurements of the DHT22 , so that i can see both measurements in excel and compare them

Your code doesn't have an instance of the DHT class for the DHT22 sensor.
Your code doesn't read the temperature from the DHT22. Nor does it read the humidity, though that may not matter.
Your code doesn't write the data (that it doesn't have) from the DHT22 sensor to the file.

I can't imagine how you would expect your code to just somehow magically know that it needs to do those things.

As Paul says, you should declare a pin and an instance for the DHT22 as well.
Then when doing measurement, you should make only one function that measures all data from both sensors and creates a string containing all the stuff you want to save on the SD card.

Here is a pseudo code for it:

DHT11 : measure temp11
DHT11 : measure humi11
DHT22 : measure temp22
DHT22 : measure humi22
Create string with all data
Write string on SD card

This is very light pseudocode of course. But you have everything needed in your code by now.

However, you might as weel want to add some timing information to display that data vs time. Then you'll need a real time clock (RTC, choose a DS3231 for example) or a Wifi connection to get the time from the Internet.