fae
    • 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
    • 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 Versions and GitHub Sync Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Tutorial on how to build an air quality and temperature sensor #### By Fritiof Andersen Ekvall, fa222xh ###### tags: `IoT,LNU,LoPy4,Pycom` - Table of Content [ToC] ## :memo: Project overview This project describes how to easily create a sensor that monitors the air quality and temperature of your home. This involves some light tinkering and just a pinch of programming. Following this guide will probably take about 2-3 hours but someone with experience could complete the project in under an hour. ### Purpose of project I chose this project because I was curious how the air quality and temperature changes during a nights sleep, does open windows equal less CO2? Does the construction site next to my apartment building whey in? What is the peak temperature when trying to sleep during a heatwave? ### Material used - LoPy4: Micropython-programmable microcontroller - Expansion Board: Allows the LoPy4 to connect with USB and pins - Breadboard: Base for connections - Jumpwire: Connect different items/pins - MCP9700 TO-92: Measure temperature (-40°C to 125°C) - Joy-it CCS811 Sensor: Measure CO2 and VOC levels | Material | Where to buy | | ----------------- |:----------------------- | | LNU IoT bundle 1024kr | [:link:][Electrokit] | | CSS811 sensor 181,09kr | [:link:][CDON] | [Electrokit]: https://www.electrokit.com/produkt/lnu-1dt305-tillampad-iot-lopy4-and-sensors-bundle/ [CDON]: https://b2c.cdon.se/hushallsapparater/joy-it-sen-ccs811v1-sensormodul-p47786925? [Book-mode]: https://hackmd.io/c/tutorials/%2Fs%2Fhow-to-create-book [Slide-mode]: https://hackmd.io/c/tutorials/%2Fs%2Fhow-to-create-slide-deck [Share-Publish]: https://hackmd.io/c/tutorials/%2Fs%2Fhow-to-publish-note The LoPy4 has been the base for this project as one of the recommended boards for this course it has a lot of capabilities, especially useful for IoT implementations. ### Computer setup As someone without that much experience with Python I went with Atom as my IDE (since it's the same our teacher uses). Installing the pymakr package was really easy, just go to Packages-> search for pymakr-> Click install-> Done, now you have a pybytes REPL in Atom! There also needs to be a installation of python on your computer. I had previously installed Python 3.8 which can be found here: [:link:][Python]. Another alternative would be to install node.js which can be found here: [:link:][NodeJS] Pycom provides an easy tool to change firmware of your LoPy4 here: [:link:][Firmware] download the installation file for your OS, install and run! Now you choose between several firmwares and if you want to do an erase of the system before (recommended) under advanced settings. To run code with Atom and your LoPy4 connected to the computer you have to make sure that your latest/current project is selected and press the :arrow_forward: button. A great alternative is to setup your device on the pybytes website, especially if you want to communicate with the LoPy4 without it being connected to your computer. [:link:][Pybytes]Here you can sign up, set up a network connection over WiFi, LoRa, Sigfox or LTE (if you have a FiPy). It also let's you execute code over an online pybytes REPL. [Python]: https://www.python.org/downloads/ [NodeJS]:https://nodejs.org/en/ [Firmware]:https://docs.pycom.io/gettingstarted/installation/firmwaretool/ [Pybytes]: https://pybytes.pycom.io/ ### Putting the sensor setup together ![](https://i.imgur.com/7OLR5zC.png) Both sensors used here like 3.3V so no resistors needed. This is not the most space effective way to do this setup, there is a possiblity to optimize several connections with male-female cables, really the only ones that doesn't have directly one counterpart is the 3.3V and the ground. A rough estimate of the power consumption: LoPy4's 3.3V pin can give out a maximum of 1.2A | Component | Power draw | | ----------------- |:----------------------- | | CCS811* | 30mA | | MCP9700 TO-92 | 6 μA | | Total | 30,06mA | **The CCS811 power draw is from a different brand of CCS811* [:link:](https://www.electrokit.com/produkt/luftkvalitetssensor-ccs811-monterad-pa-kort/) We're nowhere close to the LoPy4's maximum. If you want to test something with a regular LED, a resistor is a good idea otherwise they may get burnt. If we use the 3.3V pin and want to use a LED with a regular current of 25mA the calculation goes like this: $$ {V \over I}=R $$ $$ {3.3 \over 0.025}=132 Ω $$ You want to have atleast a 132Ω resistor connected aswell. ### Platform Pybytes online platform let's me keep everything in the cloud, whilst having quickly readable results and an edit is just a click away. It's ease of integration from the Atom pybytes is a big plus (it works the same way), it's free of charge and works fast. ### The Code For the CCS811 sensor I'm using the course provided library: [:link:][CCS811]. For the temperature sensor I searched around a bit and found this great guide on how to get it started: [:link:][TMP] [CCS811]: https://github.com/iot-lnu/applied-iot-20/tree/master/sensor-examples/ccs811-air-quality [TMP]:https://www.losant.com/blog/how-to-read-the-tmp36-temperature-sensor-with-pycom-and-sigfox - Code: ```python=1 import pycom import machine from machine import I2C import time #... #CCS811 library #CCS811 library #CCS811 library #CCS811 library #... ccs = CCS811(i2c=i2c,addr=90) # Import values from the CCS811 lib time.sleep(1) # Just to get it some slack starting up adc = machine.ADC() # Get the raw data from the temperature sensor apin = adc.channel(pin='P16') while True: ccs.data_ready() # Make a reading time.sleep(30) # Dictates how often readings are done and sent co2 = ccs.eCO2 voc = ccs.tVOC millivolts = apin.voltage() degC = (millivolts - 500.0) / 10.0 # Calculate the temperature pybytes.send_signal(1, degC) # Send the data to pybytes pybytes.send_signal(2, co2) pybytes.send_signal(3, voc) ``` The first part of my main file is the CCS811 library. It's also possible to import the library from a separate file. ### Connectivity The data is sent every 30 seconds over WiFi. Pybytes.send_signal is used for transmitting one signal for each type of measurment with the MQTT protocol. The LoPy4 is plugged in the wall with an old android charger in my bedroom, neither power nor range is a problem so I opted for a bit more precision with more data points sent (every 30 seconds). WiFi is a more power hungry alternative but the close proximity to my home router ensures a good signal, while keeping the setup stationary (and connected to a wall outlet) the power doesn't really matter and a LoRa/Sigfox signal might be hampered by apartement buildings close by aswell as being in the outskirts of town. ### Presenting data ![](https://i.imgur.com/H9jFmYa.png) The pybytes database is easily implemented when using their platform. The data is saved for one month and it's saved as often as it's sent: every 30 seconds. They offer several different options for the dashboard, for each signal you can create different windows, different kinds of graphs, choose size of pull (how many points of data should be used) and it's all free! Triggers can be setup, I have made it so I get a notification if no data is received for 30 minutes. ### Finalizing the design ![](https://i.imgur.com/IInBsX3.jpg) The little sensor array is hidden under my old rocking chair in my bedroom. This isn't really a permanent solution (gathering dust and might be knocked around by something) but it works as a prototype. When I have access to a 3D printer a case might be in order! ![](https://i.imgur.com/0R82rIA.png) *Pybytes offer a function **Limit** that increases readability and also makes averages of the data points available. This will be used but for comparison the exact temperature data points is shown here above.* ![](https://i.imgur.com/SOilwgi.png) *Here is a look at 25 hours of data* ![](https://i.imgur.com/6Lw2m4k.png) *Here is a look at several days of data.* The aggressive spikes in the data seem unlikely to represent real world data very well, it's possible energy fluctuations from the grid might cause some of this. The CCS811 is also not the best CO2 sensor out there, for more precise numbers a sensor upgrade might help. I think this worked out quite well considering when this project started out I had no clue what Fredrick referred to when he said that we were going to choose a platform (my mind were thinking of game platforms and platform games). But I did have some experience of both programming and tinkering with SBCs (single-board computers). I did start a webhooks page because I wanted to explore more automation and trigger possibilities, for their custom action (based on incoming data) they wanted a fee but I wanted to try this without recurring expenses. Using grafana and docker seemed to be the stylish option but wasn't on the cloud which would require my desktop to act as a server 24/7 (not a practial choice). I have thought of several options for the dashboard and such. Ubidots might be a good free alternative. The idea of running a raspberry pi as the server for a docker/grafana solution is also interesting. To automate something more than a notification such as a fan or a warning for high CO2 might also be a good addition in the future. The CCS811 is also not the best CO2 sensor out there, for more precise numbers such an upgrade might help aswell. This project leaves me with a feeling of eagerness to explore the seemingly endless possibilites with IoT!

    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