Hi all -
I'm trying to build a small temperature monitor, with an UnoR3 and 5 DHT11 temperature/humidity sensors. These are 3-wire digital thingies (5V, GND, data). I'd like to have the code sort-of generic, but can't figure out how to set it up properly.
The library uses something like this (simplified from original example):
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
DHT is a class for the sensor and defined in the DHT library.
dht(pin,type) is a constructor for the sensor and defined in the DHT library.
This good for one sensor, but now I'd like to do the same for 3 or 4 or 5...
Something like this:
const int MaxSensors = 5;
DHT myDHT[MaxSensors]; // an array[0..4] of sensors
void setup() {
for (int n=0; n<MaxSensors-1; n++) {
myDHT[n] = dht(n, 11); // define a sensor at pin 'n' with sensor type DHT11
}
}
void loop(){
// etc.
}
However, I can't get this to work. So ...
Given a given class DHT with a constructor dht(pin, type), how do I create an array of sensors with pins 0,1,2,3,4 and type 'whatever' in Arduino ?
Any help is seriously appreciated.
/O.