ap223pt
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: 'Humidity and temperature sensoring using LoPy4 and DHT11' disqus: hackmd --- Humidity and temperature monitoring using LoPy4 and DHT11. = #### Anton Pettersson - ap223pt ### Overview This work is aimed to give a detailed description of how the LoPy4 quadruple bearer board and the DHT11 sensor can be used to monitor temperature and humidity and display these environmental factors on a Pybytes dashboard. To transfer the data a WiFi connection will be used. This methodology can be applied to other projects where similar sensors are used. The aim is to describe the setup of the LoPy4 and the sensor, how the data is collected and packaged, and how the data is displayed for the end user. To do this project it should roughly take about eight hours from start to finish. ## Table of Contents [TOC] ## Objective This project was chosen because IoT solutions are very usable in hard-to-reach places, for example the foundation of a house. The idea for the device is to be used in a crawl-space foundation where moisture is a commonly occurring problem and therefore the humidity is of interest. The purpose of this device is to monitor the temperature and relative humidity using the DHT11 sensor. The temperature is logged as well because to sensor has the ability to do so, but will not serve any other purpose than merely an informative one. Since both the temperature and relative humidity is logged one can observe the phenomenon that if the temperature decreases, the relative humidity increases since the air does not need as much moisture to become saturated. These kinds of fluctuations are expected and unavoidable and should be relatively small. If the relative humidity would increase a lot, something unwanted might have happened, there could be water standing the crawl space for example. If this following scenario was to occur, the user will be notified: + The relative humidity exceeds a threshold value (>55%) This value was suggested as a general rule regarding crawl space foundations but is arbitrary in terms of how the project is executed. This project will hopefully lead to insights into how IoT solutions can be used to monitor sensor data and automate otherwise tedious tasks such as measuring the humidity and temperature in a house foundation to avoid moisture-related problems. ## Material Since the hardware used in this project were bought in a bundle, individual prices for the different products can not be stated. The following prices were estimated using listed prices, (from the Pycom webshop and RS Components Sweden), for the products themselves without taking shipping into consideration. The hardware below is what is required to make this project. | Component | Function | Retail price [SEK] | | --------------------------- |:-------------------------------------------- | ------------------ | | Pycom LoPy4 | Microcontroller | 367 | | Expansion board | Enables multiple physical connections to LoPy4 | 168 | | DHT11 sensor | Temperature and realtive humidity measuring | 52 | | Breadboard and jumper wires | Connection between expansion board and DHT11 | 69 | | | **Sum**: |706 All hardware for this project was purchased at www.electrokit.com/, at a total cost of 1339 SEK, but this bundle included several components which are not necessary for this project. Since an open LoRa network was not in range where this project was carried out, a simpler microcontroller than the LoPy4 could have been used, for example the WiPy3 from Pycom as well. This device does not feature the ability to connect to LoRa but is cheaper and choosing this would have reduced the total price to approximately 547 SEK instead of the previously stated 706 SEK. The LoRa antenna is added as a safety precaution but is not necessary in this project, therefore it is not included in the table of components. An image of all the components in shown below in section [Results and discussion](https://hackmd.io/sT83MFubRmKE7YYqZ9I_9w?both#Results-and-discussion). ## Computer setup **Operating system**: macOS **IDE**: Atom with Pymakr plugin **Development board** LoPy4 **Expansion board version** 3.0 This chapter aims to describe the software setup for this specific setup. Some steps are different if the expansion board is an older version, or another operating system is used. In these cases the [Pycom documentation](https://docs.pycom.io/gettingstarted/) is highly recommended. This guide aims to summarize the essential steps to get started for this particular setup. 1. Connect LoPy to expansion board such that the text (*Pycom*) on both units are oriented the same way. 2. Connect a LoRa antenna to the 868MHz/915MHz (LoRa & Sigfox) port. Not necessary for this project but a good safety precaution since a lack of this antenna might lead to damage on the device if LoRa or Sigfox is tried. 3. Update firmware on the LoPy following the [firmware update](https://docs.pycom.io/gettingstarted/installation/firmwaretool/)-section in the documentation, first downloading the update tool for macOS. Nothing was changed in the installer, meaning these steps were very straightforward. 4. Install IDE and Pymakr plugin following [Atom](https://docs.pycom.io/pymakr/installation/atom/)-section in the documentation. 5. Connect the device using a USB cable, if Pymakr does not automatically connect, click on *connect device* and then on your device. At this stage three arrows should be showing (>>>) indicating that the Pycom device is connected and up and running. The next step is now to write and upload code to the device. This is done by creating a project in Atom and writing a Python file and pressing upload to the device in the Pymakr interface. ## Construction (putting everything together) The sensor was connected according to the following scheme: ![](https://i.imgur.com/b8RQ65x.png) Where the left pin on the sensor is the signal out (S), middle is the voltage in (+) and right is the ground (-). The image was constructed taking images from the [Pycom website](https://pycom.io/product/expansion-board-3-0/), and a free to use image of the [DHT11](https://freesvg.org/temperature-and-humidity-sensor) licensed under the public domain. Since this sensor features a built in 1 k$\Omega$ pull up resistor no other resistor has to be added. This is used because the DHT11 sends digital signals and this resistor helps define the high/low state. According to the [data sheet](https://www.electrokit.com/uploads/productfile/41015/User_guide.pdf) supplied with the sensors, the sensor can operate at a current from 3.3 V to 5.5 V. Since the voltage output on the pin used (*3V3*) is on the lower end of the spectrum, long cable lengths are to be avoided to avoid risking line voltage drops potentially leading to errors in measurement. Currently the device is powered through a USB cable. This setup is only to be used for development and would not be suited to be used in production for multiple reasons. The components are quite expensive, the setup takes a bit of time and the device is not in any way shielded. ## Platform During this project the Pybytes platform was used because the integration was very simple and it was available without cost since the development board was bought from Pycom. Few lines of code had to be added and the data steamed seemingly without errors. This platform simply shows the temperature and humidity values plotted over time. In the future a more developed platform could be used, for example Google cloud, which is free up to a 250 MB/month data limit. For users familiar with MATLAB, their platform Thingspeak might be an interesting alternative. This platform should make it fairly simple to analyze data, and is also free up to a data limit of 8200 messages per day. ## MicroPython code ```python= import time from machine import Pin from dht import DHT # https://github.com/JurassicPork/DHT_PyCom th = DHT(Pin('P23', mode=Pin.OPEN_DRAIN), 0) # Type 0 = dht11 time.sleep(2) while True: result = th.read() #reads temperature and humidity values while not result.is_valid(): time.sleep(.5) result = th.read() if result.humidity > 55: pybytes.send_signal(3,1) #flag if relative humidity > 55% pybytes.send_signal(1,result.temperature) #sends data to Pybytes pybytes.send_signal(2,result.humidity) time.sleep(5) ``` > Based on: https://github.com/iot-lnu/applied-iot-20/tree/master/sensor-examples/DHT11-22 > The code is built mainly using the code found at the Github repository with some minor changes to signal if the humidity exceeds the threshold value. Basically, it import the modules stated in code row 1-3, where the *dht* module is used to read the sensor in question and output the readings as integer values that can be uploaded to Pybytes. The loop from row 8-18 implements this functionality of the module and sends the data using the function described in the following chapter. The device then sleeps for five seconds before restarting the loop. This value could be set much higher for the application but works well in development purposes. ## Data transmission and connectivity **Data update rate:** Every five seconds **Wireless protocol:** WiFi **Transport protocol:** None, however the terminal writes the following: `Connected to MQTT mqtt.pybytes.pycom.io` when connecting the LoPy4, suggesting that MQTT is used by the pybytes.send-function described below, which seems reasonable since it is a lightweight connectivity protocol, commonly used in IoT applications. The data is transmitted to Pybytes using the following function ``` pybytes.send_signal(signalNumber, value)) ``` which is part of the [Pybytes library](https://docs.pycom.io/pybytes/api/send_signal/) and is used to send data values labeled with a signal number. Since the data is transferred over WiFi, the data does not need to be manipulated in any way which would be the case if for example LoRa was used. WiFi was chosen because no open LoRa network, for example [TTN](https://www.thethingsnetwork.org) was in range. If a LoRa network would have been in range this would have probably been the wireless protocol of choice, since it is less power consuming to use than WiFi. ## Data presentation **Dashboard:** Pybytes built in. **Data save rate:** Same rate as the data is uploaded, every five seconds. **Data preservation time:** One month. Image of the dashboard: ![](https://i.imgur.com/n9AGSTi.png) The dashboard was built following the [Visualise data from your device](https://docs.pycom.io/pybytes/dashboard/)-guide in the Pycom documentation, where the main steps are: 1. Define signal numbers and what they represent in Signals tab under *Devices*: + Signal 1 - Temperature - °C + Signal 2 - Relative humidity - % + Signal 3 - Warning - no unit 2. Click on the "signal card", *define new display*-button, select type of display and click *create*. Then click *edit* on the widget and click *add the widget to the dashboard*. 3. Edit the position of the widgets on the dashboard to your prefered setup. The first two signals are self-explanatory, but the third signal is used to signal the user if the threshold value of 55% relative humidity has been exceeded (the value 1 is sent out). There are so called alert functions on the Pybytes site under construction and these could perhaps be used in the future to notify the user instead of using a third signal. ## Results and discussion (finalizing the design) ![](https://i.imgur.com/2SuamPj.jpg) This image shows what the final set up looks like for this project. The different components are built into a cardboard box just to keep everything in place and make the unit somewhat transportable. The objective of this project was to monitor the temperature and relative humidity using the DHT11 sensor, and notify the user if the relative humidity exceeds a threshold value of 55%. This purpose is fulfilled and for this the Pybytes website works well. The setup is relatively easy when using Pybytes which is an advantage over other platforms. ### Futher development Since all the components have not been delivered when this report is being written there are some steps that have not been able to be done yet. These are the following: + Build a nicer looking case for the unit, perhaps 3D-print one using the [linked models](https://github.com/iot-lnu/applied-iot-20/tree/master/3D-printing-models). + Implement Pybytes alert when the threshold value is exceeded. + Use another power source than an USB-cable from a computer. + If a battery is used: + Reduce the amount of data being sent from the unit to save power. + Create an *alert* on Pybytes to notify if the power level decreases below a certain level. ### Suggested improvements for future project If the project was to be done again some changes would have been done: + Either use LoRa, or swap the LoPy to a cheaper development board. + Use a more precise sensor, for example the DHT22 instead. + Set up a The Things Network gateway to be able to use LoRa.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully