Looking to enhance your smart home with a touch of relaxation and cutting-edge technology? In this tutorial, we’ll show you how to build a Smart Twitterbox—a DIY device that automatically plays calming sounds like birdsong and jungle ambiance when it detects your presence. Using an advanced mmWave presence sensor and seamless integration with Home Assistant, this project offers precise motion and even presence detection and versatile automation for any room in your home. Whether you’re new to DIY electronics or an experienced maker, this step-by-step guide will walk you through creating your own Smart Twitterbox and setting up the perfect ambiance effortlessly.

You can watch the following YouTube video which explains everything:

Required components

To get this project started, we need the following components:

  • An ESP32 dev board, for example a D1 mini ESP32
  • An LD2420 mmWave presence sensor
  • A MAX9857A amplifier
  • A 5W speaker
  • a 5V power supply & USB cable
  • Somit jumper wires
  • A 3D priner + filament OR a 3D printing service

Wiring scheme

The ESP32 dev board is the heart of the architecture. It connects to the LD2420 presence sensor and to the MAX98573A. The LD2420 detects presence an when presence is detected, then sound is played via the MAX98573A amplifier on the speaker.

ESPHome YAML code

After we have wired everything up, we need to prepare, compile and flash the software to the ESP32 dev board. We use ESPHome for that which allows for a super simple configuration just using YAML files. To understand how you can compile and flash ESPHome code to the ESP32 dev board please follow the official docs. In the following listing, you can find the ESPHome YAML code.

The assumption is that you have wired everything exactly as shown above, so all the GPIOs match. Please be aware that YOUR_ENCRYPTION_KEY, YOUR_OTA_PASSWORD and YOUR_AP_PASSWORD are just placeholders as those are keys/passwords that are usually auto generated by ESPHome. Please note that you need to replace YOUR_FILE_URL with the URL to your sound file.

esphome:
  name: smart-twitterbox
  friendly_name: smart-twitterbox

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: YOUR_ENCRYPTION_KEY

ota:
  - platform: esphome
    password: YOUR_OTA_PASSWORD

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Smart-Twitterbox"
    password: YOUR_AP_PASSWORD

captive_portal:

uart:
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 115200
    
ld2420:

text_sensor:
  - platform: ld2420
    fw_version:
      name: LD2420 Firmware

sensor:
  - platform: ld2420
    moving_distance:
      name : Moving Distance

binary_sensor:
  - platform: ld2420
    has_target:
      name: Presence
      on_press: 
        - media_player.play_media: 'https://YOUR_NABU_CASA_ID.ui.nabu.casa/local/bird_twitter.mp3' 

select:
  - platform: ld2420
    operating_mode:
      name: Operating Mode

number:
  - platform: ld2420
    presence_timeout:
      name: Detection Presence Timeout
    min_gate_distance:
      name: Detection Gate Minimum
    max_gate_distance:
      name: Detection Gate Maximum
    gate_select:
      name: Select Gate to Set
    still_threshold:
      name: Set Still Threshold Value
    move_threshold:
      name: Set Move Threshold Value

button:
  - platform: ld2420
    apply_config:
      name: Apply Config
    factory_reset:
      name: Factory Reset
    restart_module:
      name: Restart Module
    revert_config:
      name: Undo Edits

i2s_audio:
  - id: i2s_in
    i2s_lrclk_pin: GPIO27
    i2s_bclk_pin: GPIO26
  - id: i2s_out
    i2s_lrclk_pin: GPIO25
    i2s_bclk_pin: GPIO14

media_player:
  - platform: i2s_audio
    name: "Twitterbox Mediaplayer"
    i2s_audio_id: i2s_out
    id: speaker_i2s
    dac_type: external
    i2s_dout_pin: GPIO32
    mode: mono

switch:
  - platform: template
    name: "Play sound"
    id: "play_sound"
    turn_on_action:
      - media_player.play_media: YOUR_FILE_URL
      - switch.turn_off: play_sound

Print the housing

Next step is to print the housing. You can download the files from printables:

https://www.printables.com/de/model/1000815-diy-twitterbox-box-plays-sound-when-person-present

Try it out

After you have wired everything up, you can play around with the device. I should play the defined sound file (YOUR_FILE_URL) whenever a person is present.

Comments are closed