Sep 6, 2026

Build an Autonomous Bark and Noise Detection Scanning Robot with a Raspberry Pi

5 min readIntermediate

A mobile robot that autonomously scans an area, detects a specific sound like barking, and logs when and roughly where it happened is a genuinely practical project, not just a demo: the same combination of a microphone array, a lightweight audio classifier, and simple motor control shows up in real noise-monitoring and wildlife-monitoring setups. This walks through building one with current, real hardware and a working detection pipeline.

What you actually need

  • A Raspberry Pi 4 or 5 (4GB+ RAM) as the brain. This project needs enough CPU to run a small audio classification model in real time, which rules out a Pi Zero or a plain Arduino.
  • A ReSpeaker 4-Mic Array for Raspberry Pi (or an equivalent 4-channel USB microphone array). Note that Seeed Studio has stopped maintaining its bundled direction-of-arrival firmware, so treat it purely as a 4-channel audio capture board and do direction estimation yourself in software, which is what the code below does.
  • A 4WD robot chassis kit with DC gear motors (the common “4WD smart car chassis” kits sold widely for around $20 to $35 include the frame, wheels, and motors).
  • A TB6612FNG or L298N motor driver board to let the Pi’s low-current GPIO pins control the higher-current DC motors safely.
  • An HC-SR04 ultrasonic distance sensor for basic obstacle avoidance while scanning.
  • A 2S (7.4V) Li-ion or Li-Po battery pack with a 5V buck converter for the Pi, plus direct battery voltage for the motor driver.
  • Jumper wires, a small chassis-mount breadboard or perfboard, and standoffs to mount the Pi above the motor level.

Wiring the motor and sensor side

TB6612FNG PWMA -> Raspberry Pi GPIO12
TB6612FNG AIN1 -> Raspberry Pi GPIO5
TB6612FNG AIN2 -> Raspberry Pi GPIO6
TB6612FNG PWMB -> Raspberry Pi GPIO13
TB6612FNG BIN1 -> Raspberry Pi GPIO19
TB6612FNG BIN2 -> Raspberry Pi GPIO26
TB6612FNG VM   -> Battery positive (motor voltage)
TB6612FNG VCC  -> Raspberry Pi 3.3V (logic power)
TB6612FNG GND  -> Common ground (Pi, battery negative, motors)

HC-SR04 VCC -> 5V
HC-SR04 GND -> GND
HC-SR04 TRIG -> GPIO23
HC-SR04 ECHO -> GPIO24 (through a voltage divider, since ECHO outputs 5V and the Pi's GPIO is 3.3V-only)

The ECHO voltage divider is the detail people skip and then wonder why they’ve damaged a GPIO pin: a simple 1k and 2k resistor divider brings the 5V echo signal down to a safe 3.3V before it reaches the Pi.

The detection pipeline

Rather than writing a bark detector from scratch, use Google’s YAMNet, a pretrained audio event classification model that already includes a “Bark” and “Dog” class among its roughly 500 categories, and runs comfortably on a Raspberry Pi 4 via TensorFlow Lite:

import sounddevice as sd
import numpy as np
import tensorflow as tf
import csv
from datetime import datetime

interpreter = tf.lite.Interpreter(model_path="yamnet.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

CLASS_NAMES = open("yamnet_class_map.csv").read().splitlines()[1:]
BARK_INDEXES = [i for i, line in enumerate(CLASS_NAMES) if "Bark" in line or "Dog" in line]

SAMPLE_RATE = 16000
CHUNK_SECONDS = 1

def classify(audio_chunk):
    waveform = audio_chunk.astype(np.float32) / 32768.0
    interpreter.resize_tensor_input(input_details[0]['index'], [len(waveform)])
    interpreter.allocate_tensors()
    interpreter.set_tensor(input_details[0]['index'], waveform)
    interpreter.invoke()
    scores = interpreter.get_tensor(output_details[0]['index'])
    mean_scores = scores.mean(axis=0)
    bark_confidence = max(mean_scores[i] for i in BARK_INDEXES)
    return bark_confidence

def estimate_direction(multichannel_audio):
    # Simple energy-based direction estimate across the 4 mic channels:
    # the channel with the highest RMS energy indicates the nearest bearing.
    energies = [np.sqrt(np.mean(ch.astype(np.float32) ** 2)) for ch in multichannel_audio.T]
    bearings = ["front", "right", "back", "left"]
    return bearings[int(np.argmax(energies))]

def log_event(direction, confidence):
    with open("bark_log.csv", "a", newline="") as f:
        csv.writer(f).writerow([datetime.now().isoformat(), direction, round(float(confidence), 3)])

stream = sd.InputStream(samplerate=SAMPLE_RATE, channels=4, dtype='int16')
stream.start()

print("Scanning for barking...")
while True:
    audio, _ = stream.read(SAMPLE_RATE * CHUNK_SECONDS)
    mono = audio.mean(axis=1).flatten()
    confidence = classify(mono)
    if confidence > 0.5:
        direction = estimate_direction(audio)
        log_event(direction, confidence)
        print(f"Bark detected, confidence {confidence:.2f}, direction: {direction}")

The 0.5 confidence threshold is a starting point. Run it for a day in your actual environment first and check bark_log.csv against what you know really happened, then raise or lower the threshold based on your own false-positive and false-negative rate rather than trusting a default.

Adding the scanning motion

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
for pin in [5, 6, 12, 19, 26, 13, 23, 24]:
    GPIO.setup(pin, GPIO.OUT if pin != 24 else GPIO.IN)

def rotate_scan():
    GPIO.output(5, GPIO.HIGH)   # left motor forward
    GPIO.output(6, GPIO.LOW)
    GPIO.output(19, GPIO.LOW)   # right motor reverse (in place rotation)
    GPIO.output(26, GPIO.HIGH)
    pwm_a = GPIO.PWM(12, 1000)
    pwm_b = GPIO.PWM(13, 1000)
    pwm_a.start(40)
    pwm_b.start(40)
    time.sleep(0.5)
    pwm_a.stop()
    pwm_b.stop()

Call rotate_scan() between listening windows to physically sweep the mic array across a wider area than a stationary unit could cover, then pause motors while capturing audio, since the motors themselves are a significant noise source that will otherwise swamp the classifier.

Frequently asked questions

Is this still a realistic hobbyist project, or does it need research-lab equipment?
It’s realistic on hobbyist hardware. YAMNet is a real, publicly released, actively used model that runs on a Raspberry Pi 4 without a GPU, and 4-channel USB/I2S microphone arrays in the $15 to $30 range are widely available and current. The main investment is your own time tuning thresholds and the physical build, not exotic parts.

Are there privacy or legal concerns with a device that continuously records audio outdoors?
Depending on your jurisdiction, continuous audio recording of areas beyond your own property can raise privacy or wiretapping-law questions, so check local regulations before deploying this beyond your own yard, and consider logging only classification results and timestamps (as the code above does) rather than retaining raw audio recordings.