Circuit cookbook
Twenty-two popular small circuits, each with a schematic, a plain explanation, the formulas with a live calculator, typical values, common mistakes and a breadboard note.
Each circuit has a schematic, how it works, the formulas with a small live calculator, typical values, common mistakes and a breadboard note. Type values with prefixes: 4.7k, 100n, 10u, 2M2 (lower-case m is milli, capital M is mega). Everything runs in this page; nothing is sent anywhere.
Voltage divider
RC low-pass and high-pass filter
Diode rectifier with smoothing capacitor
Linear regulator: 78xx and LM317
BJT transistor as a switch
MOSFET as a low-side switch
Relay driver with flyback diode
H-bridge motor driver
555 timer astable blinker
Op-amp circuits: inverting, non-inverting, buffer, comparator
Schmitt trigger (the idea)
Pull-up, pull-down and switch debounce
I2C pull-ups
Level shifter (BSS138 style)
LDR and thermistor dividers
RC snubber (the idea)
Crystal oscillator load capacitors
Power-supply decoupling
Reverse-polarity protection
ESD and TVS protection (note)
Constant-current LED driver
LED with a series resistor
How it works
An LED is a diode: past its forward voltage the current rises very steeply, so you must limit the current from outside. The series resistor drops the leftover supply voltage and sets the current by Ohm's law. Without it the LED (or the pin driving it) can burn out in a fraction of a second.
Formulas
R = (Vs − Vf) / If. Resistor power P = If² · R. Pick the next standard value at or above R.
Typical values
Vf is about 1.8-2.2 V for red/yellow/green and 3.0-3.4 V for blue/white (typical; datasheet governs). If is 2-20 mA for indicators; 5 V supply, red LED, 10 mA: R = 3.0 V / 10 mA = 300 Ω, use 330 Ω.
Common mistakes
No resistor at all; one resistor shared by LEDs in parallel (they never share current equally, give each its own); using Vf of the wrong colour; forgetting that a microcontroller pin can supply only a limited current (often 20 mA or less, check the datasheet).
Build it on a breadboard
Battery or 5 V from a USB breakout, then the resistor, then the LED long leg (anode) on the resistor side and the short leg (cathode) to ground. If it does not light, turn the LED around.
Voltage divider
How it works
Two resistors in series across a voltage give a fraction of it at the middle point. The fraction is R2 / (R1 + R2). It scales a voltage down for a measuring input, and sets bias points. Anything you connect to the output loads the lower resistor and lowers the voltage.
Formulas
Vout = Vin · R2 / (R1 + R2). With a load RL: replace R2 by R2 ∥ RL = R2·RL / (R2 + RL).
Typical values
Resistors of 10 kΩ to 100 kΩ for signals. Make the load at least 10 times R2. 12 V to 5 V: R1 = 14 kΩ, R2 = 10 kΩ ideal; 15 kΩ and 10 kΩ give 4.8 V.
Common mistakes
Using a divider to power something (it cannot supply current without the voltage collapsing); ignoring the input impedance of the thing being measured; using 1% resistors and expecting better than 1% accuracy overall.
Build it on a breadboard
Two resistors in series in the same column strip, supply on the top end, ground on the bottom, and the output taken from the shared row. Measure it with a multimeter before connecting the load.
RC low-pass and high-pass filter
How it works
A resistor and a capacitor form a first-order filter. In the low-pass the capacitor to ground shorts high frequencies away, so low frequencies pass. In the high-pass the series capacitor blocks low frequencies and DC. Both have the same corner (cutoff) frequency, where the signal is 3 dB (70.7%) down.
Formulas
fc = 1 / (2π · R · C). Gain: low-pass 1/√(1 + (f/fc)²), high-pass (f/fc)/√(1 + (f/fc)²). Roll-off is 20 dB per decade above (low-pass) or below (high-pass) the corner.
Typical values
10 kΩ and 100 nF: fc = 159 Hz. 1 kΩ and 100 nF: 1.59 kHz. Keep R well above the source impedance and well below the load impedance.
Common mistakes
Forgetting the source and load resistances shift the corner; expecting a sharp cutoff from one stage (it is gentle); using a polarised capacitor in a high-pass with a signal that goes negative.
Build it on a breadboard
Signal generator or phone audio into R, capacitor from the output node to ground. Use headphones, a small speaker with an amplifier, or an oscilloscope to hear or see the filter work.
Diode rectifier with smoothing capacitor
How it works
A diode passes current one way only. A half-wave rectifier keeps one half of each AC cycle. A bridge of four diodes keeps both halves, so the ripple is twice the line frequency. A large capacitor charges to the peak and supplies the load between peaks; the smaller the ripple wanted, the bigger the capacitor.
Formulas
Peak after the diodes Vpk = Vac(rms) · √2 − (diode drops: 1 half-wave, 2 for a bridge, each about 0.7 V). Ripple ≈ I / (fripple · C), fripple = f (half-wave) or 2f (bridge). Capacitor for a wanted ripple: C = I / (fripple · Vripple). This estimate ignores the diode conduction time and the source impedance, so it is a reasonable upper estimate.
Typical values
12 V AC adapter output, bridge, 0.5 A load, 50 Hz: 4700 µF gives about 1.06 V ripple. Diode peak current is much higher than the average load current; use diodes rated for several times the load current (1N4001/1N4007 for 1 A class).
Common mistakes
Do not build this from mains. Use a certified, sealed low-voltage AC adapter or transformer secondary; mains wiring is outside what these pages cover. Wrong electrolytic polarity (it can burst); a capacitor with too low a voltage rating (rate it at least 25% above the peak); no heat allowance for the diodes.
Build it on a breadboard
Bridge and capacitor on a breadboard from a small AC adapter of 12 V AC or less only (check the label says AC). Observe the capacitor polarity stripe, and discharge it through a resistor afterwards.
Linear regulator: 78xx and LM317
How it works
A linear regulator keeps its output steady by burning the excess voltage as heat. The 78xx family (7805, 7812 ...) has a fixed output. The LM317 is adjustable: it holds 1.25 V between OUT and ADJ, so a resistor pair sets the output. Both need an input a couple of volts above the output (dropout; read the datasheet) and small capacitors close to the pins.
Formulas
LM317: Vout = 1.25 · (1 + R2 / R1) (+ Iadj · R2, where Iadj is about 50 µA and usually ignored). R2 = R1 · (Vout / 1.25 − 1). Heat: P = (Vin − Vout) · I.
Typical values
R1 = 240 Ω (a common choice; 120 Ω to 240 Ω works). R1 = 240 Ω, R2 = 720 Ω: 5.0 V. 78xx input capacitor 0.33 µF, output 0.1 µF are common datasheet values. Typical dropout 2 V for the 78xx and 2-3 V for the LM317 (datasheet governs).
Common mistakes
Input only just above the output (it drops out); too much heat without a heatsink (P above 1 W needs attention); swapped pins (the 78xx and LM317 have different pin orders); a big output capacitor with no protection diode on a high input.
Build it on a breadboard
Only for a low current and small voltage drop on a breadboard, as the pins and contacts are thin. Measure the output unloaded first, then add the load. Check the pin order in the datasheet before powering.
BJT transistor as a switch
How it works
A small current into the base of an NPN transistor lets a much larger current flow from collector to emitter. Used as a switch it is driven hard on (saturated) or fully off. Drive the base with about one tenth of the collector current ('forced beta' of 10) so it saturates reliably whatever its real gain.
Formulas
Ib = Ic / 10. Rb = (Vdrive − 0.7 V) / Ib. Check dissipation: P ≈ Vce(sat) · Ic (about 0.2 V times Ic).
Typical values
Small NPN (BC547, 2N2222, 2N3904): Ic up to about 100-800 mA depending on the part. 100 mA load from a 5 V logic pin: Ib = 10 mA, Rb = 430 Ω; 390 Ω is the next standard value down.
Common mistakes
Leaving out the base resistor; treating the beta on the datasheet as guaranteed; wrong pin order (it differs between makers, check the datasheet); switching an inductive load (relay, motor) with no flyback diode.
Build it on a breadboard
Pin order first: with the flat side facing you and the legs down, BC547 is typically C, B, E, but 2N2222 plastic parts are often E, B, C. Verify with the datasheet or a diode test on the multimeter.
MOSFET as a low-side switch
How it works
An N-channel MOSFET switches the load's ground side. The gate takes almost no current once charged; the voltage between gate and source (Vgs) decides if the channel is on. Use a logic-level MOSFET if you drive it from 3.3 V or 5 V, and make sure Rds(on) is specified at your gate voltage. A pull-down resistor keeps it off when the driver pin floats.
Formulas
Conduction loss P = I² · Rds(on). Gate rise (rough) ≈ 2.2 · Rg · Ciss. Gate resistor 10-100 Ω to limit ringing; pull-down 10-100 kΩ.
Typical values
10 A through 10 mΩ: 1 W, so a heatsink or a lower resistance part. Check Vgs(th) is not the turn-on voltage: the part is only fully on at the Vgs where Rds(on) is quoted.
Common mistakes
A non-logic-level MOSFET on a 3.3 V pin (barely on, gets hot); no pull-down (switch-on at power-up); inductive load with no diode; static damage from handling (touch ground first).
Build it on a breadboard
Use a through-hole logic-level part (check the datasheet pin order, often G, D, S from the left but not always). Gate resistor close to the gate, load from supply to drain, source to ground.
Relay driver with flyback diode
How it works
A relay coil is an inductor. When the transistor switches it off, the collapsing magnetic field forces the current to continue and produces a large voltage spike that can destroy the transistor. A diode across the coil, cathode to the supply side, gives that current a path and clamps the spike. The relay contacts are electrically separate from the coil circuit.
Formulas
Coil current Icoil = Vcoil / Rcoil. Base resistor from the BJT page with Ic = Icoil. Diode: reverse voltage above the supply voltage, current above the coil current (1N4148 for small coils, 1N4007 is common).
Typical values
5 V relay with a 70 Ω coil: 71 mA, so Rb about 430 Ω from a 5 V pin with beta 10 (use 390 Ω). 12 V relay with 400 Ω coil: 30 mA.
Common mistakes
Diode the wrong way round (it shorts the supply); no diode; driving the relay straight from a microcontroller pin; connecting any wiring above low voltage to the relay contacts on a breadboard. Switching mains with a relay is outside these pages: use a certified, enclosed module and a qualified person.
Build it on a breadboard
Use a relay with a coil rated for your supply; test the coil circuit alone, listen for the click, and only switch low-voltage things such as an LED or a small buzzer on the contacts.
H-bridge motor driver
How it works
Four switches around a motor let you reverse it. Close S1 and S4 and current flows A to B; close S3 and S2 and it flows B to A. Close both low switches (or both high switches) to brake. The one forbidden state is a high and a low switch of the same leg on together: that is a direct short across the supply ('shoot-through').
Formulas
Stall current Istall = Vs / Rwinding. Shoot-through current ≈ Vs / (Ron,high + Ron,low), limited only by the switches. Real drivers add dead time between turning one switch off and the other on.
Typical values
Use a ready-made driver IC or module (L293D, L298N, DRV8833 and similar) for small motors; read its datasheet for current and voltage limits. A 12 V motor with 2 Ω winding stalls at 6 A; with two 50 mΩ switches a shoot-through is 120 A.
Common mistakes
Building it from discrete parts with both gate signals active at once; no flyback protection (some driver ICs such as the L293D include clamp diodes, others such as the L298 need external ones; check); undersized supply; motor noise resetting the microcontroller (separate wiring, decoupling capacitor on the motor).
Build it on a breadboard
Start with a driver module, motor on its own supply, a common ground with the controller, and a current-limited bench supply if you have one.
555 timer astable blinker
How it works
The 555 charges a capacitor through R1 + R2 up to 2/3 of the supply, then discharges it through R2 down to 1/3, over and over. The output is high while charging and low while discharging, so the duty cycle is always above 50% (put a diode across R2 to get closer to 50%). Pin 5 (control) can take a 10 nF capacitor to ground for noise immunity.
Formulas
f = 1 / (ln 2 · (R1 + 2·R2) · C) ≈ 1.44 / ((R1 + 2·R2) · C). High time = ln 2 · (R1 + R2) · C. Low time = ln 2 · R2 · C. Duty = (R1 + R2) / (R1 + 2·R2). Monostable: t = 1.1 · R · C.
Typical values
R1 = 1 kΩ, R2 = 10 kΩ, C = 10 µF: about 6.9 Hz, duty 52%, a nicely visible blink. R values 1 kΩ to 1 MΩ; supply 4.5 V to 16 V for the bipolar NE555 (CMOS parts from 1.5 V; datasheet governs).
Common mistakes
Reset (pin 4) left floating (tie it to +V); R1 too small, so the discharge pin sees excess current; using an electrolytic capacitor for high-precision timing (leakage and tolerance); expecting 50% duty from the basic circuit.
Build it on a breadboard
DIP-8 across the breadboard centre gap: pin 1 GND, 2 TRIG, 3 OUT, 4 RESET, 5 CTRL, 6 THR, 7 DISCH, 8 VCC. Join 2 and 6 together. Output to a resistor and LED to ground.
Op-amp circuits: inverting, non-inverting, buffer, comparator
How it works
With negative feedback an op-amp adjusts its output until its two inputs are at the same voltage; the gain is then set by the resistor ratio. Inverting amplifier: input and feedback resistors meet at a 'virtual ground'. Non-inverting: gain is at least 1. Buffer: gain of 1 with a very high input and low output impedance. A comparator has no feedback: the output swings towards the supply rail on whichever input is higher. (Power pins are not drawn.)
Formulas
Inverting: G = −Rf / Rin. Non-inverting: G = 1 + Rf / Rg. Buffer: G = 1. Comparator: Vout is high if V+ > V−. The output cannot exceed the supply minus the amplifier's headroom; single-supply parts (LM358) cannot swing exactly to ground or to the rail.
Typical values
Rin 10 kΩ and Rf 100 kΩ: gain −10. Non-inverting Rg 1 kΩ, Rf 9 kΩ: gain 10. Resistors 1 kΩ to 1 MΩ. Use a real comparator (LM393) for fast comparing with open-collector output and a pull-up.
Common mistakes
Forgetting the supply pins; using an op-amp as a comparator in a fast or noisy application without hysteresis; exceeding gain-bandwidth limits (gain 100 at 100 kHz needs 10 MHz); rail-to-rail assumptions on a part that is not.
Build it on a breadboard
LM358 (dual, DIP-8): pin 8 V+, pin 4 V−/GND, op-amp A on pins 1 (out), 2 (−in), 3 (+in). Start with the buffer to see 1:1 following.
Schmitt trigger (the idea)
How it works
A Schmitt trigger has two thresholds instead of one: the input must rise above an upper threshold to switch the output one way, and fall below a lower one to switch it back. The gap is hysteresis, and it stops a slow or noisy signal from making the output chatter. It is made by feeding part of the output back to the positive input. Logic gates with Schmitt inputs (74HC14, 74HC132) do the same in one chip.
Formulas
With Ra from the + node to the reference Vref, and Rb from the + node to the output: threshold = (Vref · Rb + Vout · Ra) / (Ra + Rb), evaluated with Vout at its high and low levels. Hysteresis = (Vhigh − Vlow) · Ra / (Ra + Rb).
Typical values
Ra 10 kΩ, Rb 100 kΩ, outputs ±12 V, Vref 0 V: thresholds ±1.09 V (hysteresis 2.18 V). Real op-amp outputs fall short of the rails by a volt or so; enter the real output levels.
Common mistakes
Using an ordinary op-amp as a slow comparator (it oscillates around the threshold); wrong feedback polarity (positive feedback goes to the + input); thresholds that lie outside the input's range.
Build it on a breadboard
Build with a LM358 or LM393 (with a pull-up) and feed a slow triangle or a potentiometer wiper; watch the output with an LED to see it snap at two different levels.
Pull-up, pull-down and switch debounce
How it works
A logic input left unconnected floats and picks up noise. A pull-up resistor ties it to +V, a pull-down to ground; the switch then pulls it to the opposite level when pressed. Mechanical switches bounce for a few milliseconds, creating several edges. Fix it in hardware with a capacitor across the switch (RC filter, ideally into a Schmitt input), or in software by ignoring changes for 10-50 ms after the first edge.
Formulas
Current when pressed I = Vcc / R. Debounce time constant τ = R · C; the capacitor reaches a fraction x of Vcc in t = −τ · ln(1 − x). Wait about 5τ to settle.
Typical values
10 kΩ for pull-ups on logic inputs (4.7 kΩ-47 kΩ). R = 10 kΩ, C = 100 nF: τ = 1 ms, and a 70% threshold is reached after 1.2 ms. Internal pull-ups in microcontrollers are often 20-50 kΩ; check the datasheet.
Common mistakes
Floating inputs; a pull-up and pull-down both present; a debounce capacitor that discharges through the switch with no series resistor (a spark and a current spike when it closes); in software, a blocking delay that stops everything else.
Build it on a breadboard
Use the board's internal pull-up in code and wire only the button to ground. For software debounce: on a pin change, record the time, and accept the new state only after it has been stable for about 20 ms.
I2C pull-ups
How it works
I2C uses two wires, SDA and SCL, which every device only ever pulls low. Pull-up resistors to the supply bring them high again. The resistors must be small enough to charge the wire's capacitance in time, and large enough that the devices can still pull the line low. Usually only one set of pull-ups is needed on the whole bus.
Formulas
Rise time (30% to 70%) tr = 0.8473 · Rp · Cb. Maximum Rp = tr(max) / (0.8473 · Cb). Minimum Rp = (Vdd − 0.4 V) / 3 mA. Spec rise-time limits: 1000 ns (100 kHz), 300 ns (400 kHz), 120 ns (1 MHz).
Typical values
Cb = 100 pF at 400 kHz: Rp maximum 3.5 kΩ; at 3.3 V the minimum is 967 Ω. 2.2 kΩ to 4.7 kΩ is typical. Many breakout boards already carry pull-ups; stacked boards give a parallel (lower) value.
Common mistakes
No pull-ups at all; pull-ups to 5 V with a 3.3 V device (use one voltage or a level shifter); too many boards each with their own 10 kΩ; very long wires (capacitance).
Build it on a breadboard
SDA and SCL from the controller to each device, a common GND, pull-up resistors from each line to the logic supply. On an Arduino Uno SDA is A4 and SCL is A5.
Level shifter (BSS138 style)
How it works
A bidirectional shifter for open-drain buses such as I2C uses one small N-MOSFET (BSS138, for example) per line. Gate to the low voltage, source to the low-voltage line, drain to the high-voltage line, and a pull-up on each side. If the low side pulls down, the transistor turns on and pulls the high side down; if the high side pulls down, the body diode and then the channel pull the low side down. Both sides idle high through their own pull-up.
Formulas
Each side behaves like an I2C line: rise time tr = 0.8473 · Rp · C. Use pull-ups of 2.2 kΩ to 10 kΩ on both sides.
Typical values
3.3 V to 5 V, 4.7 kΩ-10 kΩ pull-ups, one shifter per signal. It suits open-drain and slow push-pull signals; for fast SPI use a dedicated level-shifter IC.
Common mistakes
Gate tied to the wrong side; missing pull-up on one side; using it for fast push-pull signals; forgetting the common ground.
Build it on a breadboard
Ready-made 4-channel breakout boards are cheap and avoid pin-order mistakes. Check which side is LV and which HV on the board silkscreen.
LDR and thermistor dividers
How it works
A light-dependent resistor (LDR) or an NTC thermistor changes its resistance with light or temperature. Placed in a voltage divider with a fixed resistor, the changing resistance becomes a changing voltage that an ADC pin can read. The NTC resistance falls as temperature rises; the Beta equation describes it over a modest range.
Formulas
Divider as before: Vout = Vcc · Rlow / (Rhigh + Rlow). NTC (Beta equation, T in kelvin): R(T) = R0 · exp(B · (1/T − 1/T0)); T = 1 / (1/T0 + ln(R/R0)/B). Use the fixed resistor equal to the NTC value at the middle of your range for the best sensitivity.
Typical values
10 kΩ NTC, B = 3950 K (many hobby parts), R0 at 25 °C. At 50 °C: about 3.59 kΩ. The Beta model is an approximation (good to a degree or so over tens of degrees); use the Steinhart-Hart coefficients from the datasheet for more accuracy. LDR values vary widely from part to part.
Common mistakes
Self-heating of the NTC by too much current (use a high enough fixed resistor, or read it only briefly); mixing up 25 °C and 0 °C reference points; assuming all LDRs behave alike; ADC reference noise.
Build it on a breadboard
NTC in series with a 10 kΩ resistor between 3.3 V and ground; ADC on the middle node. Warm the NTC with your fingers and watch the voltage change.
RC snubber (the idea)
How it works
When a switch opens on an inductive load, or a fast edge hits stray inductance and capacitance, the node can ring or spike. A resistor and capacitor in series across the switch (or across a diode or contact) absorbs that energy and damps the ringing. Common design method: measure the ringing frequency, add a known capacitor to lower it, and use the two frequencies to find the stray capacitance and inductance; then Rs = √(L/C) and Cs about 3 times the stray C (rule of thumb).
Formulas
Stray C: Cp = Cadd / ((f1/f2)² − 1). Stray L: Lp = 1 / ((2π · f1)² · Cp). Rs = √(Lp / Cp). Cs ≈ 3 · Cp. Power in the snubber P ≈ Cs · V² · f(switching).
Typical values
Ring of 100 MHz that drops to 50 MHz with 300 pF added: Cp = 100 pF, Lp = 25 nH, Rs about 16 Ω, Cs about 300 pF. For relay contacts or motors, ready-made RC snubber parts exist; check their ratings.
Common mistakes
Skipping the resistor (a bare capacitor makes the current spike on closing); a resistor of too low a power rating; using it as the only protection on a relay coil (use the flyback diode); applying it to mains contacts without a rated, approved part.
Build it on a breadboard
Needs an oscilloscope to tune properly. Without one, fit the calculated values and compare the behaviour with and without the snubber in place.
Crystal oscillator load capacitors
How it works
A crystal oscillates at its stated frequency only when it sees the load capacitance the maker specifies (CL). Two capacitors, one from each crystal pin to ground, plus the stray capacitance of the board and chip pins, add up to CL in series. Wrong values pull the frequency off by some parts per million, or in extreme cases stop the oscillator starting.
Formulas
CL = (C1 · C2) / (C1 + C2) + Cstray. With C1 = C2 = C: CL = C/2 + Cstray, so C = 2 · (CL − Cstray).
Typical values
CL = 12 pF, Cstray about 3 pF (a typical guess; 2-5 pF): C1 = C2 = 18 pF. 8 MHz-16 MHz crystals commonly use 12-22 pF capacitors; CL is in the crystal's datasheet.
Common mistakes
Using the crystal's CL as the capacitor value; ignoring stray capacitance; long traces to the crystal; using a 32.768 kHz watch crystal with the wrong drive level.
Build it on a breadboard
Better built on a PCB with short traces. On a breadboard keep the crystal and capacitors right next to the chip pins and expect a little frequency error.
Power-supply decoupling
How it works
Digital chips draw current in sharp bursts on each clock edge. The supply wiring has inductance, so without a nearby reservoir the supply dips for a moment. A 100 nF ceramic capacitor next to each supply pin supplies those bursts locally; a larger capacitor (1-100 µF) nearby handles slower changes. Together they keep the chip supply steady and keep noise off the rest of the board.
Formulas
Capacitor to hold up a burst: C = I · Δt / ΔV. Impedance at a frequency: Xc = 1 / (2π · f · C) (a real capacitor also has ESL, so it stops helping above its self-resonant frequency; smaller values reach higher).
Typical values
A 50 mA burst of 10 ns with 50 mV allowed droop: 10 nF. Practical rule: 100 nF per supply pin as close as possible, plus 1-10 µF per few chips or per board section.
Common mistakes
Capacitor far from the pin (the wire inductance defeats it); a single large capacitor for the whole board; polarity of electrolytics; relying on a tiny breadboard where long jumpers add inductance.
Build it on a breadboard
Plug a 100 nF ceramic capacitor directly between the chip's VCC and GND rows with short legs. Add a larger electrolytic near where power enters the board.
Reverse-polarity protection
How it works
Connecting a battery or adapter the wrong way round can destroy a circuit. A series diode blocks the reverse current but wastes about 0.7 V (Schottky about 0.3 V) and dissipates power equal to Vf times the current. A P-channel MOSFET in the positive line, with its gate to ground, conducts when the polarity is right and has an on-resistance of a few milliohms, so it wastes almost nothing. The body diode is oriented so the reverse voltage is blocked.
Formulas
Diode loss P = Vf · I. P-MOSFET loss P = I² · Rds(on). The gate voltage is −Vsupply relative to the source, so Vsupply must stay below the MOSFET's maximum Vgs (often 20 V); add a zener and resistor from gate to source if the supply is higher.
Typical values
2 A: a 1N5819-type Schottky diode (Vf about 0.4-0.5 V, datasheet) wastes roughly 0.9 W; a P-MOSFET with 20 mΩ wastes 0.08 W. Pick a MOSFET with Rds(on) specified at a Vgs close to your supply voltage.
Common mistakes
Putting the P-MOSFET in backwards (the body diode then conducts the wrong way); using it above its Vgs limit; omitting the protection on a plug-in supply that someone will eventually reverse.
Build it on a breadboard
Try the diode version first. For the MOSFET version, test with a current-limited supply, and check the drain-source orientation in the datasheet.
ESD and TVS protection (note)
How it works
Static discharge and cable-induced spikes can destroy inputs. A TVS (transient voltage suppressor) diode connected from the signal line to ground stays off in normal use and clamps hard when the voltage exceeds its standoff voltage. A series resistor limits the current that the clamp and the pin must absorb. Keep the protection close to the connector, with a short, solid ground path.
Formulas
Choose a standoff voltage at or above the highest normal signal voltage; the clamping voltage at the peak current must stay below the protected pin's absolute maximum. Series R limits current: I = (Vspike − Vclamp) / R.
Typical values
A 5 V line: TVS with 5 V standoff (e.g. an SMF5.0A-type part), 100 Ω-1 kΩ series resistor where the signal allows it. Capacitance matters for fast data lines; use low-capacitance ESD arrays for USB and similar.
Common mistakes
Protection placed after the long trace instead of at the connector; a TVS with a standoff voltage below the signal's normal level (it conducts constantly); ignoring the ground return; assuming it protects against mains.
Build it on a breadboard
Not usually breadboarded; this belongs on the PCB at the connector. See the PCB guide for layout hints.
Constant-current LED driver
How it works
A resistor makes a poor current source if the supply varies. An LM317 can regulate current instead of voltage: it holds 1.25 V across the resistor between OUT and ADJ, so the current through that resistor (and the LED in series with it) is fixed. A simple two-transistor circuit does the same with about 0.65 V (one Vbe) across the sense resistor.
Formulas
LM317: I = 1.25 V / Rset, P(Rset) = 1.25 V · I. Transistor sense: I = Vbe / Rsense, Vbe about 0.6-0.7 V. Minimum supply = (LEDs in series × Vf) + 1.25 V + dropout (about 2 V; datasheet).
Typical values
20 mA: Rset = 62.5 Ω (62 Ω, E24), dissipating 25 mW. 350 mA for a power LED: 3.57 Ω and 0.44 W, so use a 1 W resistor. Current limit of the LM317 is 1.5 A but heat limits you first.
Common mistakes
Supply too low for the LED string plus 3 V or so; no heatsink at high current; wiring the LED between OUT and the resistor instead of after it; very low-current LEDs (the LM317 needs a minimum load of about 3.5-10 mA; datasheet).
Build it on a breadboard
Adjust Rset with a resistor decade box or a few parallel resistors while measuring the current with a multimeter in series. Start with a low current.
Circuits and values are textbook starting points for low-voltage hobby electronics; verify against the datasheets of the parts you use. The person building the circuit is responsible for its safety.
Ruggi.Site