Sub topic 11
Noise, decoupling capacitors, and brownouts
This chapter assumes you can upload sketches, wire a breadboard, and read the earlier chapters on external motor power, a common ground, DC motor stall current, and flyback diodes. Here you will learn why a motor can reset or confuse an Arduino even when the wiring looks correct. You will also learn how to fix it with capacitors, better layout, and a few firmware habits.
Two different problems
Motors cause two separate kinds of trouble. They look alike from the outside, because both make the board misbehave, but the causes and fixes differ.
- Brownout: the supply voltage sags below what the microcontroller needs. A large current draw, such as a motor starting or stalling, pulls the voltage down through the resistance of wires, connectors, and the supply itself.
- Electrical noise: fast spikes and ripples ride on the supply and ground lines, or couple into signal wires. The voltage may average out fine but briefly goes wrong by hundreds of millivolts or more.
A brownout is a slow, large dip lasting milliseconds. Noise is a fast, small disturbance lasting microseconds. Different capacitors handle each.
Why motors make both
A brushed DC motor is a coil with a mechanical load. Three behaviors cause most of the trouble.
- Inrush current. A motor at rest has no back-EMF, so its current is limited only by winding resistance. A small hobby motor that draws 150 mA while running can pull 1 A or more for the first few milliseconds, and the same amount when stalled.
- Brush arcing. The brushes make and break contact with the commutator many times per revolution. Each break produces a small spark and a burst of high-frequency noise.
- Inductive spikes. When current through the winding is interrupted, as it is every PWM cycle, the coil pushes voltage in the opposite direction. The flyback diode handles the largest spike, but it does not remove everything.
Servos add their own pattern. A servo draws a surge when it starts moving or hits a load, and a cheap hobby servo can pull 500 mA to 1 A or more under stall.
How a brownout resets the board
The ATmega328P on an Uno has a brown-out detector, usually set to about 2.7 V on the Uno. If the chip's supply falls below that level, the chip resets and setup() runs again. The visible symptoms:
- The board restarts when the motor starts, or when a servo moves a large distance.
- The serial monitor prints your startup message repeatedly.
- An LED on pin 13 flashes briefly as the bootloader runs.
- Behavior depends on battery charge. Fresh batteries work and tired ones fail.
Sometimes the voltage sags only partly. The chip stays above the reset threshold but runs unreliably, so you see corrupted serial output, odd sensor readings, or an LCD showing garbage characters.
The sag happens in two places. If the motor shares a supply with the Arduino, the supply voltage drops directly. If the motor has its own supply, the sag can still travel through a shared ground wire or a long thin wire, because every wire has resistance and inductance.
Capacitors as local energy storage
A capacitor stores a small amount of charge close to where it is needed. When the supply voltage dips, the capacitor releases charge to fill the gap for a moment. When the voltage rises, it absorbs the excess. Placed close to the load, it acts as a tiny local battery that handles fast changes the distant supply cannot follow.
Two kinds are common in motor circuits, and they do different jobs.
| Capacitor | Typical value | Placement | Job |
|---|---|---|---|
| Ceramic (decoupling or bypass) | 100 nF (0.1 µF) | Across the motor terminals, and across the supply pins of each IC | Absorbs fast, high-frequency noise and brush spikes |
| Electrolytic (bulk) | 100 µF to 1000 µF | Across the motor supply near the motor or driver, and across the servo supply | Covers slower, larger dips from inrush current |
Use both together. The electrolytic is large but slow to respond to fast edges because of its internal inductance and resistance. The ceramic is small but fast. Together they cover a wide range of frequencies.
Placement rules
- Place capacitors as close as possible to the thing they protect. A capacitor on the far end of a 30 cm wire does little for fast noise.
- Electrolytic capacitors are polarized. The stripe on the body marks the negative lead. Connecting one backward can make it vent or burst. Also keep its voltage rating at least 1.5 to 2 times the supply voltage.
- For a small brushed DC motor, solder a 100 nF ceramic capacitor directly across the motor terminals, with leads as short as possible. Some builders also add one from each terminal to the motor case, but the single capacitor across the terminals is the standard first step.
- For servos, add 100 µF to 470 µF across the servo supply and ground, close to the servo connector or at the point where the servo power wire leaves the supply.
- Add a 100 nF ceramic capacitor between 5 V and GND close to the Arduino or sensor modules that misbehave.
Estimating how much capacitance helps
A capacitor supplies current according to I = C × (dV/dt). Rearranged, the voltage drop while it supplies a surge is approximately dV = I × t / C.
Suppose a servo surge draws an extra 500 mA for 10 ms and you want the rail to droop no more than 0.2 V from the capacitor alone:
C = I × t / dV = 0.5 A × 0.010 s / 0.2 V = 0.025 F = 25,000 µF
That is far more than you would normally add. It shows that capacitors cannot hide a long surge. They handle short spikes, and the supply must handle the sustained part. In practice, 470 µF to 1000 µF is a reasonable addition for a servo rail because it smooths the leading edge of the surge, and a supply with enough current does the rest.
Layout and wiring habits that reduce noise
Capacitors help, but wiring does more than most people expect.
- Use a star ground. Bring motor ground and logic ground together at one point, preferably at the supply, instead of chaining them. High motor current flowing through a ground wire that the Arduino also uses creates a voltage difference along that wire.
- Keep motor wires short and thick. Use a gauge appropriate for the current. Thin jumper wires and breadboard rails have noticeable resistance.
- Separate motor wires from signal wires. Do not bundle a PWM signal wire alongside a motor power wire. Twisting the motor's two wires together reduces radiated noise.
- Avoid the breadboard for motor current. The spring contacts in a breadboard add resistance and can be intermittent. Wire the high-current path with soldered or screw-terminal connections where you can.
- Power the motor from its own supply. Use a separate battery pack or regulated supply for the motor, with its ground tied to the Arduino ground, as in the earlier chapter.
Firmware habits that help
Software cannot fix a power problem, but it can reduce how hard the circuit gets hit.
- Ramp motor speed instead of jumping from 0 to full. A gradual ramp limits inrush current.
- Move servos in steps using the non-blocking approach from the earlier chapter, instead of commanding a large jump.
- Do not start several motors at the same instant. Stagger their start times so the surges do not add up.
- Attach servos late. Calling
servo.attach()makes the servo hold position and draw current. Attach it only when you need it, anddetach()it afterward if the load does not need holding.
The sketch below starts a motor gently. It uses the MOSFET wiring from the earlier chapter and also reports whether the last reset came from a brownout, which helps with diagnosis.
// Soft-start for a MOSFET-driven DC motor on pin 5.
// Wiring is the same as the low-side MOSFET circuit: gate resistor,
// 10k pull-down, flyback diode, external supply, common ground.
#include <avr/io.h>
const int MOTOR_PIN = 5;
const int TARGET_SPEED = 200;
void setup() {
Serial.begin(9600);
pinMode(MOTOR_PIN, OUTPUT);
// MCUSR records why the chip last reset. The bootloader on some boards
// clears it before your sketch runs, so this can read 0.
if (MCUSR & (1 << BORF)) {
Serial.println(F("Last reset: brown-out"));
} else if (MCUSR & (1 << EXTRF)) {
Serial.println(F("Last reset: reset button or serial upload"));
} else if (MCUSR & (1 << PORF)) {
Serial.println(F("Last reset: power on"));
} else {
Serial.println(F("Reset cause unknown (flag cleared by bootloader)"));
}
MCUSR = 0;
// Ramp up slowly to limit inrush current.
for (int speed = 0; speed <= TARGET_SPEED; speed += 5) {
analogWrite(MOTOR_PIN, speed);
delay(30);
}
}
void loop() {
// Motor runs at TARGET_SPEED. Other work goes here.
}Telling noise from brownout
A quick way to separate the two is to test one change at a time.
| Observation | Likely cause | First thing to try |
|---|---|---|
| Resets at the instant the motor starts | Brownout from inrush | Separate supply, bulk capacitor, soft start |
| Resets only under mechanical load | Stall current exceeds supply rating | Stronger supply, lower load |
| Random resets or glitches while the motor runs steadily | Noise from brushes | 100 nF across motor terminals, twisted motor wires |
| Sensor readings jump when the motor runs | Noise on ground or analog reference | Star ground, decoupling at the sensor, shorter wires |
| Works on USB, fails on battery | Battery cannot deliver the current | Fresh or higher-capacity pack |
| Works with motor unloaded, fails when it drives a load | Load current too high | Measure current, check supply rating |
An oscilloscope shows the supply rail directly. Without one, a multimeter in min/max mode may catch some dips, though it is too slow for microsecond spikes.
Common mistakes
- Placing a large capacitor on the Arduino 5 V pin and expecting it to fix a motor on the same supply. The motor supply is the weak point, so move the motor to its own supply.
- Using a capacitor with too low a voltage rating. A 6.3 V electrolytic on a 9 V rail will fail.
- Putting a large electrolytic directly across a supply that switches on suddenly. The charging current can be large for a moment. For normal hobby supplies this is acceptable, but it is one more reason to use a decent supply.
- Skipping the ceramic capacitor because the electrolytic is already there. The two cover different frequencies.
- Adding a capacitor across the motor but leaving long leads. The lead inductance cancels much of the benefit.
Exercise
A servo project resets the Arduino every time the servo starts to move. The servo and the Arduino share the same 5 V USB supply. Name two changes that should fix it and say what each one addresses.
Show answer
First, power the servo from its own external supply, rated for at least the servo's stall current, and connect its ground to the Arduino ground. This removes the servo's current surge from the Arduino's supply, so the voltage that powers the chip no longer sags below the brown-out threshold. Second, add a bulk electrolytic capacitor (about 470 µF to 1000 µF) across the servo supply and ground close to the servo. This covers the short surge at the start of movement so the supply rail sags less. Optionally, move the servo in small steps instead of large jumps to reduce the surge.
Exercise
You solder a 100 nF ceramic capacitor across a DC motor's terminals, but the board still resets when the motor starts. Why was the capacitor not enough, and what would you add or change?
Show answer
A 100 nF ceramic capacitor handles fast, high-frequency brush noise. It stores too little charge to cover the large, slower current surge when the motor starts. The reset points to a brownout, which needs a bulk electrolytic capacitor on the motor supply (100 µF to 1000 µF), a supply that can deliver the motor's stall current, and a soft start that ramps the PWM value up gradually.