Weak Speaker Output on Ultrasonic Sensor Headset using Talkie. h – Need Help Boosting Volume

I'm currently developing an ultrasonic sensor headset as part of my research study. The headset uses an HC-SR04 ultrasonic sensor to detect obstacles and provides audio feedback through speakers. However, I ran into an issue where the output to the speakers is too weak to be heard.

Problem:
The sound output is extremely faint—I have to place the speaker very close to my ear to hear anything.
The volume is too low, making it impractical for real-world use.

Setup:
Microcontroller: Arduino Nano
Speakers: 8Ω 0.5W Mylar-type

Only thing I have seen/suggested to me is to use an audio amplifier module, but is there any other way?

Here is the code:

#include <Talkie.h>           // Include the Talkie library
#include <TalkieUtils.h>       // Include Talkie utils if needed for your project
#include <Vocab_US_Large.h>    // Include the vocabulary file for the sounds

// Declare the voice object globally
Talkie voice;   

#define TRIG_LEFT 2        
#define ECHO_LEFT 3        
#define TRIG_RIGHT 4       
#define ECHO_RIGHT 5       
#define SPEAKER_LEFT_PIN 9  
#define SPEAKER_RIGHT_PIN 10

unsigned long lastMeasureTime = 0;  
const int measureInterval = 100;    

void setup() {
  Serial.begin(115200);  // Initialize Serial communication
  pinMode(TRIG_LEFT, OUTPUT);  
  pinMode(ECHO_LEFT, INPUT);   
  pinMode(TRIG_RIGHT, OUTPUT); 
  pinMode(ECHO_RIGHT, INPUT);  
  pinMode(SPEAKER_LEFT_PIN, OUTPUT);  
  pinMode(SPEAKER_RIGHT_PIN, OUTPUT); 
}

int measureDistance(int trigPin, int echoPin) {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  long duration = pulseIn(echoPin, HIGH, 38000);  
  int distance = duration * 0.034 / 2;  

  if (distance == 0 || distance > 500) return 500;  
  return distance;
}

void sayAtLeft() {
  Serial.println("Left Speaker Activated!");
  digitalWrite(SPEAKER_LEFT_PIN, HIGH);   // Activate left speaker
  voice.say(sp2_DANGER);  
  voice.say(sp3_AT);      
  voice.say(sp2_LEFT);    
  digitalWrite(SPEAKER_LEFT_PIN, LOW);    // Deactivate left speaker
}

void sayAtRight() {
  Serial.println("Right Speaker Activated!");
  digitalWrite(SPEAKER_RIGHT_PIN, HIGH);  // Activate right speaker
  voice.say(sp2_DANGER);  
  voice.say(sp3_AT);      
  voice.say(sp2_RIGHT);   
  digitalWrite(SPEAKER_RIGHT_PIN, LOW);   // Deactivate right speaker
}

void loop() {
  if (millis() - lastMeasureTime >= measureInterval) {  
    lastMeasureTime = millis();  

    int leftDist = measureDistance(TRIG_LEFT, ECHO_LEFT);  
    int rightDist = measureDistance(TRIG_RIGHT, ECHO_RIGHT);  

    Serial.print("Left Distance: ");
    Serial.print(leftDist);
    Serial.print(" cm | Right Distance: ");
    Serial.print(rightDist);
    Serial.println(" cm");

    if (rightDist >= 6 && rightDist <= 300) {
      sayAtRight();  
    }

    if (leftDist >= 6 && leftDist <= 300) {
      sayAtLeft();  
    }
  }
}

Show us a schematic of the whole system. I suspect you are NOT using a capacitor between the Arduino pin and the speaker, so the DC component is swamping the movement of the speaker cone.

An Arduino output cannot drive a speaker directly. You will need to use an audio amplifier, with a low pass RC filter between the output pin and the amplifier input.

It appears to be working properly. But without an annotated schematic showing how you have wired it I cannot be sure. Also the Arduino is not an audio amplifier and connecting a speaker can damage it.
Gil's Crispy Critter Rules for Processor Hardware:

  1. Rule #1: An Arduino is NOT a Power Supply!
  2. Rule #2: Never connect anything inductive (motors, speakers) directly to an Arduino!
  3. Rule #3: Avoid connecting or disconnecting wires while the power is on.
  4. Rule #4: Do not apply power to any pin unless you are certain of what you're doing.
  5. Rule #5: Do not exceed the maximum voltage ratings.
  6. Rule #6: Many Arduinos cannot power transmitters directly.
  7. Rule #7: Before powering your project, take a break and double-check the wiring.

LaryD’s Corollaries:

  1. Coro #1: When starting out, add a 220Ω resistor in series with both input and output pins to protect against shorts.
  2. Coro #2: Invest in a Digital Multi-Meter (DMM) to measure voltages, currents, and resistance.

Note: Violating these rules can turn your Arduinos into crispy critters. For optimal performance, keep your wires under 25 cm (10 inches).

Additional Tips:

Thank you for your response! You're right, I am not using a capacitor between the Arduino pin and the speaker. Could you explain more about its purpose in this setup?

Also, what capacitor model (value and type) would you recommend for optimal sound output in my system? Thanks!

Thanks for the clarification! I see that an audio amplifier is necessary. What type of amplifier would you recommend for optimal sound output with my setup?

Also, can you clarify what purpose does the low pass RC filter provide? and what specific models should I use?

I appreciate your help!

I apologize if I seem unexperienced with the responses, I'm new with these kinds of stuff, I appreciate all your efforts to help me, thank you!

Hobby outlets like Adafruit and Sparkfun sell tiny amplifier modules that are suitable for your project.

The Talkie library generates ultrasonic signals (62.5 kHz) that can interfere with audio amplifier operation.

For a discussion of suitable RC filters, see this post: Screeching sound when using UNO with Talkie library with PAM8403 amplifier

Thank you so much!

Issue: Low Volume with Talkie & PAM8403 Amplifier

Hi everyone,

I previously posted about boosting the volume of my setup. Thanks to those who helped with the RC filter and suggested using an audio amplifier (I am currently using a PAM8403). However, I’m still facing issues—while the RC filter improved speech clarity, it didn’t actually amplify the sound. Additionally, I noticed that when I connect the input pin to the one specified in the code, the output is weak. However, when I connect it to D11, the sound is significantly louder, why is that?

Setup Details:

Arduino Nano running Talkie.h
PAM8403 amplifier module
3W 8Ω speaker
RC filter: 1kΩ resistor + 2.2µF (100V) capacitor
Powering PAM8403 with an external 5V supply

What I Tried:

  • Applied an RC low-pass filter (helped with clarity, but no volume boost)
    -Used PAM8403 as an amplifier (no noticeable increase in volume)
  • Ensured GND connections were properly shared
  • Powered PAM8403 using an external 5V supply

Questions:

  • Why is the amplifier not increasing the volume?
  • Is it a problem with Talkie.h?
  • Is there a better way to interface Talkie’s PWM output with PAM8403?

Any suggestions would be greatly appreciated! Thanks in advance.

As usual, a connection diagram (schematic), showing ALL connections between all components and power supplies will be worth a thousand words.

No

Applied an RC low-pass filter

You have been mis-informed about it's use, That would decrease the volume.

Is there a better way to interface Talkie’s PWM output with PAM8403?

Probably, since the way you are doing it does not work

Which nano are you using( there are several different models)?

My apologies, but I don't know how to make one, this is the best I could do

First Capacitor
Positive leg: Connected to Arduino Nano digital pin
Negative leg: Connected to one leg of the resistor

Resistor
First leg: Connected to the negative leg of the first capacitor
Second leg: Connected to:
Jumper cable going to PAM8403 right input
Positive leg of the second capacitor

Second Capacitor
Positive leg: Connected to the resistor's second leg
Negative leg: Connected to:
Jumper cable going to Arduino GND
Jumper cable going to PAM8403 GND input

PAM8403 Power Supply
5V input: Connected to Lithium-ion battery positive terminal
GND: Connected to battery negative terminal

PAM8403 Right Channel Output
Right channel (+): Connected to positive wire of the speaker
Right channel (-): Connected to negative wire of the speaker

Im using a Arduino Nano ATmega328P CH340G, I bought it online

How can I increase it?

You have a 5V battery?
How much current can it supply?

If you are using a 3.7V Li-ion that would explain some of the reduced volume.

Probably your next lesson in electronics.

Do you have a pen, pad and phone camera.
That’s a starting point.

Sadly word salad doesn't cut it in electronics.

Have a look at this video:-
Colin's Lab video on reading a schematic

Connect like this

is the 3.7V too insufficient?