DIY spectrometer for $ 5 and some OpenCV

In mastering physics, laboratory experiments clarify concepts much better than lectures. But due to the pandemic, the author of the article, the translation of which we share to the start of the flagship Data Science course, there have been no laboratory classes for over a year; however, most of the experiments in the last physics course require complex, expensive instruments. But the author was struck by the experiments with the spectroscope, and he decided to make his own inexpensive digital spectrometer from the materials at hand, and wrote a program in Python to analyze the output of the device.


1. Some theory of spectrography

Initial information

A spectrometer is an instrument used to measure the properties of light. This allows scientists to use this device for a wide variety of experiments, such as identifying materials found in objects from everyday life, or identifying elements found on distant stars and planets.

The basic concept of the spectrometer is that an “unknown” light beam is applied to an optical element that separates the beam according to the wavelengths present in the “unknown” light beam. Each wavelength is deflected by a different amount, so by measuring the deflection it is possible to determine the wavelengths in an “unknown” beam of light, which can potentially provide more information about the light source, even if it originated millions of kilometers away.

Spectrometer then and now

In the old days, scientists used prisms to split a beam of light into components and a pivoting eyepiece to measure the angular deviation of the wavelength of each component. More recently, however, the prism has been replaced with a diffraction grating, which serves the same purpose as the prism, and the eyepiece has been replaced with an electronic photoreceptor unit connected to a computer.

2. Materials

All materials are fairly easy to find, and you may already have them at home):

List of materials
  • cardboard;

  • black map paper;

  • old DVD;

  • razor blades;

  • Webcam;

  • glue;

  • insulating tape.

Without a webcam, it cost less than $ 5.

Photo materials

3. Calculation of the case

9 more photos
Note the small notch
Note the small notch

The case could have been made using any kind of box, but I decided to make it from scratch to fit my webcam perfectly. Start by measuring your webcam. Fold the box according to the following measurements:

  • length – from 20 to 25 cm;

  • width – 2 cm more than the width of the webcam;

  • height – 1 cm higher than the height of the webcam.

Draw 6 sides of the box according to the dimensions on a piece of cardboard, cut the pieces with a knife. On the back panel, make a slot through which you can pass the webcam cable, and on the front panel, make a 2 × 1 cm slot in the middle at the height of the camera lens. Glue all the edges onto a sheet of black map paper, cut the paper along the edges of the cardboard pieces, and glue. To avoid confusion, you can mark the edges with a pencil.

4. Assembly of the case

3 more images

Take the bottom edge and two side edges and place them side by side. Tape the three pieces together, then after making sure the orientation of the faces is maintained, attach the front and back faces with additional tape. The top face is attached along one edge so that we can open the case, the top face will be a hinged cover in case we need to change something later. To prevent light from coming through the top, cut a few more pieces of cardboard, making a slight overlap. Look into the case through one of the slots and make sure no light is entering the box. You can use an extra layer of duct tape or any other opaque tape to close the gaps.

5. Making a slot

To make an entrance slit, glue one of the blades vertically to cover part of the slit on the front surface. Glue the second razor blade next to the first, using one sheet of paper to create a thin gap between the two blades. Tape the second blade with tape and use it to cover all gaps so that light does not enter the case.

6. Diffraction grating from a CD

This step in the project is the most important one. The diffraction grating is responsible for dividing the light beam according to the wavelength. One option would be to simply buy a diffraction grating. They are usually available online for about $ 4-5. Another option is to use an old DVD as a grid; the result will be similar to the result from the $ 5 grill. First, cut the disc with scissors. As you dig deeper into the disc, you will notice that it has two layers that will begin to separate. Separate them completely and discard the silver-coated layer. Cut a quarter from the other half and align the edges to make a rectangle slightly larger than the width of the lens.

Attaching the grill to the camera

Then glue this piece onto the lens. Be sure to work with temporary glue so that you can remove the diffraction grating in case you want to use the webcam for something else.

Note: One of the important steps in constructing your spectrometer is to make sure that the concentric grooves along the disc are vertically aligned, that is, they must be parallel to the slot. If this is not the case, there will be no diffraction.

7. Installing the camera

Once the diffraction grating is attached to the webcam, pass the cable through the rear housing slot and place the webcam in the rear housing at a 30 ° angle from the front surface and align with the front slot. Before reinstalling your webcam, connect it to your computer and open the camera application. Aim the spectrometer towards the light source and adjust the position of the webcam until the diffraction spectrum is in the center of the image. Now you can use double-sided tape to glue the webcam to the bottom edge.

8. Testing

Two more images

To check if your spectrometer is working properly, aim it at the light source and adjust the heights of the source and spectrometer until they are aligned. A stack of books or something else will do, but I decided to put in some old rolls of 3D printer filament. Connect your webcam to your computer and open the camera app. The image should have a clear diffraction spectrum.

9. Working with the software of the spectrometer

A simple representation of the spectrum provides little information, so I developed a Python program to plot the light intensity. It calculates the relative distance between the “peaks” that can be used in determining the wavelengths of the light source. To run the program, you need to install Python and several open source libraries:

pip install opencv-contrib-python
pip install numpy
pip install matplotlib

With the libraries installed, you can clone the spectrum analyzer program from of this repository. Then run the program and you will see the webcam feed. Point the camera at a light source and, to capture the area of ​​interest, press the “r“. Click and drag over the spectrum and press Enter… Once the desired area is selected, click the “s“To capture a frame and analyze the intensity through rendering. To exit the program, you can click “q“.

10. Results

5 more photos

After testing the spectrometer and its software, you can begin your experiments. For example, aim your spectrometer at various light sources such as lamps CFL, neon bulbs, incandescent bulbs or even color-changing LED smart bulbs. Or go outside, point the spectrometer at a clear part of the sky and study the results.

To measure the wavelengths of a specific light source, you can start with a light source with a known wavelength, such as a laser, and determine the relationship between the position of the peaks and the wavelength.

There are other interesting experiments, for example, it is possible to determine and measure the sodium content in table salt or the chlorophyll content in olive oil. With this inexpensive spectrometer, you can carry out a variety of simple and interesting experiments right at home. And if you are interested in experimenting with other types of data, understanding them, distinguishing seasonal phenomena from real trends and drawing correct conclusions, you can take a closer look at our flagship Data Science coursewhere students gain an experience equal to that after three years of self-study in data science. Or, if you are more into programming, you can pay attention to the course on Fullstack development in Python.

find outhow to level up in other specialties or master them from scratch:

Other professions and courses

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *