DSLR / Camera Lens Spectrometer - Photograph the Full Spectrum!

by GK-Astro in Design > Photography

563 Views, 6 Favorites, 0 Comments

DSLR / Camera Lens Spectrometer - Photograph the Full Spectrum!

20260610_222044.jpg
20260610_222154.jpg
stackedspectra2.png
plot.jpg
Code-Output.jpg

This is a DIY spectrometer that can be used with DSLR lenses. This design incorporates a diffraction grating, adjustable slit, and 3 DSLR lenses to produce a spectrometer that can be used to measure the light spectrum from lights or even stars. It can be used as a teaching tool or a fun way to learn about light spectrums.


Essentially, the light comes in through the first lens (Canon Mount, I used a 100-300mm zoom lens), and focuses at the adjustable slit. Once the remaining light passes through the slit, it goes into the colliminating lens (I used an old Minolta 50mm lens), passes through the diffraction grating, and then enters the final camera lens (I used a 135mm Nikon lens) before going into the camera. The lens mount types only matter for what goes to your camera and the canon on the front, and aside from that they just need an exterior diameter of less than 65mm.


Once you have your images, you will need a calibration image of a white LED and a science image of whatever you are interested in viewing. Then you read the two images into your code, edit anything necessary, and it should display the estimated spectra of your science image.


This is a fairly complicated project, and you may need some knowledge of coding and CAD (Fusion 360) to adjust dimensions and settings if your camera or camera lenses are different from what was used in this project. I tried to incorporate a lot of comments to explain any potential things you need to change in the code to make it easier. Happy building!

Supplies

20260610_222207.jpg

Optical elements

  1. Canon Mount Objective Lens
  2. Colliminating lens with OD < 65mm (tested with 50mm focal length)
  3. Diffraction grating (can find cheap diffraction gratings online)
  4. Focusing lens mounted to camera (lens OD < 65mm, I used one with 135mm FL )

Hardware

  1. 2 standard razor blades for the flat edge
  2. 2 bolts 1/4-20, 1 inch
  3. 8 M3 x 12 machine screws and nuts
  4. 4 springs (~4mm OD x10mm length)
  5. Aluminum foil for light leaks
  6. 1/4-20 nut
  7. Superglue
  8. Foam padding to line the inside if lenses are under 65mm OD
  9. M3 x6 plastic screws (2)

3D printed parts (Printed with SLA, but FDM should also work)

  1. Main Chassis
  2. Top
  3. Lid of adjustable slit
  4. Adjustable slit body
  5. 2x RazorHolder
  6. Diffraction Grating Holder
  7. Screw caps (2)

Software

  1. Fusion 360
  2. Python compiler
  3. (optional) image stacking software (DeepSkyStacker works well!)

Tools

  1. 3D printer (resin preferred)
  2. Screwdrivers

Printing the Components

  1. BEFORE PRINTING: Ensure that the parts are the correct size for your equipment. Read through the rest of the steps and check anywhere I've flagged where you may need to adjust the connectors for different mounting types.
  2. Download the f3z file for Fusion and open the project.
  3. Once you have appropriate dimensions and are ready, download stl files and print.
  4. I used an SLA (resin) printer for this project, and the parts came out very nice. However, I expect you could use any printer for this as there are not many components with small features. The only one that may have issues would be the adjustable slit, which might need finer tolerances, so try and use your finest tolerance when printing that part.


If you have spare or older lenses, I also recommend using those at first until you understand how everything fits together.

Assembling the Adjustable Slit

20260610_220805.jpg
20260610_220906.jpg
20260610_221011.jpg
20260610_221214.jpg

Here we assemble the adjustable slit. A smaller slit will help you get higher resolution, and a larger slit will allow more light through the system for fainter sources.

  1. Place the bolts into the screw caps so that they are tightly assembled. You may want to use the nut to pull the screw down further.
  2. Re-thread the holes using the small bolts, simply screwing them in place and out of place a few times. The threads are modeled in Fusion, but most printers have difficulty with that resolution and most people will need to re-thread the holes.
  3. Insert the springs into the small holes on each of the sides of the razor blade holders so that they stick in place.
  4. Put the razor blade holders into the adjustable slit body, pushing the springs into place in the holes. You may want to use a screwdriver to push the springs in place.
  5. Take the razor blade and the super glue, and line the razor blade up so that the small circles are touching each of the edges as you glue it in place. Repeat for both razor blade holders, ensuring that the blades are properly lined up and aren't crooked.
  6. Insert the two screws into the top and bottom of the body. The screw should line up with the semikinematic 'V' on top of the razor blade holder.
  7. Assemple the lid of the adjustable slit, ensuring it is in place. Screw in the two 3mm screws.

The Diffraction Grating / Colliminating Lens Assembly

20260610_221242.jpg
20260610_221316.jpg

Here, we assemble the diffraction grating. Diffraction gratings are inexpensive and can be purchased easily online.


This is one step that you may need to adjust the files before printing. My colliminating lens was a Minolta mount, so the diffraction grating is set up to work with that type of mount. If you have a colliminating lens that is a Nikon, it will need to be slightly wider, and a Canon will need to be significantly wider. These should be pretty simple edits in Fusion to simply change the diameter and potentially the length of some of the lip that comes over the edge.


  1. Cut the diffraction grating to size so that it can fit in the diffraction grating holder. I made the tall side be 'up' but the only thing that matters is that you know which side is which.
  2. The diffraction grating will angle the light off at about 30 degrees, so if your diffraction grading is shifted by 90 degrees you won't be able to see anything in the camera. Luckily, this is very easy to change as you only have to rotate the lens assembly 90 degrees.
  3. Use the superglue to put the diffraction grating in place.
  4. Once the glue is dry, assemble the lens assembly by rotating the lens onto the back of the colliminating lens, just like a lens cap.


Tip: If you're having trouble getting the printed part to go on the back of the colliminating lens, simply take an old back lens cover and drill or cut a hole in the back, then glue the diffraction grating on top.

Assemble the Spectrometer

20260610_221431.jpg
20260610_221512.jpg
20260610_221457.jpg
20260610_221532.jpg
20260610_221614.jpg
20260610_221943.jpg
20260610_222154.jpg
  1. Take the main chassis and put it upright on a table. Push the nut into place at the middle of the assembly so that you can use this with a tripod in the future.
  2. Insert the Adjustable slit assembly so that the screws come out of either side. Make sure it is firmly in place and straight inside the assembly.
  3. Tip: If you're interested, see what happens if you put the slit in at a 90 degree angle so that the screws come out the top and bottom! There is an interesting optical effect, so this can be set up either way.
  4. Next, line up the colliminating lens assembly. In my case (50mm FL) this lens goes all the way up to the slit. You can see if it is focused by looking through the back to verify if you can see a focused image.
  5. You may need to use some kind of foam or padding to artificially increase the outer diameter of your lens. Make sure this goes in at this step.
  6. Place the top of the assembly over the chassis, so that the holes line up. Use the M4 screws to tighten this in place.
  7. Put the final lens with the camera in the back of the assembly. You may need to use the padding to make this fit tightly.
  8. Place aluminum foil over any gaps where light may leak in. You'll be able to tell in the image if there are unwanted light leaks.
  9. Now just put the Canon mount objective lens on the front, and you're ready to take pictures.


You may notice extra room to angle the lens on the back. This is so you can focus on different parts of the spectrum. If you want to keep it firmly in place, add some extra padding.

Calibration Image

calibration.jpg
  1. Find a white LED as your source. Make sure there are no other sources in the room if possible.
  2. Put the assembly on a tripod using the mounting point at the bottom of the chassis.
  3. Remove the camera and the focusing lens, and look through the colliminating lens to focus the assembly on the LED. You may want to open the adjustable slit further during this step.
  4. Put the focusing lens and camera into the assembly when it is in focus. Use the viewfinder to look for the spectra. You may need to wiggle things around or adjust the tripod before you find it.
  5. Take an image (or multiple!) of the spectra. Try and make the slit as small as possible for this section.
  6. (Optional) If you took multiple images, you can stack them using DeepSkyStacker (alignment: none) or another image processing software.
  7. Convert the image to a .png from whatever form it was initially, and save it somewhere you can find it.

Science Image

Code-Output.jpg
blueLED.png
colorsoftherainbow.png
20260610_222154.jpg
  1. Repeat the process of step 5, but this time, use an interesting source. Make sure that all of your camera settings are the same as they were in the Calibration image. Some fun sources include other color LEDs, household lights, or even bright stars.
  2. Once you have your image (or images) you can stack them on the computer or just convert them to .png files.
  3. Open Python and copy the code into your file. Unfortunately it seems I can only upload a .txt file for code, so you'll need to copy and paste this in place. You'll also need to change the path for your images to be able to read them.
  4. If anything doesn't work in the code, review the comments I made. There are a few places where you may need to adjust settings or tolerances based on your source and your camera settings. This is where it can be handy to have some Python knowledge.
  5. You will most likely need to change the tolerances in the calibration image until it is selecting the proper peaks. Fortunately, this only needs to be done once and then you can reuse the calibration image.
  6. Admire your spectra! The code outputs the calibration image and its 2 main peaks, the science image, a cropped science image, and the graph showing normalized intensity of the light between the two peaks of the calibration image.


One word of caution: I would not recommend using the Sun because you may damage your camera or your eyes. Remember that even with the slit, a lot of light can still get through and could potentially be a very dangerous mistake.