In this lesson, we will show you how to get DHT11 data remotely, we will use Osoyoo Mega-IoT Shield to connect DHT11 sensor and MEGA2560 MCU board. OSOYOO Advanced Board for Arduino MEGA2560 can work as a web server. Remote browser can access this web server and get the data of DHT11 connected to D2 pin of MEGA2560.
First please plug OSOYOO MEGA-IoT Extension Board into OSOYOO Advanced Board for Arduino MEGA2560:
Then connect the DH11 Temp & Hum Sensor to the D2 port of the OSOYOO MEGA-IoT Extension Board with a 3-pin PnP cable as below: (Jumper Cap should connect ESP8266 RX with A8, TX with A9):
Step 1 Install latest IDE (If you have IDE version after 1.1.16, please skip this step)
Download IDE from https://www.arduino.cc/en/software , then install the software.
Step2 WifiEsp Library Installation (if you have installed WifiESP library, please skip this step)
OSOYOO MEGA-IoT extension TX/RX pin to OSOYOO Advanced Board for Arduino MEGA2560 A9/A8 pin by default. So in sketch code, we need use Software Serial Port to communicate with ESP8266 (set A9 as TX and A8 as RX in softwareserial object).
To use this wifi shield in IDE, we need download WiFiEsp-master library from following link:
https://osoyoo.com/driver/WiFiEsp-master.zip
You need go to IDE ->Sketch ->Include Library ->Add ,Zip library to load above zip files into IDE.
To use the DHT11 sensor here, you also need to install the DHT11 library as above operations.
Step 3 After installing above libraries, please download the main code from following link, unzip it, you will see a folder called “smarthome-lesson7”:
https://osoyoo.com/driver/smarthome/7/smarthome_lesson7.zip
Step 4 After above operations are completed, connect OSOYOO MEGA2560 Board to PC with USB cable.
Step 5 IDE: Choose corresponding board type and port type for you project .
Step 6 IDE: Click file – Open, then choose code “smarthome-lesson7.ino” in the folder, load up the sketch onto your board.
Note: In the sketch, find line 24,25 as following:
char ssid[] = "******"; // your network SSID (name) char pass[] = "******"; // your network password
please replace the ****** with your correct wifi SSID and password, otherwise your project can not connect to Internet.
After loading the sketch to OSOYOO Advanced Board for Arduino MEGA2560 , open the serial monitor in the upper-right corner of IDE, you will see following result:
From the serial monitor , you can see the IP address of your MEGA2560 board in the read circle (in above picture, 192.168.50.8).
Then use your browser to visit the website http://mega2560-ip-address (in above case, http://192.168.50.8), you will see following result:
From here, you can see a simple web server that shows the temperature and humidity data of the DHT11 sensor. The web page will be automatically refreshed each 20 seconds. Wait a minute, you may see the following data on the web page:
DownLoad Url osoyoo.com
You must be logged in to post a comment.
Hi, my name is Antonio and is impossible to print the page. I connect with the server (client.connected=true) but I don’t get “Sending response”
You can clear the browser cache, restart the browser and try again
Is it hard to change to Fahrenheit? Anyone know where that can be changed in the library?
I think you can follow below code
1 double Fahrenheit(double celsius)
2 {
3 return 1.8 * celsius + 32; //Convert degrees Celsius to Fahrenheit
4 }
5
6 double Kelvin(double celsius)
7 {
8 return celsius + 273.15; //Conversion of Celsius temperature to Kelvin temperature
9 }
10
11
12
13 double dewPoint(double celsius, double humidity)
14 {
15 double A0= 373.15/(273.15 + celsius);
16 double SUM = -7.90298 * (A0-1);
17 SUM += 5.02808 * log10(A0);
18 SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
19 SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
20 SUM += log10(1013.246);
21 double VP = pow(10, SUM-3) * humidity;
22 double T = log(VP/0.61078); // temp var
23 return (241.88 * T) / (17.558-T);
24 }
25
26
27
28 double dewPointFast(double celsius, double humidity)
29 {
30 double a = 17.271;
31 double b = 237.7;
32 double temp = (a * celsius) / (b + celsius) + log(humidity/100);
33 double Td = (b * temp) / (a – temp);
34 return Td;
35 }
36
37 #include
38 dht11 DHT11;
39 #define DHT11PIN 2
40
41 void setup()
42 {
43 Serial.begin(9600);
44 Serial.println(“DHT11 TEST PROGRAM “);
45 Serial.print(“LIBRARY VERSION: “);
46 Serial.println(DHT11LIB_VERSION);
47 Serial.println();
48 }
49
50 void loop()
51 {
52 Serial.println(“\n”);
53 int chk = DHT11.read(DHT11PIN);
54 Serial.print(“Read sensor: “);
55 switch (chk)
56 {
57 case DHTLIB_OK:
58 Serial.println(“OK”);
59 break;
60 case DHTLIB_ERROR_CHECKSUM:
61 Serial.println(“Checksum error”);
62 break;
63 case DHTLIB_ERROR_TIMEOUT:
64 Serial.println(“Time out error”);
65 break;
66 default:
67 Serial.println(“Unknown error”);
68 break;
69 }
70
71 Serial.print(“Humidity (%): “);
72 Serial.println((float)DHT11.humidity, 2);
73
74 Serial.print(“Temperature (oC): “);
75 Serial.println((float)DHT11.temperature, 2);
76
77 Serial.print(“Temperature (oF): “);
78 Serial.println(Fahrenheit(DHT11.temperature), 2);
79
80 Serial.print(“Temperature (K): “);
81 Serial.println(Kelvin(DHT11.temperature), 2);
82
83 Serial.print(“Dew Point (oC): “);
84 Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
85
86 Serial.print(“Dew PointFast (oC): “);
87 Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
88
89 delay(2000);
90 }
MY DHT11 sensor shows 0.0% of humidity and 0 of temperature, is it normal?
The source code supplied in smarthome_lesson7 does not run. It appears to be using a very old reference to the DHT class. However, if you download the DHT Sensor Library from here (https://www.arduino.cc/reference/en/libraries/dht-sensor-library/), the two projects under the examples directory work well. There are two DHT classes, one is called DHT and the other is DHT_Universal. Both work. So then I went back and modified my smarthome_lesson7 with the code from the DHTTest example and now it is working.