Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

new to Ardunio but trying to compile

Status
Not open for further replies.
the code seems to work?
have put this project on hold while I was trouble shooting my LCD issue as well as waiting for parts from Mouser.
Not saying your wrong but want to experiment as a learning exercise. Something Jon seems to not understand.
Will look at schematics again and ??
 
the code seems to work?
If by "seems to work" you mean it produces an output then yes, I'm sure it "works".

If "work" means it produces something that's remotely correct then no, it doesn't.
The first circuit diagram (with the LM386) shoves an AC voltage into the ADC pin of the uC.
That will do nothing good other than to try and blow up the arduino.
The description is even nonsense. He talks about DC noise being a problem? WTF?

And I'll say it again. You can't take the ADC readings and shove them directly into a dB equation.
Think of it this way,. Lets say your sine wave goes peak to peak, so the low part is 0V and the high part is 5V.
You get two radically different results even though the level of the sine wave hasn't changed.
 
That's much better. At least that guy knows what he's talking about.

All you should need is the part up to MeasureVolume()... the Fast Hartley Transform stuff is cool but you won't need that
unless you're trying to build a spectrum analyzer.
 
well I found (pretty sure) a code that shows real promise in relation to volume levels.
the original code used double volts=(peakToPeak*3.3)/1024;//converts to volts
So I started increasing the 3.3 to 4 and the values fluctuate with volume levels more so with the lower multiplier. I used 1.25 since the module has an offset of 1.25 volts and seems to work really well with volume changes. More so using 100hz sound. going to experiment more.
Code:
[code]
const int sampleWindow = 50; //a sample 50 ms long
unsigned int sample;

void setup()
{
  Serial.begin(9600);
}
  // put your setup code here, to run once:



void loop()
{
  unsigned long startMillis=millis(); //start sample window
  unsigned int peakToPeak=0; //peak to peal level
  unsigned int signalMax=0;
  unsigned int signalMin=1024;
  //collect data
  while (millis()- startMillis<sampleWindow)
  {
    sample=analogRead(0);
    if (sample<1024) //toss out spuriousreadings
    {if (sample>signalMax)
    {
      signalMax=sample; //save just the max levels
    }
    else if (sample<signalMin)
    {
      signalMin=sample;  //save min samples only
    }
    }
  }
  peakToPeak=signalMax-signalMin;  //max-min=peaktopeak
  double volts=(peakToPeak*1.25)/1024;//converts to volts
  Serial.println(volts);
  delay(1000);
}
  
  // put your main code here, to run repeatedly:
[/CODE]
 
the original code used double volts=(peakToPeak*3.3)/1024;//converts to volts
So I started increasing the 3.3 to 4 and the values fluctuate with volume levels more ...
Well, imagine that! If you multiply something by a bigger number you get a bigger number!

...I used 1.25 since the module has an offset of 1.25 volts
That bears no relation to where the "3.3" comes from in the original equation, but whatever floats your boat.

You could get almost the same result by picking any two random numbers.
You could even just leave off the multiply and divide. It's not volts anymore but neither is your current number.
 
I found using the 1.25 instead of the 3,3 the resulting output measurement varies more.
will post some screen shots showing different volume levels.
 
In that case, leave out the "/1024" too and just use
Code:
peakToPeak=signalMax-signalMin;  //max-min=peaktopeak

The numbers will vary from 0 to 1023. Anything else is just fictitious numbers created by multiplying and dividing.
There's no more useful information there than the peakToPeak value.
 
All I am interested in is a HIGH volume value and LOW volume level. Both to be compered to desired listening level preset by user so three different values needed.
 
so if you change the last part of post #227 from
Code:
 peakToPeak=signalMax-signalMin;  //max-min=peaktopeak
  double volts=(peakToPeak*1.25)/1024;//converts to volts
  Serial.println(volts);
  delay(1000);

to this
Code:
 peakToPeak=signalMax-signalMin;  //max-min=peaktopeak
  Serial.println(peakToPeak);
  delay(500);
you'll get peakToPeak numbers ranging from 0 (dead quite) to 1023 (max volume it can measure).
The upper number may not reach 1023 depending on the mic, gain pot, and volume.

Try running the program with a sinewave first, changing the volume to get a feel for what results you get, and then try some music.
The numbers you get when using the sinewave should be pretty stable, and the numbers from the music will bounce around.

In the real world you're not going to be able to just sample, take the peakToPeak value and say "if it's > my upper limit turn it down" or "if it's < my lower limit turn it up".

It's more complicated than that. You'll find that out later...
 
Probably not.

You're going to get little snapshots of what the level is in a small window of time. Normal speech, bomb blasts, and quite times are all going to have different levels.

The tricky part is figuring out what's normal and what's due to a change in the overall volume. Otherwise it's going to be constantly adjusting the level up and down when you really don't want it to.
 
the volume going up and down is a concern.
thinking a CASE SELECT / SWITCH with a large window between too loud and too low. for desired volume level
 
using Tumbleweeds suggestion it outputs a wider range of data.
for experimental purposes I assembled an LM358 circuit that I compared with the Max4466 module and the results are a more sensitivity to volume changes than the Max4466 module.
contemplating a pot in place of the 100K resistor.
I attempted to display both circuits on one plotter but wouldn't show the two different sine waves.
After I recheck my code will show comparisons between the LM358 and the Max4466
 

Attachments

  • lm358 circuit.jpeg
    lm358 circuit.jpeg
    32.9 KB · Views: 275
I'm sort of surprised by that. The LM358 wasn't really designed to use a single supply, so it's output range will be limited compared to the MAX4466. You should be able to get more gain out of the MAX4466 module (about x125) vs x100 for that schematic.

I guess you're using a different mic as well?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top