Build a DIY Spectrometer: CD Diffraction Grating, 3D-Printed Enclosure, and Spectral Analysis Software
Blank recordable CD-R or DVD-R (for the diffraction grating)
Webcam with manual focus, or Raspberry Pi Camera Module
Matte black filament (PETG or PLA) for the light-tight housing
Razor blade or box cutter for a precise slit aperture
Small cardboard or acrylic light shield/hood
USB extension cable, if mounting the webcam away from the main unit
Calibration light sources: a CFL bulb and a laser pointer work well to start
Prices and availability as of Nov 22, 3:23 AM ET and subject to change. The price shown on Amazon at the time of purchase applies.
A spectrometer splits light into its component wavelengths and measures the intensity at each one — the same basic principle used to identify elements in starlight, check LED color temperature, verify a laser's wavelength, or tell a CFL bulb's spectral fingerprint apart from an LED's. The core optical trick is decades old and genuinely simple: a diffraction grating bends different wavelengths of light by different amounts, spreading white light out into a rainbow the same way a prism does but with much finer, more measurable precision — and a working grating is sitting in your recycling bin right now in the form of any blank recordable CD or DVD.
This build pairs a CD-grating optical path with a 3D-printed light-tight enclosure and a basic webcam to capture the spread spectrum, then uses free spectral analysis software to turn the captured image into an actual intensity-vs-wavelength graph. It's a genuinely approachable weekend project, and the resulting instrument is sensitive enough to tell apart different light sources and, once calibrated against known reference lines, to make real wavelength measurements.
How a CD Works as a Diffraction Grating
A CD's data surface is etched with a spiral track of microscopic pits spaced at a very regular, very fine interval — about 1.6 micrometers between tracks on a standard CD, closer on a DVD. That regular spacing is, functionally, a diffraction grating: light hitting it at a shallow angle reflects back at an angle that depends on wavelength, spreading white light into a visible rainbow. It's not laboratory-grade (a purpose-built grating has a much higher line density and far better efficiency), but it's more than good enough to resolve distinct emission lines from fluorescent and LED sources, and it costs nothing.
Optical Layout
The design is a simple straight-line optical path: a narrow slit lets in a controlled sliver of light, that light travels down a light-tight tube to strike the CD grating at a shallow angle, and the diffracted spectrum falls onto the webcam sensor at the far end.
- Entrance slit: cut a narrow (0.2-0.5mm) slit in a piece of black card or 3D print one directly into the housing — the narrower the slit, the sharper the resulting spectral lines, at the cost of less light getting through.
- Light-tight tube: print this in matte black filament, and paint the interior with additional matte black paint if the print still shows any sheen — any stray reflected light inside the tube shows up as noise or ghost lines in the captured spectrum.
- Grating mount: cut a flat piece from the data side of a CD (avoid the label side) and mount it at roughly 30-45 degrees to the incoming light path — this angle is adjustable in practice, so build in a way to fine-tune it (a simple pivoting mount) during initial testing.
- Camera position: position the webcam to capture the diffracted spectrum fan where it falls, with its own lens focus set manually to the distance of the grating — autofocus will hunt and refocus unpredictably on a dim, mostly-black scene.
3D Printing the Housing
| Design choice | Reasoning |
|---|---|
| Matte black filament throughout, not just paint | Printed layer lines on the interior walls scatter light less predictably than a smooth painted surface; matte black filament plus a light paint pass on top gives the best result |
| Modular, slip-fit sections rather than one printed tube | Lets you adjust slit width, grating angle, and camera distance during calibration before committing to a glued final assembly |
| Light baffles (internal ridges) inside the tube | Knock down any light that reflects off the tube walls before it reaches the grating or camera, the same principle used inside telescope tubes |
| A hood or hinged cap over the slit | Lets you control exactly how much ambient light enters, and seals out stray room light during a measurement |
Capturing and Calibrating a Spectrum
Point the slit at a light source, adjust the grating angle and camera position until a clean, sharp spectral band appears in the webcam's live view, and capture a still image. From there, free tools built specifically for amateur spectroscopy — Theremino Spectrometer and RSpec are the two most commonly used by the hobbyist and citizen-science spectroscopy community — take that image and convert the pixel positions across the spectral band into an intensity graph.
Calibration is the step that turns "a pretty rainbow photo" into "a real measurement": you need at least two known reference wavelengths to map pixel position to actual nanometers. A compact fluorescent bulb is the standard first calibration source, since it has several well-documented, sharp mercury emission lines (notably around 405nm, 436nm, 546nm, and 611nm) that show up clearly even on a modest webcam sensor. Mark those known lines in the analysis software against their pixel positions, and the software interpolates a wavelength scale across the rest of the spectrum.
What You Can Actually Measure
- Comparing light sources: capture spectra from an incandescent bulb, an LED, a CFL, and sunlight side by side — the differences in continuous versus spiky, line-based spectra are immediately visible and genuinely instructive.
- Laser pointer wavelength verification: a cheap laser pointer's actual wavelength sometimes drifts from its labeled spec; a calibrated spectrometer can check it (diffuse the beam onto a white card first rather than aiming it directly at the slit, both for eye safety and to avoid overloading the sensor).
- Flame tests: classic chemistry-demo flame coloration (copper's green, sodium's yellow-orange) shows up as distinct emission lines rather than just a color blob, which is a nice bridge between the visual demo and the actual physics behind it.
Limitations and Safety
A CD grating has real limits: lower spectral resolution than a purpose-built grating, and some light loss to higher diffraction orders that a proper grating minimizes. Never point this instrument's slit directly at the sun or at any high-power laser without a diffusing step in between — the whole optical path is designed to concentrate light, which is exactly what you don't want aimed into your eye or your camera sensor at full intensity.
Once the basic unit works, the most useful upgrade is usually a better camera — swapping the webcam for a Raspberry Pi camera module with manual gain and exposure control gives much more consistent, repeatable captures than a typical consumer webcam's auto-exposure, which is constantly fighting you to "correctly expose" what is, to its auto-exposure algorithm, just a mostly-dark image with one bright thin line in it.