Projects / Decoupling capacitor noise lab

Decoupling capacitor noise lab

Intermediate1 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Build the divider

    Two 10 kilohm resistors from 5V to GND with A0 at the middle.

  2. NANO

    Run with NOISE_ON false

    Note mean, spread and std.

  3. NANO

    Lay the D9 wire next to the A0 wire and set NOISE_ON true

    Upload and note the three numbers.

  4. NANO

    Add a capacitor from A0 to GND

    Upload is not needed, just watch the monitor.

  5. NANO

    Add a second capacitor from 5V to GND

    Compare again.

  6. NANO

    Move the noise wire away

    See how distance matters.

  7. NANO

    Write the four spreads side by side

    Sketch a bar chart.

In short

How do you build a decoupling capacitor noise lab?

Read a steady voltage with a Nano many times while a noisy wire runs next to it, then add small ceramic capacitors and compare how much the readings wobble. You see what a decoupling capacitor really does. You need Arduino Nano, Resistor 10 kΩ × 2, Ceramic Capacitor 100 nF × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 60 minutes.

Level
Intermediate
Time
About 60 min
Parts
5
See the electronics first. This build uses capacitor charging. Try a capacitor charging in the circuit builder and watch the voltages and currents before you wire it.

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
10 kilohm resistor 1Nano 5V and Nano A0Top of the divider
10 kilohm resistor 2Nano A0 and Nano GNDBottom of the divider
Jumper wire from D9Laid alongside the A0 wire for about 8 cmThe deliberate noise source, not connected to A0
100 nanofarad capacitor 1Between A0 and GNDAdded in step three
100 nanofarad capacitor 2Between 5V and GND at the dividerAdded in step four

Code

A 5 kilohm source, two 10 kilohm resistors in a divider, is an easy target for stray signals, and a wire next to a fast square wave picks some of it up. This sketch makes a 31 kilohertz square wave on D9, with a jumper wire lying alongside the A0 wire as the noise source, and then reads A0 five hundred times, printing the mean, the gap between highest and lowest, and the standard deviation. Run it in four steps and write down the spread for each. First set NOISE_ON to false for a baseline. Then set it true and note how the noise rises. Then add a 100 nanofarad ceramic capacitor between A0 and ground, which gives the fast noise a path to ground, and the spread should fall. Then add a second one across the supply at the divider and see what it adds. This is exactly what a decoupling capacitor next to a chip does. Ceramic capacitors have no polarity, so they can go either way round.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

const uint8_t SENSE_PIN = A0;
const uint8_t NOISE_PIN = 9;
const bool NOISE_ON = true;        // set false for the quiet baseline
const int N = 500;

void setup() {
  Serial.begin(115200);
  if (NOISE_ON) {
    pinMode(NOISE_PIN, OUTPUT);
    TCCR1B = (TCCR1B & 0xF8) | 0x01;   // Timer1 at about 31 kHz on D9
    analogWrite(NOISE_PIN, 128);       // a fast square wave next to the sense wire
  }
  Serial.println("mean  spread(max-min)  std");
}

void loop() {
  int lo = 1023, hi = 0;
  float mean = 0, m2 = 0;
  for (int i = 1; i <= N; i++) {
    int v = analogRead(SENSE_PIN);
    if (v < lo) lo = v;
    if (v > hi) hi = v;
    float d = v - mean;                // running mean and variance
    mean += d / i;
    m2 += d * (v - mean);
  }
  float sd = sqrt(m2 / (N - 1));
  Serial.print(mean, 1);
  Serial.print("   ");
  Serial.print(hi - lo);
  Serial.print("   ");
  Serial.println(sd, 2);
  delay(500);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

mean  spread(max-min)  std
205.0   2   0.56
205.0   2   0.53
205.0   2   0.56
205.0   2   0.54
205.0   2   0.55

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Quiet baselineSpread of only a few counts
Noise on, no capacitorA larger spread and std
Capacitor on A0The spread falls clearly
Second capacitor addedA little further improvement
Mean value throughoutStays near 512

If it does not work

No difference with noise on

Run the noise wire right alongside the A0 wire and twist them loosely.

Spread is large even with no noise

Check the resistors are firm in the breadboard.

Mean is not near 512

Check both resistors are 10 kilohms.

Nothing prints

Set 115200 baud in the monitor.

Capacitor seems to have no effect

Check both legs are in the right rows.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the decoupling capacitor noise lab?

Arduino Nano, Resistor 10 kΩ × 2, Ceramic Capacitor 100 nF × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the decoupling capacitor noise lab take to build?

About 60 minutes for a intermediate maker, in 7 steps.

How do I know the decoupling capacitor noise lab works?

Quiet baseline: Spread of only a few counts. Noise on, no capacitor: A larger spread and std. Capacitor on A0: The spread falls clearly.

No difference with noise on: what should I check?

Run the noise wire right alongside the A0 wire and twist them loosely.

Spread is large even with no noise: what should I check?

Check the resistors are firm in the breadboard.

Mean is not near 512: what should I check?

Check both resistors are 10 kilohms.

Nothing prints: what should I check?

Set 115200 baud in the monitor.