Arduino+esp8266wifi (2)--dht11 temperature and humidity data automatically uploaded

Source: Internet
Author: User

after the module test, make sure the ESP8266 is working properly and start connecting with Arduino to upload the data detected by the DHT11 temperature and humidity sensor to the monitoring platform. Prior to understand the platform has Yeelink and thingspeak, the principle should be the same, I choose Thingspeak here, we can try Yeelink, welcome to provide learning to share.

put the results first. Welcome visit: https://thingspeak.com/channels/296658


first, pre-preparation Hardware:

Arduino MCU (I use the nano here, the other is the same)
esp8266 Module
DHT11 temperature and humidity sensor Software:

1. Registered account on Thingspeak website: https://thingspeak.com/

2. Add Device: Click Channels–>my channels–>new Channel
Build Your own equipment

3. Set the sensor properties, the temperature and humidity sensor in this example two data so select two areas, tick make public easy to share links, click Save

4. Click on "API Keys" in the sensor management interface to view the Write API Key, which will be used later.

Second, the circuit connection ESP8266 module:

Wiring method The same as the TTL serial connection, just replaced by the Arduino MCU. (It is recommended that the ESP8266 can be powered separately 3.3V, the microcontroller current is too weak may affect the module to work properly) DHT11:

pin1–> Single-chip microcomputer
pin2–> Single Chip microcomputer digital port (I chose 4 pins here)
pin3–> floating without tube
pin4–> Grounding
It is recommended that the PIN2 port be connected with a 5K ohm resistor and then VCC to do the pull-up resistor

I drew a simple schematic, the circuit is very simple (but I still draw for more than 10 minutes OH)

III. Preparation of the procedure

#include <stdlib.h> #include <SoftwareSerial.h> #include <dht.h> DHT DHT;  const int PIN = 4; The DHT11 data pin will be connected to the Arduino pin 4 #define SSID "* * *"//wifi name #define PASS "* * *"//wifi password #define IP "184.106.1 53.149 "//connection thingspeak.com server String GET =" get/update?key=**** "; Enter the previously noted API Softwareserial monitor (10, 11);
    Define soft serial Rx, TX//Initialize-----------------------------------------void Setup () {monitor.begin (9600);
    Serial.begin (9600);        Senddebug ("at");
    Instruction test delay (5000);
        if (Serial.find ("OK"))//Receive instructions return OK {monitor.println ("Received:ok");
    Connectwifi ();  }}//main loop-----------------------------------------void Loop () {DHT.READ11 (PIN);    Read DHT11 sensor//serial.print (dht.humidity,1);  
    Serial Printing Humidity//serial.print (", \ T");   Serial.println (dht.temperature,1);
    Print temperature float temph = dht.humidity;
    float tempt = dht.temperature;
    Char buffer[10]; String temph = DtostrF (temph, 4, 1, buffer);    
    String tempt = DTOSTRF (tempt, 4, 1, buffer);
    Updatetemp (temph,tempt);
Delay (60000);
    } void Updatetemp (string temph,string tempt) {string cmd = "at+cipstart=\" tcp\ ", \" ";
    cmd + = IP;
    cmd + = "\", 80 ";                         Senddebug (CMD);
    Send instruction, link server delay (2000);
        if (Serial.find ("Error")) {Monitor.print ("Received:error");
    Return        } cmd = GET + "&field1=" + temph + "&field2=" + tempt + "\ r \ n";
    Record the value of T and H Serial.print ("at+cipsend=");
    Serial.println (Cmd.length ());
        if (Serial.find (">")) {Monitor.print (">");
        Monitor.print (CMD);
    Serial.print (CMD);
    } else {senddebug ("at+cipclose");
    } if (Serial.find ("OK")) {monitor.println ("Received:ok");
    } else {monitor.println ("Received:error");
    }} void Senddebug (String cmd) {monitor.print ("SEND:");Monitor.println (CMD);
Serial.println (CMD);
    } Boolean Connectwifi () {serial.println ("at+cipmux=0");
    Serial.println ("at+cwmode=1");
    Delay (2000);
    String cmd= "At+cwjap=\" ";
    Cmd+=ssid;
    cmd+= "\", \ "";
    Cmd+=pass;
    cmd+= "\" ";
    Senddebug (CMD);
    Delay (5000);
        if (Serial.find ("OK")) {monitor.println ("Received:ok");
    return true;
        }else {monitor.println ("Received:error");
    return false; }
}
library file Download:

Soft Serial library file (click to download)

DHT11 Sensor library file (click to download) Iv. Results

The circuit works normally and the data is measured normally.

Connect WiFi OK

data transfer is normal and updated in real time

The circuit has been working continuously for several days without appearing a problem, very powerful. View received data on the monitoring site: https://thingspeak.com/channels/296658

Circuit:

The green board above is the one I welded the 5V down to 3.3V circuit, convenient to meet the different voltage requirements. v. Exclusion of problems

1. If there is a problem with the circuit connection, does the Rx,tx

2. Program writing (directly with my program should not be a problem), note that the burning will be rx,tx first unplug, burning after the success immediately connected, observe the Arduino IDE monitoring window

3.AT Instruction module is normal when testing

4. Whether the WiFi connection is successful, the password is correct (can be connected to the hotspot, to see if there is new device access)

5. Module power supply PROBLEM: We recommend the ESP5266 module separately for 3.3V power

6. Module baud rate problem, using 15200 or 9600 (I'm using 9600)

7. Each time the module sends data, the blue light will flash. This morning saw a long time did not flash (or have been flashing), guess is the data upload estimate interrupted, check the monitoring page real data update to four o'clock in the morning interrupted, in fact, just the problem of wiring, in the bread board line, DuPont Line permanent may also loose, there are problems we can also check the wiring is loose You are welcome to continue to provide problem solving solutions, exchange learning together. WiFi Series prev: Arduino+esp8266wifi (1)--module test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.