Introduction: DIY Low Cost Spectrometer
Being a final-year undergraduate student majoring in physics, I believe that labs and practical experiments are just as important as the theory when it comes to subjects like physics. Lab sessions and experiments provide tangible results which often help clarify the concepts much more effectively than a lecture. However, due to the global pandemic, we have not had a lab session for over a year now.
Most experiments, especially in the final year of an undergraduate physics course require complex, intricate, and highly expensive instruments and equipment. However, in our course, the spectroscope experiments caught my eye and I decided to build a low-cost version using materials that are available in every household.
I am also interested in the field of computer science so I decided to make a digital version of a spectrometer using a webcam, and create a program to analyze the results.
Follow on to create your own DIY Low-Cost Spectrometer and do drop a favorite and follow this page if you enjoyed the project and decide to build your own version. I would love to see your own versions so do post your creations using the "I made it" section.
Step 1: Overview of the Theory of Spectrophotometry
The concept of spectroscopy is generally elaborated in undergraduate-level physics courses, however, here is a brief explanation about the theory behind spectroscopy and the spectrometer.
A spectrometer is a clever instrument used to measure the properties of light. This allows scientists to use this instrument for a vast number of experiments such as determining the materials found in objects used in day-to-day life or determining the elements found on distant stars and planets.
The basic concept of a spectrometer is that an "unknown" beam of light is flashed onto an optical element that splits the beam of light based on the wavelengths present in the "unknown" beam of light. Each wavelength is deviated a different amount, therefore by measuring the deviation, one can determine the wavelengths present in the "unknown" beam of light, which could potentially provide more information about the source of the beam of light, even if it originated millions of kilometers away.
In earlier times, scientists used prisms to split the beam of light into its components, and a pivoting eyepiece to measure the angular deviation of each wavelength component. However, more recently, the prism is replaced by a diffraction grating that serves the same purpose as the prism, and the eyepiece is replaced by an electronic photoreceptor array that is connected to a computer.
Step 2: Materials Needed
Here is a list of all the components and parts required to make your very own Low-Cost Spectrometer. All parts should be commonly available and easy to find and you may already have them lying around in your home.
Materials:
- Cardboard
- Black chart paper
- Old DVD disk
- Razorblades
- Webcam
- Glue
- Tape
The total cost of the project excluding the webcam is less than 5$.
Step 3: Building the Enclosure Pieces
The enclosure could have been made using any kind of box but I decided to create one from scratch to make it the perfect size for the webcam that I was using. Begin by taking the measurements of the webcam:
- Height
- Width
- Height of lens
Build a box according to the following measurements:
- Length - 20 to 25 cms
- Width - 2 cm larger than the width of the webcam
- Height - 1 cm taller than the height of the webcam
Trace the 6 faces of the box according to the dimensions onto a piece of cardboard and use a knife to cut the pieces out. On the rear face make a slot through which you can pass the webcam's cable and on the front face make a 2cm x 1cm slot in the middle at the height of the camera lens.
Stick all the faces onto a piece of black chart paper using glue and cut the paper along the boundaries of the cardboard pieces.
Note: It may be useful to mark the faces using a pencil to avoid any confusion.
Step 4: Assembling the Enclosure
Grab the bottom face and the two side faces and place them side by side. Use tape to join the three pieces together. Next, attach the front and rear faces using more tape by making sure that the orientations of the faces are maintained.
The top face is attached along a single edge so that we can open the enclosure using the top face like a hinged lid in case we need to make any adjustments later. To prevent any light from entering through the top, cut some more pieces of cardboard to make a slight overlap.
Peek into the enclosure through one of the slots and make sure that no light gets into the box. An extra layer of electrical tape or any kind of non-transparent tape can be used to cover up small gaps.
Step 5: Making the Entrance Slit
To make the entrance slit, tape one of the razorblades vertically to cover up a portion of the gap on the front face. Tape the second razor blade next to the first one by using a single sheet of paper to create a thin gap between the two blades. Tape the second blade and use electrical tape to cover any gaps to prevent any light from getting into the enclosure.
Step 6: Making the Diffraction Grating
This step is the most crucial part of the project. The diffraction grating is responsible for splitting the beam of light according to the wavelength. One option would be to buy a diffraction grating directly. These are usually available online for about 4 to 5$. The other option is to use an old DVD disk for the diffraction grating. Both provide similar results.
Begin by cutting into the disk using a pair of scissors. As you cut deeper into the disk, you will notice that the disk consists of two layers that will begin to split apart. Split the two layers completely and discard the half that consists of the silver coating.
Cut a quarter piece out of the second half and square the edges to form a small rectangle that is a little bigger than the width of the lens.
Next, use some glue to stick this piece onto the lens. Make sure to use temporary glue so that you can remove the diffraction grating in case you want to reuse the webcam.
Note: One crucial step for your spectrometer to work is that the concentric grooves along the disk are lined up such that they are vertical, that is, they need to be parallel to the slit. If they are not parallel to the slit, the diffraction will not take place.
Step 7: Mounting the Camera
Once the diffraction grating is stuck to the webcam, pass the cable through the enclosure using the rear slot and place the webcam towards the rear of the enclosure at a 30-degree angle with respect to the front face, and aligned with the slit in the front. Before sticking the webcam in place, connect the webcam to a computer and open the camera app. Point the spectrometer towards a source of light and adjust the position of the webcam till the diffraction spectrum is positioned in the center of the image.
At this point, you can stick the webcam to the bottom face using double-sided tape.
Step 8: Testing
To test if your spectrometer works correctly, point it at a source of light and adjust the height of the light source and spectrometer till both are aligned. You can use a pile of books or something else to adjust the vertical alignment, I decided to use some old 3D printer filament rolls.
Connect the webcam to a computer and open a camera app. The image should consist of a neat diffraction spectrum.
You can further decorate and label the spectrometer using printouts.
Step 9: Using the Analyzer Software
Simply having a picture of the spectrum may not provide much information, so I designed a program in Python to plot the intensity of light. This will provide the relative distance between "peaks" which can be further used to determine the wavelengths present in the source of light.
To run the program you will need to install Python on your computer along with a few additional open-source libraries. Python can be downloaded using the following link https://www.python.org/.
The additional libraries can be downloaded and installed using pip through the terminal. The libraries along with the terminal commands are provided below:
- Opencv - pip install opencv-contrib-python
- Numpy - pip instal numpy
- Matplotlib - pip install matplotlib
Once all the libraries are installed, you can clone the spectrum analyzer program from the following GitHub repo: https://github.com/kousheekc/DIY-Spectrometer-Analyser
Run the program and you should see the webcam feed. Point the webcam to a source of light and press the "r" button on your keyboard to capture the region of interest of the feed. Click and drag your mouse over the spectrum and press enter. Once the region of interest is selected, press the "s" button to capture a frame and analyze the intensity using a graph visualization. You can use the "q" button to quit the program.
Step 10: Final Results
Once you have tested the spectrometer and the software program, you can begin your experiments. You can point your spectrometer at various sources of light such as CFL bulbs, neon lights, incandescent bulbs, or even smart color-changing LED bulbs. You can also step outside and point the spectrometer into a clear portion of the sky and explore the results.
To measure the wavelengths of a certain light source you can begin with a source of light with a known wavelength such as a laser and determine a relation between the position of the peaks and the wavelength.
There are various other fun experiments that you can try such as detecting and measuring sodium in table salt and detecting chlorophyll in olive oil. With this low-cost spectrometer, you can perform various simple and interesting experiments right from your house.
Hope you enjoyed this Instructable and it has inspired you to build your own DIY Low-Cost Spectrometer. This was originally targeted towards undergrad physics students who are unable to conduct practical experiments and labs due to the pandemic, though the process is simple for anyone to follow without the need for a formal physics background. I would love to see your very own versions of the spectrometer so do post them and the results using the "I made it" section. Apart from that, feedback, questions, comment, concerns can be addressed in the comment section below.
Happy Making!

Grand Prize in the
Explore Science Challenge
54 Comments
Tip 27 days ago
Hi, A couple of useful tips. I've explored this in detail and noticed that on some webcams there's a Bayer filter that can cause all sorts of anomalies though the fix here is to use one that
has a different arrangement such as one from a car reversing camera.
The fix is to sum from 3 different lines and then calibrate using a known source.
LEDs and laser diodes will work at LOW POWER ie constant current of 3mA or just enough for lasing to begin, or use a diode from an optical mouse.
Self heating of the diode causes wavelengths to shift and this is more pronounced with LDs.
Also useful, adding a laser line generator optic inline with your filter as this might yield a clearer image if placed carefully so the centre beam aligns.
On my list is using a tube from a defunct printer as this is highly stable and can be modified easily.
Interesting note here, I found that the tiny VCSEL on laser meeces can be a valuable source of very pure 740-850nm light and usually its less than 3% from the centre wavelength specified in the datasheet, current is about 0.6mA on the ones here.
Question 1 year ago on Step 9
Hello, I did build the spectrometer but am unsure how to get all the python libraries installed correctly. I did get python installed and tried to get the three libraries on correctly but when I try to run the program, I get a CV2 error. Not sure what all of that means or if I have those three libraries installed correctly? I unzipped the opencv-contrib-python-4.6.0.66, numpy-1.22.4, and the matplotlib-3.5.2, and now have those three folders. So, when I open the python launcher and try to run the spectra python program, I get the following info (see image.). Thanks for helping! Alan
Answer 8 months ago
I got various errors trying to install with pip on my macOS Mojave 10.14.6. I have Macports installed and have their python3.10 installed, so I issued "sudo port install opencv3", followed by "sudo port install py310-opencv3", followed by "sudo port install py310-matplotlib". Then "python3.10 analyser.py" works like a charm.
Question 11 months ago
Looks good, I'm hoping to do this with my daughter as part of a science fair.
We want to shine a light through the Nobel gasses and see the differences in the spectrum. Would I need stand pressure gasses for this or rarefied?
1 year ago
Thanks for the instructable, it was an easy build that gave nice results. The python part works, but one has to get used to the delays at startup (I thought that something was wrong). In the attached image, I show the spectrometer used for an illustration of atmospheric absorption at the "Fête de la Science" at Sorbonne University this year: the original spectrum was compared with the one obtained after passing the "atmosphere" (a box with blue fluid). Thanks again!
1 year ago
Great project, simple and powerful! Two questions:
1) If I remove the IR filter on the sensor, will your software work with the extra IR data?
2) I have a 8 megapixel camera, any reason the current software would not run? & Any value in so much data?
Thank you
Question 1 year ago on Step 8
You are still not clear on how the spectral image is on the outside of the enclosed box. Have you cut a window in the cardboard box --- I don't think this would work. see section 8
Answer 1 year ago
That is only a printout that was attached to the side for decoration. It isn’t a spectral image being displayed by the spectrometer. The spectral image is only visible on the laptop screen.
1 year ago
amazing project! thanks for this. you should start a youtube channel, showing home made lab equipment and what you can do with it. i'm very interested in that because i have no education in these topics and you explain it very well.
Reply 1 year ago
Guys, This is called Chemistry - which many professors thereof, can be found on YouTube. Pick the one you like.
1 year ago
Did you remove the IR filter? and second to this question will the software recognize ir? I am going to build a few of these with my class as it’s a great way to introduce spectrophotometry and I was just interested to see if you think IR is also possible?
2 years ago
Hello.
Before my question, thank you for this instructable. It's fantastic.
I made and it's working fine but I've just one doubt. How do you get the rgb lines? I only get a blue one.
Tip 2 years ago on Step 10
Brilliantly simple. The work of an hour to put together and the included software works perfectly. I needed to compare the relative wavelength of blue LEDs. By using a red laser along with each blue LED, I was able to see the relative distance of the blue peak from the red peak. (See my Ï Made It)
Reply 2 years ago
Thank you and glad to hear your positive results!
2 years ago
Wow impresive!!!
Reply 2 years ago
Thanks!
2 years ago
Excellent, I've been looking for a digital spectrometer. I will definitely build this! thank you so much for all the information
Reply 2 years ago
Thank you!
2 years ago on Step 10
Very nice, and very nice results.
Reply 2 years ago
Thank you!