Need help for a poultry project

Hello

I am doing a datalogger poultry project and i want to measuse temperature humidity and ammonia in 3 points inside a poultry and store the measurements to an sd card every 10 minutes.

I am using a mega 2560 and 3 dht11 sensors and 3 mq137 sainsmart sensor.

For reading measurements from dht11 sensor i am using this library
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN A3

// 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");
}

For the mq137 i need only to read the analog voltage so i know i have to use the command analogread(Apin)

Can you help me combine the code to read from 3 different dht 11 and 3 different mq137 and store them to an sd card via waveshare sd card module ( as i read in a topic i connected the sd module to 50,51,52,53 pins and 3.3 volts and ground) Also i am using an external power supply to the breadboard cause the mq sensors consume a lot of electricity and the arduino doesnt have this supply.

Thanks in advance

#define DHTPIN1 ...
#define DHTPIN2 ...
#define DHTPIN3 ... //where ... is replaced with the pin you want to use.

DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
DHT dht3(DHTPIN3, DHTTYPE);

Then read them with like
float h = dht1.readHumidity(); //instead of dht, we use dht1 or dht2 or dht3.

Reading those gas sensors is just reading an analog value. Use analogRead(). You need them wired up as a voltage divider, like an LDR or the other MQ gas sensors.

Glad to hear you're using an external power supply for the sensors. You would be amazed how badly some people don't want to use external power.

Anyhelp for datalogging to the sd ?

Thanks in advance

tsotos:
Anyhelp for datalogging to the sd ?

Thanks in advance

https://www.arduino.cc/en/Tutorial/ReadWrite perhaps?

I do logging in two parts.
One Arduino for data acquisition, one Arduino for data logging.

See:

Hello,

So this is the final code

/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:

#include “DHT.h”
#include <SPI.h>
#include <SD.h>

#define DHTPIN1 A1
#define DHTPIN2 A3
#define DHTPIN3 A5

#define DHTTYPE DHT11

DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
DHT dht3(DHTPIN3, DHTTYPE);

const int chipSelect = 53;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

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.”);

dht1.begin();
dht2.begin();
dht3.begin();
}

// the loop routine runs over and over again forever:
void loop() {

float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
float h3 = dht3.readHumidity();
float t3 = dht3.readTemperature();
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
int sensorValue1 = analogRead(A2);
int sensorValue2 = analogRead (A4);
File datafile = SD.open(“datalog.txt”, FILE_WRITE);
// print out the value you read:
Serial.print("to proto A0 = ");
Serial.println(sensorValue);
datafile.print("to proto A0 = ");
datafile.println(sensorValue);
datafile.print("thermokrasia to proto = ");
datafile.println(t1);
datafile.print("igrasia to proto = ");
datafile.println(h1);

delay(1000);
Serial.print("to deutero A2 = ");
Serial.println(sensorValue1);
datafile.print("to deutero = ");
datafile.println(sensorValue1);
datafile.print("thermokrasia to deutero = ");
datafile.println(t2);

delay(1000);
Serial.print("to trito A4 = ");
Serial.println(sensorValue2);
datafile.print("to trito = ");
datafile.println(sensorValue2);
datafile.print("thermokrasia to trito = ");
datafile.println(t3);
datafile.close();
delay(1000); // delay in between reads for stability
}

Everything seems to work but in the sd file in the temperature and humidity measurement i get nan

Any help?

Thanks in advance

the code is working. The problem was my fault due to a bad connection of the dht 11 sensors . Thank you very much !!