Playing Recorded sound to mini A6 GSM Module

I am trying to make a project which plays a recorded sound when the call from Arduino is answered. I have an Arduino UNO, a mini A6 GSM Module, and an SD card Reader module. I am using the following code:

#include <SoftwareSerial.h>
#include <SD.h>
#include <TMRpcm.h>
#include <SPI.h>

TMRpcm tmrpcm;


SoftwareSerial mySerial(3, 2); 

void setup()
{

  Serial.begin(115200);
  

  mySerial.begin(115200);
  
  tmrpcm.speakerPin=9;
  
  if(!SD.begin(4))
  {
  Serial.println("SD fail");
  return;
  }

  Serial.println("Initializing..."); 
  delay(1000);

  mySerial.println("AT");
  updateSerial();
  
  mySerial.println("ATD+91xxxxxxxxxx"); 
  updateSerial();
  delay(3000); 
  tmrpcm.setVolume(6);
  tmrpcm.play("test.wav");
  delay(15000);
  mySerial.println("ATH"); 
  updateSerial();
}

void loop()
{
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());
  }
}

I replace “xxxxxxxxxx” with my phone number. I thought that the same signal that a speaker gets to produce a sound is ok if I connect GND to MIC- and pin 9 to MIC+, it will work but it didn’t. Can you tell me what are the problems and if my concept is fully wrong, how to do it? Below are my schematics and pictures of mine GSM Module.

all connections are as follows:
UTX (of A6) - D3
URX(of A6) - D2
MIC- (of A6) - GND
MIC+ (of A6) - D9
CS(of SD Card Module) - D4
SCK(of SD Card Module) - D13
MOSI(of SD Card Module) - D11
MISO(of SD Card Module) - D12

Power is given to both modules. individually, with the same connection, the sd card is playing test.wav to a speaker and the GSM module is calling the number. just the sound is not being played.

thought that the same signal that a speaker gets to produce a sound is ok if I connect GND to MIC- and pin 9 to MIC+, it will work but it didn't. Can you tell me what are the problems and if my concept is fully wrong, how to do it?

Well given that a microphone generates uV of signal and you need to drive a speaker with volts of signal you are totally swamping the microphone input. So at the least you need an attenuator on the input mike. You will have to experiment with the values of the two resistors forming the potential divider, but keep the whole impedance highish say 200K.

That is not a schematic it is just a pinout diagram with labels. A schematic would show your an Arduino and the other things connected so we could see things like ground and power connections to all modules.

Grumpy_Mike:
That is not a schematic it is just a pinout diagram with labels. A schematic would show your an Arduino and the other things connected so we could see things like ground and power connections to all modules.

But you don't need the schematic as the problem is how I do the connection from Arduino to the gsm and what change I should do in the code?

Can you explain the impedance thing with a diagram? :slight_smile:

But you don't need the schematic as the problem is how I do the connection from Arduino to the gsm and what change I should do in the code?

If you knew what the problem was you wouldn’t have to ask here. Many times what people think is a software problem turns out to be a hardware one. Especially beginners like you who don’t know what impedance is. Your entire problem is hardware not software.

Impedance is just like resistance but for AC signals.
For details of an attenuator see this.

Grumpy_Mike:
Your entire problem is hardware not software.

Impedance is just like resistance but for AC signals.

Now I know how a voltage divider. Some doubts:

  1. How do AC signals/ Impedance come in between? Ain't I am using DC signals?
  2. The voltage divider deceased the voltage(at specific points not total) and hence it works as an attenuator, right?

Grumpy_Mike:
So at the least you need an attenuator on the input mike. You will have to experiment with the values of the two resistors forming the potential divider, but keep the whole impedance highish say 200K.

  1. You mean that I have to make a voltage divider which has an output of x volts with an impedance of about 200k ohm?

Grumpy_Mike:
Well given that a microphone generates uV of signal and you need to drive a speaker with volts of signal you are totally swamping the microphone input.

  1. x voltage equals some uV volts, right?
  2. At last, you mean that instead of connecting the speaker input from Arduino to mic input, I should add a voltage divider with output in microVolts and that too with resistors with an impedance of almost 200k, right?
    Actually, it took me some days to understand what you said :slight_smile:

And here is the schematic:

If You don't understand my schematic(cause it looks messy) these are connections:
UTX (of A6) - D3
URX(of A6) - D2
MIC- (of A6) - GND
MIC+ (of A6) - D9
CS(of SD Card Module) - D4
SCK(of SD Card Module) - D13
MOSI(of SD Card Module) - D11
MISO(of SD Card Module) - D12

my schematic(cause it looks messy)

It looks messy because you make the classic mistake of making all the pin numbers on a chip in the same physical location on the rectangle as they are on the chip.

The pin locations on the rectangle representing the chip should be positioned to make the interconnections between the chip as uncluttered as possible. The use of a ground symbol and a Vcc symbol also reduce the mount of weaving about the wires have to do.
You also seem to have shorted the MISO line on the SD card module to ground. A dot indicates a connection. If you want a crossing point the the connection should go just short of the wire it wants to cross and then reappear on its way just the other side of it.

  1. How do AC signals/ Impedance come in between? Ain't I am using DC signals?

No you are not, you are using AC signals. Audio is an AC waveform.

  1. The voltage divider deceased the voltage(at specific points not total) and hence it works as an attenuator, right?

Not sure what you mean by "(at specific points not total)" but yes this works as an attenuator.

  1. x voltage equals some uV volts, right?

Yes.

  1. At last, you mean that instead of connecting the speaker input from Arduino to mic input, I should add a voltage divider with output in microVolts and that too with resistors with an impedance of almost 200k, right?

Yes, the 200K is only an order of magnitude, I chose to say that because that is more like a microphone than a speaker and that your GSM module is expecting a microphone. However when you say " the speaker input from Arduino" you mean the speaker output from Arduino.

But you have another problem. The GSM module is expecting a differential input for the microphone. You have wired one to ground and the other directly to your Arduino. That will only produce an output that goes above and the same as the signal on the -mike input, this will cause severe distortion so you should bias the -mike input to half way between ground and Vcc. Use two equal value resistors, again about 220K or so for an other voltage divider to bias that signal input.

You are not quite out of the woods yet. I am not sure how the GSM module will react to being given a PWM signal, this is not what a microphone produces, so you will need a restoration filter on the PWM output, and then you need to AC couple that signal into your attenuator.

In order to help you I have drawn a diagram of that bit of the circuity, note the use of power and ground symbols:-

I will take care of the schematics suggestion that you told me.
Ignore that "(at specific points...).

Grumpy_Mike:
However when you say " the speaker input from Arduino" you mean the speaker output from Arduino.

Yes, that's correct.

Grumpy_Mike:
But you have another problem. The GSM module is expecting a differential input for the microphone. You have wired one to ground and the other directly to your Arduino. That will only produce an output that goes above and the same as the signal on the -mike input, this will cause severe distortion so you should bias the -mike input to half way between ground and Vcc. Use two equal value resistors, again about 220K or so for an other voltage divider to bias that signal input.

You are not quite out of the woods yet. I am not sure how the GSM module will react to being given a PWM signal, this is not what a microphone produces, so you will need a restoration filter on the PWM output, and then you need to AC couple that signal into your attenuator.

In order to help you I have drawn a diagram of that bit of the circuity, note the use of power and ground symbols:-

Some More Doubts:
1)Why using an attenuator? Isn't the voltage divider working as an attenuator?
2) What should be my criteria for choosing that "adjust on test" resistor? If impedance, How to calculate that? Its formula is quite difficult (or I don't know whats are those things in that formula). If Decreasing The Volts, By using the formula from the tutorial and taking the output as 200 uV and using R1 as variable and R2=220K, I get a Value of 5499780K. Should I Increase the value of R2?

Can you please leave a link to the 0.1 uF AC coupling attenuator?

1)Why using an attenuator? Isn't the voltage divider working as an attenuator?

I don’t understand what you are saying. I have drawn dotted lines round groups of components to underline what they do. The voltage divider IS the attenuator.

What should be my criteria for choosing that "adjust on test" resistor?

So that you get sound and good quality sound at that.

If impedance, How to calculate that

The voltage drop of a resistance divider is given by the ratio of the two resistors. So to take the mid point bias resistors as an example the two resistors are the same. You will get the same voltage drop ( that is a half in this case ) if those resistors are both 1k, 100k or 220k or 1M. The only difference in all those cases is the impedance of the voltage divider. The impedance is what a circuit connected to the mid point “sees”. as the ground and the Vcc are considered to be the same point as far as impedance is concerned then the mic- connection sees an impedance of those two resistors in parallel. Which in this case is simply half the value or 110k. So the calculations are simply the formula for resistors in parallel.

Can you please leave a link to the 0.1 uF AC coupling attenuator?

You are conflating two separate labels. The 0.1uF capacitor is the AC coupling and the dotted line round the voltage divider is labelled attenuator.

Grumpy_Mike:
I don’t understand what you are saying. I have drawn dotted lines round groups of components to underline what they do. The voltage divider IS the attenuator.

OhK.
I have a new problem. To get 100 uV in the voltage divider, I have to get the resistors in a ratio of 1 : 5,000,000 (For me that is 5 1M Ohm resistors in series). And to get an impedance of 220K, I have to take the R1=220K Ohms and R2=(5M*220K) Ohms which is ALOT. Do you think I am doing something wrong? If not, Then THATS ALOT of Resistance. What should I do?
Thanks For All Support you gave me till now.

Do you think I am doing something wrong?

No, not only is that a lot of resistance it is a lot of attenuation.

hen THATS ALOT of Resistance. What should I do?

Well if it is going to be too much then I would relax the 200K total resistance, maybe even forget it for the time being, and see what results you get with lower values for the bottom resistor. If it gives problems then a more drastic solution might be needed, but see what you get first.

I have read on the internet that microphones usually make a signal of about 5 to 50 mV which lot more than what I am taking (100uV). If You think that would work, I will take 23 mV as my base and it will be very easy as the ratio will be 1 : 220, and the impedance will be 199K at R1=200K Ohm and R2=44M Ohm( Still quite difficult and messy but at least possible).

If you have any other suggestions to even decrease R2, I appreciate it :smiley: .

One Question:
On my google search, I found that a microphone has an impedance of just 200 Ohms. Is it right? :o
Thanks again for a very quick reply.

If you have any other suggestions to even decrease R2, I appreciate it

Well the way to do it would be in two stages with an op amp buffer between the two potential dividers.

R2=44M Ohm( Still quite difficult and messy but at least possible).

No not very practical, the resistance of a fingerprint is about 10M, anything higher has real problems if you handle them. So don’t go higher than that.

On my google search, I found that a microphone has an impedance of just 200 Ohms. Is it right?

Microphones come in all sorts of measure. What you need is the data sheet of the A6 module, that will tell you exactly what those inputs are expecting.

Grumpy_Mike:
Well the way to do it would be in two stages with an op amp buffer between the two potential dividers.

I Will read about that.

Grumpy_Mike:
No not very practical, the resistance of a fingerprint is about 10M, anything higher has real problems if you handle them. So don’t go higher than that.

I will go with outputs over 23 mV till 50 mV and keep the resistance lower than 10M ohm. If that gives a satisfactory result then that’s good.

Grumpy_Mike:
Microphones come in all sorts of measure. What you need is the data sheet of the A6 module, that will tell you exactly what those inputs are expecting.

I have found the datasheet for A6/A7/A6C but not for mini A6. It is in attachments. I could not find anything useful about mic in this.

A6_A7_A6C_datasheet-EN.pdf (985 KB)

I have found the datasheet for A6/A7/A6C

That is not really data sheet, it is just the pinout of various models. There is no actual data in it of any other description. Sadly what a lot of Chinese manufacturers think of as a data sheet is not what we would call a data sheet.

I Will read about that.

I will be surprised if you can find anything about it on the web.

Grumpy_Mike:
That is not really data sheet, it is just the pinout of various models. There is no actual data in it of any other description. Sadly what a lot of Chinese manufacturers think of as a data sheet is not what we would call a data sheet.

Ok.
I have calculated that taking 50 mV(which is, according to the internet, max) as the base and 200k ohm impedance which you said is the least you could go, R1=220K Ohm and R2=19M ohms so that won't work. So I have to try what you said,i.e., op-amp buffer(which don't know what is till know).
One question:

  1. Isn't the impedance of mid-rail bias and restoration filter counted with the attenuator impedance?

Grumpy_Mike:
I will be surprised if you can find anything about it on the web.

Is this info not correct? Op-Amp Voltage Buffer | Ultimate Electronics Book
I don't why I could not hyperlink it.

  1. Isn't the impedance of mid-rail bias and restoration filter counted with the attenuator impedance?

No.

base and 200k ohm impedance which you said is the least you could go, R1=220K

Read reply #9 again.

Is this info not correct?

Yes it is but it is not what I mean. I mean having one or more op amps having gains of less that one. There is a lot more to go wrong with op amps than you can cope with in your current state of knowledge. Just forget for the moment about the 200K thing and try what is in the circuit I posted.

I am currently experimenting with the resistors. Can you explain the use of restoration filter and mid-rail bias?
One More question, the point you connected to mic+ is actually supplying - current. So is it right?

After experimenting, no matter which resistor I try, on the phone I only hear only one sound, "zzzzz.....zzzzz.....zzzzz.....zzzzzz" while I am supposed to hear a fire brigade siren.

Can you explain the use of restoration filter and mid-rail bias?

A restoration filter converts the PWM signal into an analogue voltage.

The mid range bias is to bias or shift the mic- line to the point half way between ground and the positive supply. It allows the mic+ to go above or below the mic- input. These two inputs are differential inputs, that is they amplify the difference between the the mic+ and mic- input.

the point you connected to mic+ is actually supplying - current.

No it is not. What makes you think that?

no matter which resistor I try

Doesn't mean much because you don't say what resistors you tried.

on the phone I only hear only one sound, "zzzzz.....zzzzz.....zzzzz.....zzzzzz" while I am supposed to hear a fire brigade siren.

This is progress isn't it? You weren't getting any sound before.
Do the dots in the sound between the zzzz indicate a pause in the sound. Is this pause in your original sound?

You could try increasing the restoration capacitor.

But really you need to look at the signal with an oscilloscope to see what it looks like. Can you borrow one from school?

Grumpy_Mike:
No it is not. What makes you think that?

When I connect the negative lead of my multimeter to the wire going to mic+ and the positive one to the other end of the “adjust on the test” resistor, I get a positive value if I do it otherwise I get a negative value that makes me think that it is gnd at the mic+ wire if you take the other end of the “adjust” resistor as positive. Am I take the wrong point as to know the potential difference which makes the voltage seem negative.

Grumpy_Mike:
Doesn’t mean much because you don’t say what resistors you tried.

I used 220 Ohm, 470 Ohm, 1K Ohm, and 2.2K Ohm but I got the same zzz noise.

Grumpy_Mike:
This is progress isn’t it? You weren’t getting any sound before.
Do the dots in the sound between the zzzz indicate a pause in the sound. Is this pause in your original sound?

You could try increasing the restoration capacitor.

There was no sound before. I think it is progress. I think there is a rhythm in zzz. The sound is in attachments. I will try increasing the capacitor value.

Grumpy_Mike:
But really you need to look at the signal with an oscilloscope to see what it looks like. Can you borrow one from school?

No, my school doesn’t have an oscilloscope. I suspect if any of the schools in my district have an oscilloscope. Can you tell me some usual jobs which use an oscilloscope? Maybe, I could find one.

test.zip (126 KB)

When I connect the negative lead of my multimeter to the wire going to mic+ and the positive one to the other end of the "adjust on the test" resistor, I get a positive value

That sounds reasonable because that resistor it to top end of the attenuator and the mic+ is connected to the middle of the attenuator so it makes sense that you will see a positive voltage here.

if I do it otherwise I get a negative value

Now what do you mean by "otherwise"? That covers an almost infinite number of things.

That sound sample, is it the sound you are trying to generate or the sound you are getting on the call, the latter would be more useful.

Can you tell me some usual jobs which use an oscilloscope?

I would get your teacher to approach the next level of educational establishment up, for a start. I am in the UK so for here it would be sixth form collages or collages of further / higher education.
And other good source of oscilloscopes is maker spaces, or Radio Hams most of these will be very friendly to your request. Of course you have to know how to use one once you get one, so see if its owner could come and help you.