"Espruino" No.14 temperature and humidity sensor DHT11

Source: Internet
Author: User

http://blog.csdn.net/qwert1213131/article/details/35828873

This article belongs to the individual understanding, the ability is limited, the mistake is unavoidable, also looks correct.

"Little Fish has a little electricity."

"Espruino Chinese Community"

In section 10th, a DS18B20 temperature sensor is introduced, which introduces a sensor DHT11 that detects temperature and humidity simultaneously, detects a temperature range 0~50℃ (precision is +/-1℃), and humidity 20~90% (precision +-+ 4%). DHT11 sometimes do not recognize the trigger pulse, or occasionally do not read the correct data, so use the checksum mechanism to verify the data received. returns {"Temp":-1, "RH":-1} If 20 consecutive failures cannot be answered or the checksum fails. It is therefore recommended that the returned data be checked again.

Communication with the Ds18b20 consistent with the use of one-way mode, power supply range of 3-5.5v, the board using 3.3V power supply, communication lines connected to the pin C9, recommended in the communication line length of 20 meters when the use of 5K pull resistance, greater than 20 meters, please choose the appropriate pull resistance according to the actual situation.

For DHT11 already have a ready-made module file can be called directly, the operation is as follows:

var DHT = require ("DHT11"). Connect (C11);
Dht.read (function (a) {Console.log ("Temp:" +a.temp.tostring () + "RH:" +a.rh.tostring ());});

After entering the above code in the right area of the Espruino Web IDE, the temperature and humidity will be displayed on the left side, and the SetInterval function can be used to obtain the temperature and humidity periodically.

We can also synthesize the contents of the LCD section, display the value on the LCD, the code below, video address:

Spi1.setup ({sck:b3, mosi:b5, Order: "LSB", baud:2000000});
var g = require ("MEMORYLCD"). Connect (SPI1, b4/*scs*/, c12/*extcomin*/,128/*width*/, 128/*height*/); 
G.clear ()//clear buffer

var DHT = require ("DHT11"). Connect (C9);
Temp= "";
Rh= "";

SetInterval (function () {
  dht.read (function (a) {Temp=a.temp;rh=a.rh;console.log (temp+ "" +RH);});
  if (temp!==-1) {
    led1.set (1);
    G.setfontvector (a);
    G.fillrect (0, 0, 128-1, 60-1);
    G.setcolor (0,0,0);
    g.DrawString ("DHT11", 4,12);
    G.setfontvector ();
    G.setcolor (1,1,1);
    g.DrawString ("Temp:" +temp);
    g.DrawString ("RH:" +RH);
    G.flip ();
    G.clear ();
  }
  else{
    Led1.reset ();
  }

},1000);
Save ();


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.