help with code datalogger sensors dht 11 mq137

Hello,

I have to build a project that measures temperature humidity and ammonia and log the measurments in an sd card.

I downloaded the simple code of dht11 testing and the library and all the dht11 sensors work. If i run the datalogger code that is on the examples of arduino the mq137 works fine and store the measurements in the sd but the dht11 only shows 1023. Can you help me connect the two codes so the dht11 work on the datalogger code ?

Thanks in advance

Can you help me connect the two codes so the dht11 work on the datalogger code ?

Without seeing them? No.

How is anyone going to help you alter something in your code if you dont post your code...
Perhaps post your code?

sorry for not posting the code

The datalogger code is

/*
  SD card datalogger

 This example shows how to log data from three analog sensors
 to an SD card using the SD library.

 The circuit:
 * analog sensors on analog ins 0, 1, and 2
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4

 created  24 Nov 2010
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

#include <SPI.h>
#include <SD.h>

const int chipSelect = 4;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ",";
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}

and the dht11 sensor testing is this

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN A4     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT11   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // 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(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}
  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ",";
    }
  }

Use the damned code that worked to read the DHT11. Reading analog pins with nothing connected to them is useless.

Using Strings, instead of just writing to the file is wasting resources. You don't have any to wasted. GET RID OF THE String CLASS!

i have 6 dht11 sensors and 3 mq137 ...

I dont know if i am using the right codes. I have to take measurments from 6 dht 11 sensors and 3 mq137 sensors every 10 minutes and store them in a sd card.

So both these sketches work fine seperately, right?

You asked for help combining the two into one. What exactly is it that you cannot do?

Just put everything above the setup into the same location in your main sketch, the same for the setup as well as the main loop in whatever order you want. Obivously you would write to the SD card after you read the sensor.

The datalogger example will print nothing if you do not connect a snensor.
Make sure your sensor is connected correctly, if it works in the seperate sketch then it will work in this one two, just combine the sketches.

Setup goes in the setup, loop in the loop... etc...

the sketch for the dht 11 is working fine only for one sensor. I cant make it to work for 6 sensors. in the datalogger code it work fine for the 3 mq137 sensors. If i add the dht 11 sensors to the datalogger code i get only 1023 measurments from the dht 11 and correct measurment from the mq137.

any help ?

this is a test sketch for 2 dht11 (there digital so any input pin will work, re-assign to test as this is copied from a sketch I used on a mega)

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

//#define DHTPIN A4     // what pin we're connected to

#define DHT1 14
#define DHT2 16

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT11   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT sensor1(DHT1, DHTTYPE);
DHT sensor2(DHT2, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  sensor1.begin();
  sensor2.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = sensor1.readHumidity();
  // Read temperature as Celsius (the default)
  float t = sensor1.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = sensor1.readTemperature(true);

  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h2 = sensor2.readHumidity();
  // Read temperature as Celsius (the default)
  float t2 = sensor2.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f2 = sensor2.readTemperature(true);



  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor one!");
  
  }
  if (isnan(h2) || isnan(t2) || isnan(f2)) {
    Serial.println("Failed to read from DHT sensor two!");
  
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = sensor1.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = sensor1.computeHeatIndex(t, h);

  Serial.print("Humidity one: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature one: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index one: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
  Serial.print("Humidity two: ");
  Serial.print(h2);
  Serial.print(" %\t");
  Serial.print("Temperature two: ");
  Serial.print(t2);
  Serial.print(" *C ");
  Serial.println(f2);
}

any help for how do i program the mq137 to show right measurements ?