Hi, I am currently working on a project, where I need to be able to read the volume of music. Later iI should get the decibel values, but I will get the values by comparing the decibel values of my multimeter with the values from the arduino.
My teacher told me that RMS is a possiblilty, however since im kinda new to arduino i would have to get a complete code for this and i failed to find one on the internet.
I am using an normal microphon with an amplifier and lifted the signal to be positive (new 0 value is now approximitly 2,5V).
Does anybody know of any other ways to get the volume expect the RMS or does anybody have a code for it?
In my code I am using the FHT aswell:
//FHT
#define LIN_OUT8 1 // use the lin8bit output function
#define FHT_N 256 // set to 256 point fht
#define SCALE 64 //Improves resolution of the fht_mag_lin8()
#include <FHT.h>
int k;
int j=0;
void setup() {
Serial.begin(115200); // use the serial port, with baudrate of 115200
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe7; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
void loop() {
//FHT
while(1) { // reduces jitter
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf7; // restart adc
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fht_input[i] = k; // put real data into bins
}
fht_window();
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_lin8(); // take the output of the fht
sei();
}
}
As you can see my code resembels the example code a lot, however i lowered the sample rate to get a better read of low (bass) frequencies.
I am using an Arduino UNO.
For the reading of the analog0 pin(where the mic is) i would have to use this code right:
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
Where k would be the actual read. I know that analogRead() doesnt work but this should give similar values, right?
If anybody could help me i'd be really thankful
Thanks and greetings!
Crocs