GithubHelp home page GithubHelp logo

james-calliope / calliope-dht11_dht22 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alankrantas/pxt-dht11_dht22

0.0 1.0 0.0 75 KB

MakeCode extension for DHT11/DHT22 humidity and temperature sensors

License: MIT License

Makefile 1.31% TypeScript 98.69%

calliope-dht11_dht22's Introduction

BBC micro:bit MakeCode editor extension for DHT11 and DHT22 humidity/temperature sensors

DHT11 and DHT22 are two popular sensors among microcontroller users, especially the cheap DHT11s. DHT22s cost more but have better data resolution.

My codes are based on MonadnockSystems/pxt-dht11 but modified the pin pull-up time calculating method based on some Arduino examples with several additional features. The extension also support DHT22s.

To import this extension, go to Advanced -> +Extension and enter "DHT11" or "DHT22" in the search box, or copy/paste https://github.com/alankrantas/pxt-DHT11_DHT22 into the search box. Press enter and click the extension.

img_0001

img_0002

Blocks

The extension can be used for DHT11 or DHT22 sensors. Use the first block to select module type and read data (it is recommended to wait between queries; at least 1 second for DHT11 and 2 seconds for DHT22), then use the second one to read either humidity level (%) or temperature (celsius).

This extension also verifies checksum from sensors. If the checksum is wrong, you'll get -999 for both temperature and humidity readings, and "Last query successful?" block would return false.

1

microbit-screenshot

basic.forever(function () {
    DHT11_DHT22.queryData(
    DHTtype.DHT11,
    DigitalPin.P0,
    true,
    false,
    true
    )
    basic.showString("T: " + DHT11_DHT22.readData(dataType.temperature) + " *C")
})

You can also choose to output data via serial port:

DHT11 query completed in 25848 microseconds                   
Checksum ok                   
Humidity: 77 %                
Temperature: 22.01 *C         
----------------------------------------
DHT11 query completed in 25849 microseconds                   
Checksum ok                   
Humidity: 77 %                
Temperature: 22.01 *C         
----------------------------------------
DHT11 query completed in 25838 microseconds                   
Checksum ok                   
Humidity: 77 %                
Temperature: 22 *C            
----------------------------------------
DHT11 query completed in 25861 microseconds                   
Checksum ok                   
Humidity: 77 %                
Temperature: 22 *C            
----------------------------------------
DHT22 query completed in 26162 microseconds                   
Checksum ok                   
Humidity: 74.500000000000001 %
Temperature: 21.899999999999999 *C                            
----------------------------------------
DHT22 query completed in 26162 microseconds                   
Checksum ok                   
Humidity: 74.299999999999997 %
Temperature: 21.899999999999999 *C                            
----------------------------------------
DHT22 query completed in 26120 microseconds                   
Checksum ok                   
Humidity: 74.099999999999992 %
Temperature: 21.899999999999999 *C                            
----------------------------------------
DHT22 query completed in 26048 microseconds                   
Checksum ok                   
Humidity: 74 %                
Temperature: 21.899999999999999 *C                            
----------------------------------------

Sensor versions and wiring

There are two types of DHT11/DHT22s, one without PCB boards and have 4 pins; another have PCB boards, built-in pull up resistors and only 3 pins. Personally I would recommend you to use PCB versions.

For the PCB version it's easy: Vcc (+) to 3.3V or 5V (both works), GND (-) to GND, Data (out) to any GPIO pins you like.

dht11-pinout-for-three-pin-and-four-pin-types-2

Be noted that some PCB version sensors may have different order of pins.

If you are using the 4-pin version, you'll need to add a resistor (in my test 220 Ω - 10 KΩ works under 3.3V; above that the sensor won't response) between Vcc and Data to pull up the voltage of the data pin. Or you can simply use the pull up option in the query block - the micro:bit has internal resistors about 12-13 KΩ.

The third pin on the 4-pin sensor from the left is not used.

untitled sketch_bb

If a hardware pull-up resistor already exists, use the internal pull up resistor dosen't seems to affect the results.

Powering up issue

The DHT modlue might not be responsive if you query it immediatly after powering up. In this case you'll need to manually restart micro:bit while connecting to power, or add a small delay (like basic.pause(100)) in "on start" block.

License

MIT

Supported targets

  • for PXT/microbit (The metadata above is needed for package search.)

calliope-dht11_dht22's People

Contributors

alankrantas avatar james-calliope avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.