David Granath (Devve)
    • 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
    # Babymonitor David Granath / dg222px In this project I created a babymonitor which is able to display brightness, temperature and if it's noisy. The system uses a microcontroller, sensors, MQTT-broker and lastly Adafruit Dashboard for visualisation of the data. Adafruit collects data from the broker which collects data from the microcontroller via Wifi. It should take about 4 hours to perform this tutorial. ## Objective I chose to create a babymonitor because it's something that is very useful for anyone that has a baby. With the help of a babymonitor you can monitor the baby and their environment even while they are asleep. The purpose for it is mainly to prevent babies from crying for their parents for a longer period of time but also to check the temperature and brightness of the environment. The data from the system will bring the user some insight to how their baby is doing. ## Material |Component|Purpose|Provider|Cost| | ----- | ----- | ----- | ----- | |Raspberry Pi Pico WH|Main processing unit|[Elektrokit](https://www.electrokit.com/raspberry-pi-pico-wh)|99 kr| |DHT11|Temperature data|[Elektrokit](https://www.electrokit.com/digital-temperatur-och-fuktsensor-dht11)|49 kr| |Photoresistor|Brightness data|[Elektrokit](https://www.electrokit.com/fotomotstand-cds-4-7-kohm)|9.5 kr| |Sound sensor|Sound data|[Elektrokit](https://www.electrokit.com/ljudsensor-analogdigital)|36 kr| |Breadboard|840-point breadboard|[Elektrokit](https://www.electrokit.com/kopplingsdack-840-anslutningar)|69 kr| |1 x 10kΩ resistor|Resistor for photoresistor|[Elektrokit](https://www.electrokit.com/motstand-kolfilm-0.25w-10kohm-10k)|1 kr| |Jumper wires (Male-Male)|Connect components|[Elektrokit](https://www.electrokit.com/labbsladd-20-pin-15cm-hane/hane)|52 kr| |USB Cable (USB-A to Micro-USB)|Connect to Raspberry Pi|[Elektrokit](https://www.electrokit.com/usb-kabel-a-hane-micro-b-5p-hane-1.8m)|39 kr| ||||354,5 kr| ## Computer setup To create the babymonitor I chose the IDE [Thonny](https://thonny.org) because it was very easy use. To be able to start coding you need to install MicroPython which can be done [here](https://www.raspberrypi.com/documentation/microcontrollers/micropython.html). After downloading the file hold the boot button on the Pico while plugging it in to a the computer containing the MicroPython file. It should now be accessable on the devices page. Just put the MicroPython file in it and it will be accessable inside of Thonny by selecting it down to the right where it probablys says "Local Python 3". Click that button and select MicroPython (Raspberry Pi Pico). Now you're able to code and upload it to the Pico by right-clicking a file and select "Upload to /". ## Putting everything together To understand the setup it's necessary to know what the different pins on the Pico does. Please look at this [datasheet](https://datasheets.raspberrypi.com/picow/pico-w-datasheet.pdf). The setup is quite simple due to all the sensors work great with the 3.3 volt that the Pico is able to provide from its 3V3 PIN (PIN 36). But you need to be sure to connect the photoresistor and the DHT11 to an ADC PIN such as PIN 31 and 32. ![image](https://hackmd.io/_uploads/ryArfY2Hle.png) This in an image of how my breadboard looks. ## Platform The platform I chose was [Adafruit I/O](https://io.adafruit.com). I chose Adafruit I/O because it provides a cloud-based service with both a MQTT Broker and a Dashboard. The MQTT Broker is a publish/subscribe system which provides an easy way to collect the data and then send it elsewhere. The Adafruit Dashboard provides an easy and nice way to visualize the data provided by the broker. ## The code The code starts off with trying to connect to the wifi which is done with the help of the network library provided by MicroPython. You can use this library to connect to the wifi like this (the keys library is my folder with sensitive information): ``` import network, machine, keys wlan = network.WLAN() ssid = keys.WIFI_SSID key = keys.WIFI_PASS def connect_wlan(): wlan.active(True) wlan.connect(ssid, key) ``` After connecting to the wifi you can connect to the Adafruit MQTT Broker. I used the [umqtt library](https://github.com/micropython/micropython-lib/blob/master/micropython/umqtt.simple/umqtt/simple.py) for this due to it providing an easy way to connect to the broker. With this library you can use the `MQTTClient()` function which creates a client object that can call the `connect()` function which connects it to the MQTT Broker. It's necessary to make an I/O Adafruit account for this to work: ``` client = MQTTClient(keys.AIO_CLIENT_ID, keys.AIO_SERVER, keys.AIO_PORT, keys.AIO_USER, keys.AIO_KEY) client.connect() ``` The sensors are coded a bit different from one another. But what they do have in common is that's important that you provide the correct Pin when using the Pin library. This is an example of using the Pin library from the machine library: `digitalPin = Pin(22, Pin.IN)` The difference between the sensors is that the photoresistor uses the ADC library, the DHT11 uses the dht library and the sound sensor only uses a digital pin. Due to the sound sensor needing to have some kind of way to prevent false positives (like a quick noise that isn't necessarily a baby crying) I made this code: ``` def is_noisy(): noise_counter = 0 for x in range(20): if(__measure() == 1): noise_counter += 1 time.sleep_ms(50) if(noise_counter >= 10): return 1 else: return 0 ``` This code only returns 1 (True) if at least half of the measurements during a second are returned as true by the digital output of the sound senor. The main loop is a bit tricky to understand due to the previous code that takes a second: ``` #Collect and send data forever (until stopped) while True: #Brightness (Every 37.5 sec, 1.6/min) if(timer%15 == 0): brightness = photoresistor.measure() broker.publish(client, str(brightness), keys.AIO_FEED_BRIGHT) #Temperature (Every 37.5 sec, 1.6/min) if(timer%15 == 0): temp = temperature.measure() broker.publish(client, str(temp), keys.AIO_FEED_TEMP) #Check Microphone (Every 2.5 sec, 24/min) #(Measurement takes 1 second) is_noisy = sounddetector.is_noisy() broker.publish(client, str(is_noisy), keys.AIO_FEED_SOUND) #Limit to 37.5 loops per min (Note that mic takes a sec) time.sleep(1.5) #Add to timer timer = timer + 1 ``` It's coded this way because the sensors data is published to different feeds and have different frequencies. ## Transmitting the data / connectivity Data is sent about 27.2 times per minute, 24/min for the sound sensor and 1.6/min each for the photoresistor and DHT11. I/O Adafruit has a limit of 30 messages/min which is why it's lower than 30. To send this data I used wifi. The transport protcols I used was Adafruit MQTT Broker which I used to provide data for my Adafruit Dashboard. ## Presenting the data The dashboard is built with the help of Adafruit Dashboard. It's able to present the data that is stored up to 30 days in different forms, such as graph and line gauge. This is how the dashboard looks: ![Skärmbild 2025-07-09 231850](https://hackmd.io/_uploads/HkgDY52Beg.png) The amount of data that is saved inside of the broker depends on how often the system is on. If it was on all the time it would save be able to save 27.2 messages per minute. I/O Adafruit clears the feed data 30 days after last entry or if it goes past 2.5 GB storage. ## Finalizing the design This is a picture of the babymonitor: ![Skärmbild 2025-07-10 003741](https://hackmd.io/_uploads/BJW40c2rel.png) The project went good but there is a lot of room for improvement in my opinion. Some improvements that I would like to add in the future are a better sound sensor, notification capabilites, 3D-printed case, a battery and communication via LoRaWAN. Right now the babymonitor is both unsafe for children and not very portable which both are very important aspects of a babymonitor. Here is a [link](https://github.com/Devve2000/babymonitor) to the repository containing all the code that I used for the project.

    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