DIY USB Spectrometer Actually Works

image of diy spectrometer

When we hear spectrometer, we usually think of some piece of high-end test equipment sitting in a CSI lab. Sure, a hacker could make one if he or she put their mind to it. But make one out of a webcam, some cheap diffraction grating purchased off ebay and some scrap? Surely not.

[Renaud] pulls off this MacGyver like build with a detailed knowledge of how spectrometers work. A diffraction grating is used to split the incoming light into its component wavelengths. Much like a prism would. The wavelengths then make their way through a slit, which [Renaud] made from two pieces of highly polished brass, so the webcam sensor can see a specific wavelength. While the spectrometer-from-webcam concept isn’t new,  the build is still impressive.

Once the build was complete, [Renaud] put together some software to make sense of the data. Though a bit short on details, we hope this build will inspire you to make your own spectrometer, and document it on hackaday.io of course.

32 thoughts on “DIY USB Spectrometer Actually Works

  1. Once I got some discharge lamps from my friend. They came in a cardboard box. I made my spectrometer of this box: painted it black inside, used two razor blades and hot glue as slit, mat translucent plastic from broken laptop screen to make light even, and a camera. Just for watching how spectrum changes when lamp(s) heat up: http://argon.printf.cc/lampki/

  2. Would a triangular prism work as well as a diffraction grating ? Apart from the extra weight. cost, availability, safety is there some reason that a diffraction grating is used ?

    *ponder* now that I ask the question – never mind, I’ll get my coat.

    1. As well, do. But you can. The first spectrometers used prisms. Typically most spectrometers use reflective gratings which give a better range since the light does not need to pass through the glass. A lot of glasses have their own absorption range, especially in the UV area which makes them not as useful. Though I suppose you could use something like sapphire or quartz for the prism which has a much higher bandpass range than standard optical glass.

    2. The problem with prisms is that they give non-linear dispersion with angle of view; this made it troublesome to use simple motor drive scanning and complicated non-linear cams were required in old spectrophotometers like the Beckman DU prism versions. The problem with gratings is that they have a peak efficiency at one wavelength (blaze) and they also overlay higher order “re-entrant” spectra and require “order sorting filters” to make sure your detector is measuring the part of the spectrum you intend. Since our eyes and many other sensors have limited spectral bandwidth, order sorting filters may not be needed in some cases.

  3. The slit does not select a single wavelength, it “trims” down the beam of light coming in which increases the resolution of the spectrometer at the cost of sensitivity. Many commercial spectrometers have adjustable slits that allow you to adjust to your light source and bandwidth requirements. You can add a second slit after the grating to create a monochrometer, this is useful when you need to look at a certain wavelength like what is done for process endpoint detection in semiconductor manufacturing.

    1. You give very useful information and answers in a concise manner, I’m impressed. And it’s a bit of a breath of fresh air on the internet to see such a thing.

      Anyway, thanks.

  4. Havingmy own problems with the word surely, I has to laugh at surly. I tend to want to write shurely. Dam spell checkers can’t yet figure out what we meant, and because surly is valid they would go with that.

  5. so in theory, would getting a pair of diffraction grating with larger slits would allow you to trim the grating to the required wavelengths that you want to monitor?

    1. Yes — I believe what you’re talking about is typically called a “monochromator”. Use the grating to disperse the light and then use a slit to select a certain wavelength from the spectrum.

      These used to be very common instruments, but sensors have gotten sensitive enough with high enough pixel density that spectrometers have mostly replaced them.

      1. Not exactly.. these type of ‘single shot’ spectrometers (i.e. capture the entire spectrum in one go on one CCD) lack for high resolution. Monochrometers are still quite common, though in most of the ‘high’ end designs, the diffraction grating is rotated to scan the spectrum over the output slit. The grating turret can contain several gratings with different ruling for a broader spectral range.

        As you can imagine, these can be very sensitive, and often resolve down to the picometer wavelength range or better.

        It is also worth nothing that a longer spectrometer will give better resolution, since you get more wavelength dispersion with distance from the grating.

  6. I also noticed that Renaud is trying to reduce noise from the sensor, I wonder if he’s thought of using ‘dark’ frames to reduce noise? It’s a technique used to reduce sensor noise for astrophotography. Essentially, you make sure that absolutely no light can reach the camera sensor, then capture a number of frames, then put those frames + a light frame (real image) into some astro processing software (Deep Sky Stacker) and it will sum the dark frames and subtract the noise from the light frame giving you an overall cleaner result. dark frames should be taken either before or after taking your images so that the temperature of the sensor is broadly similiar/same to achieve the best results. It’s up to you how many dark frames you take, the more the merrier, as it’s a webcam, you can easily take 1000 dark frames but it’s a law of diminishing returns, 50-100 should be sufficient.

  7. *ponder* Would you get a better range with a NoIR module on a RPi ?

    380nm to 750nm (789 – 400 THz) is normal visible light for most sensors, but the NoIR module will also cover 750nm to 1000nm (400 – 300 THz.

    Some of colours output by the sensor would end up being the same for different frequencies, so the physical position on the sensor would indicate the actual frequency. And the colour would only be an indication of the intensity.

  8. I’m beginning my work on the spectrometer portion of my project.. Although I am going to probably use a linear ccd, I originally planned on using the raspberryPi camera… and will probably still end up tinkering with it to see the difference, etc..

    This looks like a great project..!

    @Truth, you might gain some insight from the discussion on my bio some time ago where we discussed the merits of the raspi cam noir vs. regular, etc….
    http://hackaday.com/2014/06/05/thp-hacker-bio-flc/

    1. One thing that I did not see in that thread was any mention of the “raspistill -raw” option which gives the actual RAW output from the sensor in the RPi camera module.
      It is in a bit of an odd format appended to the end of the captured jpeg image.
      10 bits packed as BGGR data stored in 5 bytes (see here for more details – http://www.raspberrypi.org/forums/viewtopic.php?p=357138&sid=3cda3891111a1f81ff2ec0e601ee202f#p357138 ).
      Yes you still have to deal with the Bayer filter, but you get the raw sensor data before any algorithms on a normal webcam are done like: lens shading, black level correction, debayering, denoise, sharpening, defective pixel correction, colour correction.

      1. I must have completely missed that option.. not sure how many times I read the documentation and still glazed over that. A quick google search and I also came up with this http://bealecorner.org/best/RPi/ which has some good examples…and a converter he wrote for adobe’s DNG format.. Useful stuff, and gets the mind going back on a path I think still has some potential!

  9. This is a very nice DIY… Finally someone implements a DIY spectrometer with a slit and optics — LGL topology is nice because it can use inexpensive and available lenses. Czerny-Turner or other reflective optic spectrometers have optics that are hard to source.

    I’m interested in seeing a neon lamp spectrum. I’m curious what the resolution is. I wonder if a linear CCD would do better with physically larger pixels.

    1. That is an interesting point lee… I have been thinking in this regard lately..if you don’t mind my asking for an opinion.. would an option to replace the Czerny-Turner spectrometer in my project with a transmission grated lower cost alternative be preferable? I would probably still use the ccd array since there are the issues with the Bayer filter, etc.. from using a webcam, etc.. I’m thinking this since I am trying to make my project as modular as possible to make it configurable to the use and price range as needed..

      1. Have you considered physically rotating the grating to scan the spectrum over an output slit, and pick up the resulting signal with a high sensitivity photodiode? (could be peltier cooled as well). I apologize if we’ve already discussed this, but I’ve forgotten a good bit of what was mentioned before.

        1. I have seen that done..And as it turns out, I think the first grating I bought is meant for that application.. I originally didn’t consider a photodiode, until recently…and then the matter of the max integration time with the photodiode being very short.. I was thinking of using the monochromator grating I have on a turret with the raspberry pi camera module for some tinkering since it was also brought to my attention recently of the -raw switch you can use with the raspi cam software..(mentioned above in this thread).. I recently purchased the Toshiba 1304 chip and will be playing with that too…for that I’ll be purchasing a couple concave mirrors and a new grating to experiment with the crossed czerny-turner setup.. One thing I really want to do is possibly come up with two or three different configurations covering low medium and high price ranges that will give people an option of which spectrometer portion to print out and build based on their price range…

          1. That was the other thing I think I mentioned before: You could always consider peltier cooling of the CCD to reduce noise even further. This is also an option on many high-end 2D CCD arrays (in excess of 50k USD).

            Keep up the good work!

          2. @medix
            I’m still trying to figure out a mount for the CCD that will provide good thermal conduction to the peltier, etc. that won’t require people to buy a special part or have to machine something from aluminum… I read somewhere that it’s not uncommon to cool them to around -50 degrees Celsius! I have to wonder about moisture in that case… as well as the effects that’s going to have on the surrounding printed plastic, etc.. I’m not sure if it’s necessary to cool to that level, so I have a bit of reading to do still..! :)
            I do want to thank you for all the input and encouragement tho! It’s most appreciated!

          3. Hey, no problem! I’m just happy to provide input to someone who appears to be doing things ‘the right way’. ;)

            You can indeed go to -50C, but I don’t know about moisture. I would assume that, so long as the CCD is in a separate enclosure (containing the space to be cooled) with adequate insulation, condensation should be minimal (if any). That’s partly why I suggested the photodiode, since you could easily cool down such a small thermal mass relatively quickly, with no worries about condensation. Cadmium telluride and some silicon detectors are cooled with LN2 for high sensitivity and very low noise. The diode is housed in a small dewar with a window in the front for letting in signal light. I could see a similar arrangement using an insulated container and several peltier junctions to provide cooling. Perhaps glycerine could provide a better heat conduction. You’ll want to keep the diode encased, but have a clear (i.e. air) cavity to let in the light, just so long as the body of the diode has good contact with the cooled area.

            Whatever you decide to do, I’ll be following right along.

Leave a Reply to ReggieCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.