Improving my home-office environment with noise detection
Tags: homeoffice, microbit, python, health
Published: 2021-02-02 20:31:32

---
title: Improving my home-office environment with noise detection
published: true
description: How I improved my home office environment detecting when I speak too loud. 
tags: HomeOffice, microbit, python, health
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/3aexlns4evvw76bj26of.jpg
---

# TL;DR
I used a [BBC micro:bit v2](https://microbit.org/) to notify me when I am speaking too loud. Here is the project: https://github.com/jadolg/sound-alert-microbit

# Why?
I usually don't speak too loud. Even when I'm mad, I try to remain calm and not to increase the volume of my voice as I dislike loud folks myself. There are, anyway, moments in which I involuntarily do speak really loud: When I'm wearing headphones and when I get really excited about what I'm talking about. And, guess what: That's exactly my everyday scenario since COVID19 forced us to close the offices and work from home. I work remotely for a fantastic software company and yes, my work is really exciting. On top of that, we do a lot of pair programming and have tens of meetings every week to discuss what we want to do and how we want to do it. All of this while wearing headphones that isolate me pretty well from the environment, so as you can imagine, I started speaking really loud.
This whole situation was not really fun especially for my wife. She is also a software engineer and we share the same space for working.
![our office](https://dev-to-uploads.s3.amazonaws.com/i/1ziv7t15lnmco2ph4rhb.jpg)
Just imagine having meetings at the same time :grimacing:

# What to do
I needed to do something regarding this issue and engineers will try to solve everything with tech right? I researched for some hours and found out that the [BBC micro:bit](https://microbit.org/) had released a new version of their development board. What was specifically so nice about this board is that it comes already packed with a bunch of sensors including a microphone. This also comes with a very nice price tag and a system so simple to use even kids can do it.

## Using MakeCode
You don't know how to code? No problem, you don't need to write a single line of code. [Microsoft MakeCode](https://makecode.microbit.org/) will allow you to express your automation desires in an intuitive way. After some minutes, this is what I ended up with:
![code blocks](https://dev-to-uploads.s3.amazonaws.com/i/ztork5rt3gi3hzwjzwbm.png)
It is also very useful having an emulator and being able to play around and try everything.
MakeCode also allows you to code your solution in Python and JavaScript and applies translation from one codebase to another, so what I have just shown you in blocks looks like this in Python:
```python
sound_enabled = False
sound_level = 0

def on_button_pressed_a():
    global sound_enabled
    sound_enabled = not (sound_enabled)
input.on_button_pressed(Button.A, on_button_pressed_a)

def on_forever():
    global sound_level
    sound_level = input.sound_level()
    if sound_level > 100:
        if sound_enabled:
            music.play_tone(262, music.beat(BeatFraction.WHOLE))
        basic.show_icon(IconNames.EIGTH_NOTE)
    else:
        basic.clear_screen()
basic.forever(on_forever)
```
and like this in JavaScript:
```javascript
let sound_enabled = false
let sound_level = 0
input.onButtonPressed(Button.A, function on_button_pressed_a() {
    sound_enabled = !sound_enabled
})
basic.forever(function on_forever() {
    sound_level = input.soundLevel()
    if (sound_level > 100) {
        if (sound_enabled) {
            music.playTone(262, music.beat(BeatFraction.Whole))
        }
        basic.showIcon(IconNames.EigthNote)
    } else {
        basic.clearScreen()
    }
})
```
As much as I want to explain much more, I would be only grasping the surface of this great tool, so go and give it a try :smile:

# Final result
I ended up with a pretty cool gadget that warns me visually if I'm being too loud and with the press of a button I can set it so it also beeps at me. I'm trying to condition myself to be a better home-office mate for my wife. At this point, I think I have not made much progress at it :sweat_smile: but this is only the beginning.
You can find the code for the project in [this](https://github.com/jadolg/sound-alert-microbit) repository (which MakeCode allows you to do) and explore and play with it.

<sup>Kudos to [Clem Onojeghuo](https://twitter.com/ClemOno2) for the cover picture<sup>