Taking readings from Multiple DHT22 sensors- How to get the MAC address of each

Hi All, please how can I read the MAC address of the DHT22 sensor connected to the arduino uno board?
I want to connect multiple DHT22 and will need to take readings of each at thesame time and I need the MAC address of each sensor to do this. Thank you.

David

If you mean the DHT22 temperature/humidity sensors they do not have a mac address. Each sensor needs it's own single bi-directional digital I/O line to the Arduino. Adafruit has libraries for this sensor available on line with examples. I've never tested it but you should be able to create multiple instances of the DHT object connected to different pins.
Doug

Written this dhtlib - Arduino Playground - DHTLib - supports multiple dht22 or related types side by side.

DougMorgan:
If you mean the DHT22 temperature/humidity sensors they do not have a mac address. Each sensor needs it's own single bi-directional digital I/O line to the Arduino. Adafruit has libraries for this sensor available on line with examples. I've never tested it but you should be able to create multiple instances of the DHT object connected to different pins.
Doug

That is correct.

I have four DHT11 and two DHT22 sensors on my system at http://219.88.69.69/2WG/ - check the Recent Climate and Climate for Week web pages. You can identify the DHT22 sensor readings because they provide temperature and humidity readings to one decimal place.

All of the DHT sensors on my system simply have pin 3 plugged into separate and consecutive pins on my Arduino board. This allows all the sensors to be read within a do loop and the results to be stored within arrays. The DHT sensors all share one common power and ground connection to the Arduino board.

My only use of a MAC address is to assign one to the Arduino board and then let my router assign the board a fixed internal LAN IP address when the Ethernet.begin() procedure is invoked within the setup() procedure. By using a fixed LAN IP address on the board my router can route www http port 80 traffic coming into my broadband modem (via my external/public IP address) to the Arduino board to enable my www user interface to operate using the EthernetClient object.

On my Arduino web site as above I am publishing some of the underlying code - more will be released over the new few days (weekend).

Cheers

Catweazle NZ.

This is my version for using 2xDHT22 and DHT11 sensors. Hope this could help you.

// * Ethernet shield attached to pins 10, 11, 12, 13
// * Analog inputs attached to pins A0 through A5 (optional)

#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0, A1, 5, 4, 3, 2);

#define DHTPIN A4 
#define DHTPIN1 A3 
#define DHTPIN2 A2

#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define DHTTYPE1 DHT22 // DHT 22 (AM2302)
#define DHTTYPE2 DHT11 // DHT 11 (AM2301)

DHT dht(DHTPIN, DHTTYPE);
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE2);


byte mac[] = {   
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,40);
byte gateway[] = { 
  192, 168, 1, 1 };                  
byte subnet[] = { 
  255, 255, 255, 0 };                   


EthernetServer server(80);

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


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  dht.begin();
  dht1.begin();
  dht2.begin();
  lcd.begin(20, 4);

}


void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature();
  float h2 = dht2.readHumidity();
  float t2 = dht2.readTemperature();
  //  if (isnan(t) || isnan(h)) {
  // Serial.println("Andur kadunud");
  lcd.setCursor(0, 0);
  lcd.print("Valjas:");
  lcd.setCursor(0, 1);
      lcd.print("   ");
  lcd.print(t);
  lcd.print(" *C  ");
  lcd.print(h);
  lcd.print("%");

  lcd.setCursor(0, 2);
  lcd.print("Toas:");
  lcd.setCursor(0, 3);
    lcd.print("   ");
  lcd.print(t1);
  lcd.print(" *C  ");
  lcd.print(h1);
  lcd.print("%");
  



  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // now output HTML data starting with standart header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 10");  // refresh the page automatically every 5 sec
          client.println();
          //set background to yellow
          client.print("<body style=background-color:yellow>");


          //väljas
          client.println("<font color='green' size='12'>V&aumlljas");
          client.println("
");
          client.print(t);
          client.println(" &degC");
          client.println("&nbsp");
          client.println("&nbsp");
          client.print(h);
          client.print(" %\t");
          client.println("
");
          client.println("<hr />");
          //toas

          client.println("<font color='blue' size='12'>Toas: ");
          client.println("
");
          client.print(t1);
          client.println(" &degC");
          client.println("&nbsp");
          client.println("&nbsp");
          client.print(h1);
          client.print(" %\t");
          client.println("
");
          client.println("<hr />");
          //

          client.println("<font color='red' size='12'>X: ");
          client.println("
");
          client.print(t2);
          client.println(" &degC");
          client.println("&nbsp");
          client.println("&nbsp");
          client.print(h2);
          client.print(" %\t");
          client.println("
");
          client.println("<hr />");


          client.println("</html>");
          break;

        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 

        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

You only need one DHT object to support multiple DHT11 and DHT22 sensors. You call DHT.read11(pin #) to read a DHT11 and DHT.read22(pin #) to read a DHT22.

After DHT.readXX you should check the result for DHTLIB_OK. After that you can access temperatures and humidity via the properties DHT.temperature and DHT.humidity.

Having multiple DHT objects would likely waste SRAM.

I use this procedure to read my mixed set of DHT sensors.

int DHTRead(byte p_sensor, int & p_temperature, int & p_humidity) {
  p_temperature = 0;  //D
  p_humidity    = 0;  //D
  int l_dht_result;
  //We attempt to read the sensor three times to
  //eliminate any temporary error - seems reqd for DHT22
  byte l_count = 0;
  while (true) {
    if (l_count == 3) 
      break;
    //
    if (C_SensorDHT11[p_sensor] == true)
      l_dht_result = DHT.read11(p_sensor + DC_DHT_Sensor_First_Pin);
    else
      l_dht_result = DHT.read22(p_sensor + DC_DHT_Sensor_First_Pin);
    //
    if (l_dht_result == DHTLIB_OK)
      break;
    //
    delay(2000); //DHT22 needs 1.7 secs for generate a reading
    l_count++;
  }  
  if (l_dht_result == DHTLIB_OK) {
    p_temperature = int((DHT.temperature + DC_Temp_UpShift) * 10);
    p_humidity = int(DHT.humidity * 10);
  }
  return l_dht_result; 
}

You will note that internally I multiply both temperature and humidity readings by ten so I can carry these values (particularly DHT22 values) internally as integers rather than floats. I also upshift temperatures by 35 degrees C so I can use the number zero as a NULL value since my local temperature will never be minus 35 degrees C.

I am using DHT Library Version 0.1.07 .

Cheers

Catweazle NZ

ok i like the solution

Having to use multiple pins for each DHT22 sensor kind of defeats the reason we use I2C. but then for some reason there are heaps of manufacturers out there who seem to think its a great idea to hardcode the address in limiting your ability to chain devices on the same interface.

Dallas 1 wire temperature sensors to the rescue again, OK so they will not spit out the humidity but at least you can chain them all up on one pin.