Worked Projects
Four complete small designs with parts calculated from the theory: an LED driver, a battery-powered sensor node, a motor controller and a 5 V supply.
How to use these projects
Four complete designs, each worked through the way a real design is: requirements, a block diagram, the calculation of every key value, a bill of materials, what to check on the bench and what to change if it does not work. They use the ideas from the rest of Design, Testing and Troubleshooting (resistors, regulators, transistors, switching converters and datasheets). Every number below is computed from the stated inputs; change the inputs, redo the arithmetic and you have your own design.
| Project | Skills | Parts | Difficulty |
|---|---|---|---|
| 1. LM317 LED driver | Linear regulator, constant current, power dissipation | About 5 | Easy |
| 2. Sensor node | Low power, sleep, divider sensors, battery life | About 10 | Moderate |
| 3. Motor controller | MOSFET driver, PWM, flyback, thermal | About 10 | Moderate |
| 4. Buck supply | Switching converter, inductor and capacitor sizing, protection | About 15 | Harder |
Project 1: constant-current LED driver with an LM317
Requirement: drive 2 white LEDs in series (forward voltage about 3 V each) at 20 mA from a 12 V supply, with a current that does not change with the supply or the LEDs’ voltage. An LM317 can be used as a current source: it holds 1.25 V between OUT and ADJ, so a single resistor R sets the current I = 1.25 V ÷ R (see Power Electronics: Buck, Boost and Thermal Design and the LM317 Calculator).
Design calculation
- Resistor: R = 1.25 ÷ 0.020 A = 62.5 Ω. The nearest standard E24 value is 62 Ω, which gives I = 1.25 ÷ 62 = 20.2 mA (about 1 percent over).
- Resistor power: P = I² × R = 0.020² × 62 = 0.025 W; a 0.25 W resistor has ample margin.
- Voltage needed: the LEDs take 2 × 3 = 6 V, the sense resistor drops 1.25 V and the LM317 needs about 2 V of headroom, so the supply must be at least 9.25 V. At 12 V the margin is 2.75 V.
- Regulator heat: the LM317 drops 4.75 V at 20.2 mA: P = 0.096 W, trivial in a TO-220 even without a heat sink (T rise about 6.2 °C at 65 °C/W).
- Efficiency: the LEDs get 0.12 W of the 0.24 W drawn from the supply: 50 percent. A linear driver wastes the rest; that is fine for a small lamp, not for a high-power one.
| Part | Value | Note |
|---|---|---|
| U1 | LM317T (TO-220) or LM317 in SOT-223 | Heat sink optional at this power |
| R1 | 62 Ω, 1 percent, 0.25 W | Between OUT and ADJ: sets the current |
| C1 | 0.1 µF ceramic at the input | Close to the regulator |
| C2 | 1 µF at the output (optional) | For stability with long wires; keep small so the LEDs start quickly |
| LEDs | 2 white, 20 mA, in series | More LEDs in series raise the voltage needed; use separate strings for more current |
| Fuse / connector | 100 mA polyfuse, 2-pin header | Optional protection |
- Check: measure across R1: it should be 1.25 V (1.2–1.3 V). Measure the LED current by the drop across R1 ÷ 62 Ω, or insert a meter. Vary the supply from 10 V to 15 V: the current should barely move.
- Dimming: use a PWM-driven transistor in series with the LEDs, not by changing R.
- Change it: for 350 mA (a power LED) R = 3.6 Ω, but then R dissipates 0.44 W and the LM317 drops more power: this needs a heat sink or a buck LED driver.
Project 2: battery-powered sensor node
Requirement: send a temperature reading every minute for as long as possible from one 2 000 mAh lithium cell. The design rule is that almost all the time the node must draw almost nothing: the sleeping current and the regulator’s own quiescent current set battery life, not the active burst.
Power budget
- Duty cycle: awake for 100 ms every 60 s: D = 100 ÷ 60 000 = 0.167 percent.
- Average current: 40 mA × D + 10 µA × (1 − D) = 76.7 µA, plus 1 µA LDO quiescent = 77.7 µA.
- Battery life: 2 000 mAh × 0.8 usable ÷ 0.078 mA = 20 605 hours = 859 days (2.4 years), before self-discharge and temperature effects.
- Sensor divider: a 10 kΩ NTC thermistor with a 10 kΩ resistor from 3.3 V gives 1.65 V at 25 °C and draws 165 µA while on. Left on permanently it would add 165 µA, thirteen times the whole budget. Powered from a microcontroller pin only during the 100 ms measurement it averages 0.28 µA.
- Check the numbers: the sleep current (10 µA) and the LDO’s quiescent current (1 µA) together are 11 µA of the 77.7 µA: the burst is 67 µA. Reducing the burst (a shorter on-time or a faster radio) changes life far more than a lower sleep current would.
| Part | Choice | Why |
|---|---|---|
| Cell | 18650 or 14500 Li-ion with protection, or a primary lithium cell | High capacity; primary lithium holds its voltage and shelf life |
| Regulator | LDO with 1 µA quiescent current, 3.3 V | The regulator’s own current counts all the time |
| Microcontroller | Low-power part with deep sleep and RTC wake-up | Sleep current in the microamps |
| Sensor | NTC thermistor and 10 kΩ divider, powered from a pin | Zero current while asleep |
| Radio | Low-power module (BLE, LoRa or sub-GHz) | Fast transmit, then off |
| Decoupling | 100 nF at each pin, 10 µF at the radio supply | The radio draws sharp pulses; see EMC and Noise at Board Level |
- Check: measure the sleeping current with a µA-range meter (or a series resistor and scope), not the average; many boards show 100 µA from a leaking part (a pull-up fighting a sensor, an LED, a regulator’s enable pin).
- Common faults: a floating input drawing current, the sensor divider left on, a debug LED, a USB-serial chip powered from the battery.
- Change it: reporting every 10 minutes instead of every minute cuts the burst current tenfold; life is then limited by sleep current and self-discharge.
Project 3: PWM motor controller
Requirement: control the speed of a small 12 V DC motor drawing up to 2 A, from a 3.3 V microcontroller, in one direction. The circuit is a low-side logic-level N-channel MOSFET switched with PWM at 20 kHz, a flyback diode across the motor, and a gate resistor with a pull-down (see Driving Motors and Actuators and Transistors).
Design calculation
- MOSFET choice: logic-level (specified at 2.5 or 4.5 V), 30 V or higher, RDS(on) of 20 mΩ at 4.5 V. Check the datasheet curve at 3.3 V gate drive (see Reading Datasheets).
- Conduction loss: P = I² × RDS(on) = 2² × 0.02 = 0.08 W. With θJA = 62 °C/W in a small package: junction at 50 °C ambient is 50 + 0.08 × 62 = 55 °C, safe.
- Average motor voltage: at a duty cycle of 60 percent the motor sees on average 12 × 0.6 = 7.2 V.
- Gate drive: Qg = 20 nC. At 20 kHz the average gate current is Qg × f = 0.40 mA, easily supplied by a pin. A 47 Ω gate resistor limits the peak current to 3.3 V ÷ 47 Ω = 70 mA and slows the edges (reducing noise).
- Pull-down: 10 kΩ from gate to ground, so that the motor is off while the microcontroller resets.
- Flyback diode: when the MOSFET turns off, the motor’s inductance keeps the current flowing. A Schottky diode (3 A, 40 V) across the motor carries it: its loss is about VF × I × (1 − D) = 0.5 × 2 × 0.4 = 0.40 W. Without it, the voltage spike destroys the MOSFET.
- Bulk capacitor: 100–470 µF across the motor supply and 100 nF across the motor terminals suppress brush noise.
| Part | Value | Note |
|---|---|---|
| Q1 | Logic-level N-MOSFET, 30 V, 20 mΩ at 4.5 V | For example in SOT-23 (small motors) or DPAK/SO-8 (2 A) |
| D1 | Schottky, 3 A, 40 V | Across the motor; cathode to +12 V |
| R1 | 47 Ω | Gate series resistor |
| R2 | 10 kΩ | Gate pull-down |
| C1 | 220 µF, 25 V electrolytic + 100 nF ceramic | Motor supply decoupling |
| F1 | 3 A fuse | Supply protection |
- Check: scope the drain: a clean square wave from 0 to 12 V with a small overshoot. Touch the MOSFET after a minute at full load: it should be warm, not too hot to hold.
- Common faults: motor does not stop (no pull-down or gate floating), MOSFET hot (gate drive too low, high RDS(on) at 3.3 V), spikes resetting the microcontroller (no flyback, no decoupling, shared ground wire).
- Change it: for forward and reverse use an H-bridge (see the diagram in Driving Motors and Actuators); for more than a few amps use a dedicated gate driver.
Project 4: 5 V 2 A buck supply
Requirement: turn a 12 V supply into 5 V at up to 2 A with high efficiency and a ripple below 30 mV. A linear regulator would waste (12 − 5) × 2 = 14 W; a buck converter is the right choice (see Power Electronics: Buck, Boost and Thermal Design).
Design calculation
- Duty cycle: D = Vout ÷ Vin = 5 ÷ 12 = 0.417.
- Inductor ripple current: with L = 10 µH at 500 kHz, ΔI = (Vin − Vout) × D ÷ (f × L) = 0.58 A (29 percent of the load). The peak is Iout + ΔI ÷ 2 = 2.29 A and the minimum is 1.71 A, so the inductor’s saturation current must be well above 2.29 A (choose at least 3.5 A).
- Output capacitor: for 30 mV of ripple, C ≥ ΔI ÷ (8 × f × ΔV) = 0.58 ÷ (8 × 500 kHz × 0.03 V) = 4.86 µF. The real ripple is usually set by ESR, not capacitance; two 22 µF ceramic capacitors have a low ESR, but check the DC-bias loss (see Reading Datasheets): at 5 V 22 µF X5R parts may keep only half of their value, which is still well above the minimum.
- Input current and loss: at 90 percent efficiency the supply draws 10 W ÷ 0.9 = 11.1 W, i.e. 0.93 A at 12 V, and wastes 1.11 W in the converter. A fuse of 3 A leaves a margin over 0.93 A.
- Input capacitor: the converter draws pulses of the load current from the input; ripple on the input is about I × D(1 − D) ÷ (f × C) = 0.10 V for 10 µF. Use at least 2 × 10 µF ceramic plus a bulk electrolytic.
- Protection: a series fuse; a P-channel MOSFET (reverse-polarity protection, with the gate to ground via a resistor) or a Schottky diode; a TVS diode (SMBJ15A) for supply spikes; an enable pin with a divider if an undervoltage lock-out is needed.
| Part | Value | Note |
|---|---|---|
| U1 | Synchronous buck regulator, 3 A or more, 500 kHz, 4.5–17 V in | Choose a part with built-in switches; follow its typical application |
| L1 | 10 µH, Isat ≥ 3.5 A, low DCR | Shielded to limit radiated noise |
| Cin | 2 × 10 µF X7R ceramic, 25 V (+ 47 µF electrolytic) | Keep next to the VIN and GND pins |
| Cout | 2 × 22 µF X5R, 10 V | Low-ESR; see DC-bias note above |
| RFB | Divider from the datasheet equation, 1 percent | Sets the 5.0 V output |
| D / Q | TVS SMBJ15A, P-MOSFET reverse protection | See Switches, Connectors and Protection |
| F1 | 3 A fuse or resettable fuse | On the input |
- Layout: the loop of input capacitor, switch and ground is the noisiest part: keep it as small as possible, with the input capacitor right at the pins and a solid ground plane under (see EMC and Noise at Board Level and PCB Design and Layout).
- Check: measure the output without a load (should be 5.0 V ± 2 percent), then with 1 A and 2 A; look at the ripple with a short ground spring (expect under 30 mV at the switching frequency). Measure the efficiency: input power ÷ output power. Check the temperature of the converter and inductor at full load.
- Common faults: output too high or low (feedback divider wrong), no start (enable pin or undervoltage), oscillation or buzzing (capacitor too small after bias loss, a poor layout), hot inductor (saturation).
Building and testing
- Simulate or breadboard first, then build on a PCB (see PCB Design and Layout) or perfboard for the simple designs.
- Power up carefully: current-limited supply, a fuse, and a first look at the output with no load connected.
- Measure and compare with your calculations; a difference points to a wrong assumption (a part value, a tolerance, a bias effect).
- Keep notes: a schematic, a BOM with the exact part numbers and the measured values, so that the next build is repeatable.
- Test at the extremes: minimum and maximum supply, hot and cold, full and no load.
Related
- Design, Testing and Troubleshooting: the overview of this guide.
- Power Electronics: Buck, Boost and Thermal Design: regulators, buck converters and thermal design.
- Driving Motors and Actuators and Transistors: drivers and switching.
- Reading Datasheets and Troubleshooting Flowcharts: checking parts and finding faults.
- LM317 Calculator, Battery Runtime Calculator and Ohm’s Law and Power Calculator.
FAQ
Why use an LM317 as a current source instead of just a resistor?
A series resistor gives a current that changes with the supply and the LED’s voltage. The LM317 holds 1.25 V across its sense resistor, so the current stays constant over a wide range of both.
How long will my battery really last?
Compute the average current including sleep, regulator quiescent current and bursts, then divide the usable capacity (about 80 percent of rated) by it. Measure the real sleep current: it is usually the surprise.
Do I need a flyback diode with a MOSFET that has a body diode?
Yes, for a low-side switch. The body diode is on the wrong side of the load for the motor current to circulate; an external diode across the motor provides the path.
Should I build a switching supply or buy a module?
For a one-off, a module is usually cheaper and quieter than your first layout. Build it to learn, or when you need a specific size, efficiency or integration.
References
- Texas Instruments, LM317 datasheet and buck converter design notes; Analog Devices and Monolithic Power buck design guides.
- Horowitz, P. and Hill, W., The Art of Electronics, 3rd ed., Cambridge University Press.
- Manufacturer datasheets for the MOSFET, inductor and regulator you choose.
Last reviewed: October 2026. Values are typical: check the datasheets of the parts you use. The designs are examples: check ratings against the datasheets of the exact parts you use, and test before relying on them.
