TwoSensorsDefault.ino (2012B)
1 #include <SimpleDHT.h> 2 3 // Created by santosomar Ωr using SimpleDHT library to read data from two DHT11 sensors 4 // for DHT11, 5 // VCC: 5V or 3V 6 // GND: GND 7 // SENSOR 1 is in Digital Data pin: 2 8 // SENSOR 2 is in Digital Data pin: 4 9 10 int dataPinSensor1 = 2; 11 int dataPinSensor2 = 4; 12 SimpleDHT11 dht1(dataPinSensor1); 13 SimpleDHT11 dht2(dataPinSensor2); 14 15 void setup() { 16 Serial.begin(115200); 17 } 18 19 void loop() { 20 // Reading data from sensor 1... 21 Serial.println("================================="); 22 23 // Reading data from sensor 1... 24 Serial.println("Getting data from sensor 1..."); 25 26 // read without samples. 27 byte temperature = 0; 28 byte humidity = 0; 29 int err = SimpleDHTErrSuccess; 30 if ((err = dht1.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 31 Serial.print("Read Sensor 1 failed, err="); Serial.print(SimpleDHTErrCode(err)); 32 Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000); 33 return; 34 } 35 36 // converting Celsius to Fahrenheit 37 byte f = temperature * 1.8 + 32; 38 Serial.print("Sample OK: "); 39 Serial.print((int)temperature); Serial.print(" *C, "); 40 Serial.print((int)f); Serial.print(" *F, "); 41 Serial.print((int)humidity); Serial.println(" H humidity"); 42 43 44 // Reading data from sensor 2... 45 // ============================ 46 Serial.println("Getting data from sensor 2..."); 47 48 byte temperature2 = 0; 49 byte humidity2 = 0; 50 if ((err = dht2.read(&temperature2, &humidity2, NULL)) != SimpleDHTErrSuccess) { 51 Serial.print("Read Sensor 2 failed, err="); Serial.print(SimpleDHTErrCode(err)); 52 Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000); 53 return; 54 } 55 56 // converting Celsius to Fahrenheit 57 byte fb = temperature2 * 1.8 + 32; 58 59 Serial.print("Sample OK: "); 60 Serial.print((int)temperature2); Serial.print(" *C, "); 61 Serial.print((int)fb); Serial.print(" *F, "); 62 Serial.print((int)humidity2); Serial.println(" H humidity"); 63 64 // DHT11 sampling rate is 1HZ. 65 delay(1500); 66 }