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.
RPN was used because it's simple to do - everything is done on the stack - each number is placed on the stack in turn, and then popped off by the command and the result put back on the stack.
Exactly, and can be done in hardware before software capability became common.

Mike.
 
Mike.
Edit, just installed DESMOS and tried to do 45x54 and it says its not valid!
Has worked great for me for over a year.... I need a good calculator with graphical capabilities.. DEMOS is absolutely brilliant..

45 8 54 = 2430...
 
well tried several different codes and using this code with a few minor additions (averaging 100 samples) seems to work but will find out later after :OML wakes up so I can test using sound from a Netflix movie and adjusting the volume up and down. one problem is the screen scrolls very fast. will look into it.
Code:
[code]
const int batteryPin = A0;
long sum = 0;

  void setup()
  {
    Serial.begin(9600);

    // put your setup code here, to run once:
  }


  void loop()
  {

    for (int i = 0; i < 100; i++)  //incriment i for 100 samples
    sum += analogRead(batteryPin); //adverage over 100 samples
 
  int val = analogRead(batteryPin);
  long mv = (val * (500000 / 1023L)) / 100;
  Serial.print(mv / 1000);
  Serial.print('.');
  int fraction = (mv % 1000);
  if (fraction == 0)
  {
    Serial.print("000");
  }
  else if (fraction < 10)
  {
    Serial.print("00");
  }
  else if (fraction < 100)
  {
    Serial.print("0");
  }
  Serial.println(fraction);
}
[/CODE]
 
So you threw out the version that calculated decibels properly in favor of the original junk you had.

No, wait. It's worse than that. You're using a program designed to read a linear battery voltage?

The ear does not respond to sound linearly. Why do I even try to explain things you're just going to ignore?

Very well.
 
Last edited:
Let me try to explain in more simple terms. If you don't understand something, please ask rather than just ignoring it. It is extremely disheartening to think progress is being made (after spending considerable time explaining a concept) when you say "I found another code. I'm throwing the other one away."

The last program you posted is to read battery voltage. The ADC reading is scaled to read the linear voltage. Look at and understand the chart below. An ADC of 0 = zero volts. An ADC reading of about 200 = 1 volt. 400 = 2 volts. On up to 5 volts. It's linear. A change of ADC reading by 200 counts = 1 volt.

dB vs Linear for Dummies 1.jpg



Sound pressure and the perception of noise level by the ear are not linear. The noise level has to change by about 3.15 times to sound twice as loud. And 3.15 times again to sound 4 times as loud. The perceived noise level is a multiple, not a linear relationship. Look at the chart below.

Let's say a screaming loud commercial comes on. You want to cut the level in half. You'd need to cut the level down to 315 ADC counts - from 1000 to 315 is a change of 685 counts. Want to cut the volume in half again? That requires cutting the ADC counts to 100, a change of 215 counts. 685 counts to decrease the volume by half at high levels; 215 at low levels. It's not LINEAR.

The increments get eve smaller at low levels.

Explained as well as I am able.

dB vs Linear for Dummies 2.jpg
 
the last code I posted was a learning experiment just to see how it worked.
I am going to experiment inserting the formula you suggested and see what that looks like.
the code (last one) was using the battery voltage as a reference. I ran across a website that used milli volts and showed the relationship with db. Will look for article and post a link.
 
the last code I posted was a learning experiment just to see how it worked.
I am going to experiment inserting the formula you suggested and see what that looks like.
the code (last one) was using the battery voltage as a reference. I ran across a website that used milli volts and showed the relationship with db. Will look for article and post a link.

You don't have to use a formula in the code, you can pre-calcuate it and just use a lookup table - which is obviously much faster, but speed probably isn't an issue anyway.
 
I added in suggested formula and results look better.
volume on computer low = .024
raise volume = only with talking on tv =.039
going to experiment with music
 
I added in suggested formula and results look better.
volume on computer low = .024
raise volume = only with talking on tv =.039
going to experiment with music

Those numbers didn't come from anything I suggested. No idea what you're actually doing.
 
its back to the drawing board.
I increase the volume way up (listening to the Who, buba o riley, and numbers should change but they don't
Lower the volume and still the same basic numbers.
it acts like a color organ and responds to the beat of the music regardless of volume level.
 
Please, please, please. Try to figure out the commands. You only have to do THREE THINGS:

1. Read the ADC into a variable.

2. Compute dB of the ADC value using the equation I gave you.

3. Print the ADC value (which will range from 0 – 1023) and the dB value (which will range from 0 – 60)

Wait a few seconds and read it again. Don't worry about averaging or anything else at this point.

When you get numbers, check that they are valid using a calculator.

Code:
ADC      dB
1000     60
315       50
100       40
31.5      30
10         20
0            0

^^^ this isn't code. It shows the range of values you should get.

3 commands in the main loop. Three SIMPLE commands. You don't need to copy and paste these from anywhere. After 5000 posts and 10+ years of "programming", you can figure out THREE SIMPLE COMMANDS.
 
well here is the suggested revisions. Seems to work but need to get an average.
numbers are changing very fast but they seem to vary with volume.
will work on this later today. Have several boards I need to assemble and attach to new enclosures.
 
well here is the suggested revisions. Seems to work but need to get an average.
numbers are changing very fast but they seem to vary with volume.
will work on this later today. Have several boards I need to assemble and attach to new enclosures.

How are you detecting the audio?, do you have a rectifier etc.
 
here is the code I am using. Am using an Ardunio sound module that has an amplifier on it.


Code:
[code]
const int SoundIn = A0;
void setup()
{
  Serial.begin(9600);
}
// put your setup code here, to run once:
void loop()
{
  int val = 20 * log10(analogRead(SoundIn)) / 0.1;

                       Serial.print(val);
                       Serial.println("db = ");
}
[/CODE]
 
MrDeb...

You'll need a few samples to "average" the volume...Instantaneous samples will be misleading and wrong.

Say you had a tune in 4:4 time you would normally repeat is say three to for bars so sample for at least the time of 2 bars, then work out the mean volume...
 
MrDeb...

You'll need a few samples to "average" the volume...Instantaneous samples will be misleading and wrong.

Say you had a tune in 4:4 time you would normally repeat is say three to for bars so sample for at least the time of 2 bars, then work out the mean volume...

Baby steps. Getting reasonable numbers is the first step. Then averaging can be added.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top