Measuring amps on arduino

I have come across this sketch on the internet and i was wondering how the creator has measured the amps section at the bottom

// 

const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
// this is to pick up frequencies as low as 20Hz

unsigned int sample;

unsigned long previousMillis = 0;
const long interval = 1000;

void setup() 
{
   Serial.begin(9600);
}
 
void loop() 
{
   unsigned long startMillis= millis();  // Start of sample window
   unsigned int peakToPeak = 0;   // peak-to-peak level
 
   unsigned int signalMax = 0;
   unsigned int signalMin = 1023;
 
   // collect data for 50 mS
   while (millis() - startMillis < sampleWindow)
   {
      sample = analogRead(A0);
      if (sample < 1023)  // toss out spurious readings
      {
         if (sample > signalMax)
         {
            signalMax = sample;  // save just the max levels
         }
         else if (sample < signalMin)
         {
            signalMin = sample;  // save just the min levels
         }
      }
   }
   peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
   double volts = (peakToPeak * 5.0) / 1023.0;  // convert to volts
   
   double watts = volts * 0.001; // volts times amps

Where have they got 0.001 from do you think? or how have they measured it?

 double watts = volts * 0.001; // volts times amps
   
   double soundPower = 10.0 * log10(watts/10e-12);
   
   double soundPressure = soundPower + (10.0 * log10(1.0/(4.0*PI*pow(2,2))));

In fact if anyone could break this down for me, that would be a great help

Out of context it's hard to know...

What are you trying to do?

I'm going to guess it's an "assumed value" because the programmer didn't know how to calculate dB from voltage/amplitude. And, I'm not even sure if that works... In general current is proportional to voltage (from Ohm's Law) so you can't have a fixed (or assumed) current unless the voltage is fixed.

P.S.
If you are trying to measure dB SPL (sound loudness in the air) you don't need voltage or current (amps). You just need an analog reading that correlates with loudness. And in any case, you'll need a real SLP meter to calibrate your readings.

DVDdoug:
In general current is proportional to voltage (from Ohm's Law) so you can't have a fixed (or assumed) current unless the voltage is fixed.

Even then, it'd be:

watts = volts * volts * 0.001.  // if R = (1/ 0.001)

The only way that it could be this is if the voltage was being generated by a constant current source:

watts = volts * 0.001.  // if I is constant 0.001 A source

I think the OP needs to provide a link to where they got this code to see how (and if) this makes sense.

Its an adafruit sketch for a electret microphone that prints the voltage.

The addition to the code was from here: Ambient noise meter · GitHub

I just assumed this method of getting to dBSPL was correct.

From the voltage, what equation (or equations) could i use in order to convert it dBSPL?

Not in code, just the actual equations

mrears92:
Its an adafruit sketch for a electret microphone that prints the voltage.

Measuring Sound Levels | Adafruit Microphone Amplifier Breakout | Adafruit Learning System

The addition to the code was from here: Ambient noise meter · GitHub

I just assumed this method of getting to dBSPL was correct.

From the voltage, what equation (or equations) could i use in order to convert it dBSPL?

Not in code, just the actual equations

Hmm...well, from adafruit's schematic and datasheet, I really can't see how the current would be fixed at 1mA.

I can't say that I'm familiar with condenser microphones, however. Maybe laserlemon knows something that isn't obvious from the schematic/datasheet. That 0.001 really does look like something that should be #defined at the top with a comment about where it came from.