Hi everyone,
is my first post on arduino forum so I hope will do it right.
I have an arduino UNO and I have connected 5 sensors AM2301 because I will like to check temp in 5 location. now the sensors are on my desk one next to other but the readings are different around 1.5 degrease from min to max and on humidity around 3%
I try to read all sensors and display the data and I do not understand why there is so big difference.
Is there any mistakes in my code? I am a beginner of software development and I do have basic understanding.
here is the code
#include “DHT.h”
//—
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac = {
0x90, 0xA2, 0xDA, 0x00, 0x23, 0x36 }; //MAC address found on the back of your ethernet shield.
IPAddress ip(192,168,2,177); // IP address dependent upon your network addresses.
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
//—
#define DHT1PIN 2 // what pin we’re connected to
#define DHT2PIN 3
#define DHT3PIN 5
#define DHT4PIN 6
#define DHT5PIN 7
// Uncomment whatever type you’re using!
//#define DHT1TYPE DHT11 // DHT 11
#define DHT2TYPE DHT22 // DHT 22 (AM2302)
#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +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
DHT dht1(DHT1PIN, DHTTYPE);
DHT dht2(DHT2PIN, DHTTYPE);
DHT dht3(DHT3PIN, DHTTYPE);
DHT dht4(DHT4PIN, DHTTYPE);
DHT dht5(DHT5PIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(“DHTxx test!”);
delay(5000);
dht1.begin();
dht2.begin();
dht3.begin();
dht4.begin();
dht5.begin();
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
float h3 = dht3.readHumidity();
float t3 = dht3.readTemperature();
float h4 = dht4.readHumidity();
float t4 = dht4.readTemperature();
float h5 = dht5.readHumidity();
float t5 = dht5.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t1) || isnan(h1)) {
Serial.println(“Failed to read from DHT #1”);
} else {
Serial.print(“Humidity 1: “);
Serial.print(h1);
Serial.print(” %\t”);
Serial.print(“Temperature 1: “);
Serial.print(t1);
Serial.println(” *C”);
}
if (isnan(t2) || isnan(h2)) {
Serial.println(“Failed to read from DHT #2”);
} else {
Serial.print(“Humidity 2: “);
Serial.print(h2);
Serial.print(” %\t”);
Serial.print(“Temperature 2: “);
Serial.print(t2);
Serial.println(” *C”);
}
if (isnan(t3) || isnan(h3)) {
Serial.println(“Failed to read from DHT #3”);
} else {
Serial.print(“Humidity 3: “);
Serial.print(h3);
Serial.print(” %\t”);
Serial.print(“Temperature 3: “);
Serial.print(t3);
Serial.println(” *C”);
}
if (isnan(t4) || isnan(h4)) {
Serial.println(“Failed to read from DHT #4”);
} else {
Serial.print(“Humidity 4: “);
Serial.print(h4);
Serial.print(” %\t”);
Serial.print(“Temperature 4: “);
Serial.print(t4);
Serial.println(” *C”);
}
if (isnan(t5) || isnan(h5)) {
Serial.println(“Failed to read from DHT #5”);
} else {
Serial.print(“Humidity 5: “);
Serial.print(h5);
Serial.print(” %\t”);
Serial.print(“Temperature 5: “);
Serial.print(t5);
Serial.println(” *C”);
}
Serial.println();
// 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) {
// send a standard http response 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: 5”); // refresh the page automatically every 5 sec
client.println();
client.println("");
client.println("");
client.print(“H1= “);
client.print(h1);
client.print(” %\t”);
client.print(“T1= “);
client.print(t1);
client.println(”
”);
client.print(“H2= “);
client.print(h2);
client.print(” %\t”);
client.print(“T2= “);
client.print(t2);
client.println(”
”);
client.print(“H3= “);
client.print(h3);
client.print(” %\t”);
client.print(“T3= “);
client.print(t3);
client.println(”
”);
client.print(“H4= “);
client.print(h4);
client.print(” %\t”);
client.print(“T4= “);
client.print(t4);
client.println(”
”);
client.print(“H5= “);
client.print(h5);
client.print(” %\t”);
client.print(“T5= “);
client.print(t5);
client.println(”
”);
client.println("");
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”);
}
}