Project Overview
This project creates a humane dog bark deterrent that uses ultrasonic sound to discourage excessive barking. The system activates only when motion is detected, saving battery life and preventing constant noise. When the sensor detects a dog (or person), it emits a high-frequency sound (25-30 kHz) that is unpleasant to dogs but inaudible to humans.
Difficulty: Intermediate
Estimated time: 2-3 hours
Estimated cost: $25-35
How It Works
A PIR sensor detects motion (the dog approaching or moving in the yard). When motion is detected, the system activates an ultrasonic transducer that emits a high-frequency tone. Dogs find this sound unpleasant and learn to associate the area with the sound, eventually reducing barking behavior. The system includes a sound sensor (optional) to only activate when barking is actually occurring.
Materials Needed
- Arduino Nano or ESP32 (1)
- HC-SR501 PIR sensor (1)
- Ultrasonic transducer (25-30 kHz, e.g., Murata MA40S4S)
- ULN2003 Darlington array or MOSFET (to drive transducer)
- Sound sensor module (LM393-based, optional, for bark detection)
- Buzzer (for testing, optional)
- LED (for status indication)
- Resistors (220Ω, 10k)
- Jumper wires
- Power supply (5V 1A)
- Weatherproof enclosure (if outdoor use)
Circuit Diagram
Connection Table
| Component | Pin | Arduino Pin | PIR Sensor | VCC | 5V | PIR Sensor | GND | GND | PIR Sensor | OUT | Digital Pin 2 | Ultrasonic Transducer (+) | – | Digital Pin 9 (via ULN2003) | Ultrasonic Transducer (-) | – | GND | Sound Sensor | VCC | 5V | Sound Sensor | GND | GND | Sound Sensor | DO (digital out) | Digital Pin 3 | Status LED | Anode | Digital Pin 13 (through 220Ω) | Status LED | Cathode | GND |
|---|
Arduino Code
// PIR Dog Bark Stopper
// Uses PIR sensor and ultrasonic transducer
const int pirPin = 2;
const int ultrasonicPin = 9;
const int soundSensorPin = 3; // Optional bark detection
const int ledPin = 13;
// Timing
unsigned long lastTriggerTime = 0;
const unsigned long deterrentDuration = 3000; // 3 seconds
const unsigned long cooldownPeriod = 60000; // 1 minute between activations
bool deterrentActive = false;
unsigned long deterrentStart = 0;
// Ultrasonic frequency (25kHz = 20µs period)
const int halfPeriod = 20; // microseconds (for 25kHz)
// For 30kHz: halfPeriod = 16.7, use 17
void setup() {
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ultrasonicPin, OUTPUT);
pinMode(soundSensorPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ultrasonicPin, LOW);
digitalWrite(ledPin, LOW);
Serial.println("Dog Bark Stopper Ready");
Serial.println("Waiting 60 seconds for PIR warm-up...");
delay(60000);
}
void generateUltrasonicTone() {
// Generate square wave at ultrasonic frequency
for (int i = 0; i < 1000; i++) { // Generate 1000 cycles
digitalWrite(ultrasonicPin, HIGH);
delayMicroseconds(halfPeriod);
digitalWrite(ultrasonicPin, LOW);
delayMicroseconds(halfPeriod);
}
}
void activateDeterrent() {
if (millis() - lastTriggerTime > cooldownPeriod) {
deterrentActive = true;
deterrentStart = millis();
lastTriggerTime = millis();
digitalWrite(ledPin, HIGH);
Serial.println("Deterrent ACTIVATED");
// Generate ultrasonic tone for 3 seconds
while (millis() - deterrentStart < deterrentDuration) {
generateUltrasonicTone();
}
digitalWrite(ledPin, LOW);
deterrentActive = false;
Serial.println("Deterrent deactivated");
} else {
Serial.println("Cooldown active - deterrent not triggered");
}
}
bool isBarking() {
// Read sound sensor (optional)
return digitalRead(soundSensorPin) == HIGH;
}
void loop() {
bool motionDetected = digitalRead(pirPin) == HIGH;
// Optional: only trigger if barking is detected
// bool barking = isBarking();
if (motionDetected) { // && barking) for bark-only activation
Serial.println("Motion detected");
activateDeterrent();
}
delay(100);
}
Alternative: Tone Library Method
// Using Arduino tone() function for simpler ultrasonic generation
// Note: tone() works up to about 30kHz on some boards
const int ultrasonicPin = 9;
const int frequency = 25000; // 25kHz
void generateUltrasonicTone() {
tone(ultrasonicPin, frequency);
delay(3000);
noTone(ultrasonicPin);
}
Enclosure Design
- Use weatherproof enclosure for outdoor installations.
- Drill holes for PIR sensor lens (must be exposed).
- Drill holes for ultrasonic transducer facing the yard area.
- Add mesh or screen over transducer to prevent debris from blocking.
- Mount at dog height (0.5-1m) for best effect.
Installation Steps
- Assemble circuit: Build on breadboard and test with oscilloscope to verify ultrasonic output.
- Test with dog: If possible, test with a known dog to verify they react to the sound (look for ear perk, head tilt).
- Adjust frequency: Different dogs may respond better to different frequencies (20-30kHz). Test and adjust.
- Mount unit: Place where the dog frequents (barking area) at appropriate height.
- Monitor behavior: Observe over several days to see if barking reduces.
Safety Considerations
- Humane use only: This device is meant to discourage excessive barking, not to punish. Use responsibly.
- Not for continuous use: The deterrent should only activate briefly when motion is detected.
- Test on yourself: The sound should be inaudible to humans. If you can hear it, the frequency is too low.
- Not for use on puppies: Very young dogs may be more sensitive.
- Check local regulations: Some areas may restrict ultrasonic devices.
Project Extensions
- Bark detection: Add sound sensor to only trigger when barking is actually occurring.
- Wi-Fi notification: Add ESP32 to send notifications when the deterrent activates.
- Data logging: Track how often the device activates to measure barking frequency.
- Manual remote: Add Bluetooth to manually trigger from phone.
- Water spray: Add a water sprayer for stubborn dogs (more effective but less humane).
Troubleshooting
- No ultrasonic output: Check transducer wiring. Use oscilloscope or piezo speaker to verify frequency.
- Dog not responding: Try different frequencies (20-30kHz). Ensure dog can hear (older dogs may have reduced hearing).
- False triggers: Adjust PIR sensitivity or position to avoid detecting people walking by.
- Bark sensor not working: Adjust sound sensor threshold; may need to position closer to dog.
Conclusion
This humane bark deterrent can help reduce excessive barking without causing pain or distress. Combined with positive reinforcement training, it can be an effective tool for managing nuisance barking.
