# Differing behaviour from Arduino Nano when plugged into laptop vs power source

Well here's a weird one. I'm monitoring a mic on an analog pin of an Arduino Nano and using the variation in voltage to control and LED.

When plugged in to my Laptop (USB 3, 500ma available, the nano only pulls 90) the detection is flawless. When plugged into an external power source, I get no variation at all or a random, non-responsive pattern of variation. Could be I'm getting voltage values that are out of range, but of course I can't monitor them on the serial port when I'm not plugged into the laptop.

I've got a potentiometer on the circuit to increase or decrease sensitivity by changing the trigger value. I can play poke-and-try at changing the trigger values to higher and lower ranges to try and find the sweet spot, but does anybody have an explanation of why I'd see a difference in the first place? I've tried a variety of external supplies, 500ma 1a, 2a - but if it's only pulling 90 (as reported by my Macbook System Report) this shouldn't matter, right? What else could account for differing behaviour?

Here's the code:

``````    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 = 1024;

// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
if (sample < 1024)  // 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) / 10;  // convert to volts
if (val > 0) triggervoltage = 10;
if (val > 500) triggervoltage = 11;
if (val > 800) triggervoltage = 12;
if (val > 1000) triggervoltage = 15;

Serial.println(val);
Serial.println(triggervoltage);
Serial.println(volts);
//triggervoltage =
//Serial.println(volts);
//Serial.println(val);
//THIS IS the trigger mechanism for the effect. Vary the volts value to adjust sensitivity.

if (volts > triggervoltage) [LED RESPONSE HERE]
``````
• noisy external power source, perhaps ..... how is the external power source connected? ..... try using a battery Dec 30, 2018 at 21:27
• Hmm. Indeed, it works on a battery. But I guess that means my entire house's supply is noisy -- I tried different supplies in different rooms. Dec 30, 2018 at 22:09
• which supply are you using? .... what are the specs? Dec 30, 2018 at 22:58
• You could make a small sketch to send the value of analogRead to the serial plotter (instead of the serial monitor), then you can try a few things and see what the noise is doing. The laptop running at battery power is probably the best. As soon as you connect the laptop to a charger and a external power supply to the circuit, that is when the trouble begins. How is your microphone connected to the arduino? Please add extra information to your question. Could you add a photo of the arduino with microphone?
– Jot
Dec 31, 2018 at 11:38