There is a more philosophically focussed companion article over at ArkFab.
At long last, second generation DIY spectro has arrived!

The spectrophotometer. Yes, that is an invisibility cloak. You can't see the stuff that's under it can you? Then that stuff is invisible!
If you recall, when last we left our humble spectrophotometer, it was a shambling mess of stone-age technology. Now, its a shambling mess of information-age technology!
Let’s take a closer look…

what is underneath...?
The upper box contains the Arduino microcontroller, which connects my computer to the motor and the sensor. Servo control is done with the a modified version of this PySerial-based servo communication software.

arduinoids unite
Lifting the upper box, we can see into the mechanical part of the device. The diffraction grating is turned by a servo motor; it reflects light onto the sensor. As the motor turns the gear it is sitting on, its angle changes, and the spectrum sweeps across the sensor. Or at least that’s how it’s supposed to work.

The moving parts of the spectrophotometer: The light source, gear assembly, diffraction grating, and sensor are highlighted; the motor is hidden underneath the flashlight. Click for another perspective.
By itself the motor is too coarse to properly cover the spectrum; moving from one position to the next, it covers the whole rainbow in about six steps, worse resolution than the graphing calculator setup. So I slowed it down with a gear assembly, pulled out of an old floppy drive. This is much better, but unfortunately there is still some play in the gears, which means that about a third of the motor positions don’t actually move the diffraction grating – it only starts to turn when the motor is at about degree 60 of 180. The at the same time, the motor sweeps the spectrum very slowly (the change in wavelength per change in motor position is small). This is good- it’s why I put in the gears – but now I have the opposite problem. It moves so slowly that 120 degrees aren’t enough to cover the whole spectrum! Clearly, this is an area for optimization.
The diffraction grating is a chip of CD; it stands freely on a gear in the gear assembly. It is manually aimed at the sensor. It’s not really attatched, so instrumental drift is a problem- bump the machine or look at it especially hard and the grating will shift and you will have to start all over. This seems trivial to fix once the gear situation is resolved.

A book burner lit some incense in my house and set off the smoke detector. I guess you could say the alarm came from a censor censer sensor.
So- how do you use this thing?
First, fill a cuvette with water. Run a blank sample. Run several blank samples to check for instrumental drift. Run samples with the light source off to check for light leaks and get an idea of the baseline dark signal. Run blanks with different sample sizes at each frequency (eg, 1sec/degree vs. 0.5 sec/degree) to get a measure of appropriate sample size and other statistical details.
Now, set up the diffraction grating so that the portion of the spectrum you’re interested in is swept across the detector. We’re going to look at the red region so in our case the grating is adjusted so that IR through yellow gets measured.
Run some more blanks, then caaaarefully remove the light cover and caaaaarefully place your sample into the sample slot. We’re using crystal violet, a dark purple dye used in microscopy and as a fungicide. Using a hand-held spectroscope, we can see that its color is due to its transmission of red and blue-green light and absorption of other colors. We’re going to try to measure the red transmission band.

Looking through the spectroscope, we can see the colors which crystal violet transmits (red and blue-green) and which it absorbs (everything else). We're going to measure the red band.
Once you run the sample you have a time series of sensor measurements for each motor position, for the blank and the sample. I found that there is a glitch somewhere in the serial communications which concatenates the data strings: …20, 20, 20, 2020, 20, 20, 20… obviously, this wrecks havoc with simple statistical measurements so the data gets filtered by excluding measurements above a certain limit (the Arduino analog pin doesn’t return values above 1023, for example). After this preprocessing, the time series is averaged, so that each run associates a single number (the mean) with each motor position. That is to say, at each motor position there is a sensor response I0 for the blank run and a response I for the sample being measured. Now, at each motor position, we can calculate the transmission, T, using the formula
T = I/I0
Absorbance, A, is then calculated at each motor position:
A = -log(T)
When we plot the absorbance at each motor position (which corresponds to frequency), here’s what we see:

Measured red transmission band in the spectrum of crystal violet - the horizontal axis is the motor position, which correlates with wavelength.
As expected, we can see a transmission band in the red region (the area where the absorbance dips; when more light is transmitted, less is absorbed) and an absorption band in the orange-yellow (where the absorbance spikes). Since motor position hasn’t been calibrated to frequency yet, we can’t make any quantitative claims, but it’s nice to see our qualitative expectations confirmed. For comparison, here’s someone else’s measured absorbance spectrum. Keep in mind that my horizontal axis is the reverse of theirs (redder colors are bigger wavelengths).
Obviously, this machine is far from finished. Some things to resolve:
* Optimize gear assembly!
* Stabilize diffraction grating
* Calibrate wavelength to motor position
* Amplify detector signal without destroying the precious microcontroller- the signal never gets over 100, although it has a theoretical maximum of 1023. Taking advantage of the full range of the analog input could give more precise measurements. I think this is what the AnalogReference() function is for?
* Stabilize the light intensity – run the light source off of something other than AAA’s. (USB cord?)
In conclusion,
LED’s are not good light sources for a spectrometer, they have sharp emission lines themselves — better to use a bright incandescent flashlight with a more black-body spectrum.
I was worried about that as well, but it turns out that ‘white’ light LEDs actually have a pretty smooth spectrum. I talk about it some in the FAQ but here is a spectrum:

Hey coesder, your CDS cell may be non-linear in its light sensitivity, but photomultipliers are inherently linear unless driven to saturation. A PMT outputs a current in linear proportional to the number of incident photons. BTW, moving the detector with a linear carriage adds some trig to your data reduction. You simplify that if you move detector in an arc with center at the grating surface. Of course (or is that coarse?), the angular motion of the grating which you use obviates trig too (or is that two?)
I was worried about nonlinearities as well, but I talked to a fellow who works on designing spectros for a living and they recommended I not worry about it. At any rate, a working machine would have to be calibrated for such nonlinearities (eg, measuring the spectrum of a blackbody like an incandescent bulb) to account for that.
Just to be clear, the detector is actually stationary; the grating is what moves. But you are right, there are some geometrical considerations involved – especially if the grating is not aligned exactly with the center of the rotating platform. A fully developed model would be made more exactly, but I think that direct calibration is also necessary – build a calibration curve for motor position vs. wavelength by running samples with known absorption/emission spectra. I talk about it some in this FAQ:
https://topologicoceans.wordpress.com/2011/01/29/diy-spectro-faq/
Hey purgm, don’t let that English thingy get you down! I saw this neat project as a post on the Hack-A-Day website. Csoeder said that he added gears because his steps were too coarse. The HAD post reported that they were too course! Of course they were! Or is that to course, or two course or, too course? The large redundancy of English insures that the message gets through in spite of occasional butchery!
Have you considered that the light source might be the cause of your limited spectrum? In the lab instrument they use 2 light sources a tungsten lamp and a deuterium lamp. If you wanted to stick with LEDs you might have to have a wide range of them so that you could get the entire spectrum.
I know for a fact that mechanical reasons (suboptimal gear arrangement) is responsible for the limited spectrum – I spent quite some time fiddling and watching the rainbow swing back and forth, and cursing.
The LEDs I am using have some band gaps; a small incandescant might be great for filling those gaps in. I’m still not sure how to mix the two light sources efficiently though…?
Yes, this is exactly what the AnalogReference functions/pin are for!
Here is a good tutorial:
http://tronixstuff.wordpress.com/2010/12/07/tutorial-arduino-and-the-aref-pin/
Good luck
thanks!
hey there just wondering what detector ya used as i’m actually building one of these for my final year project and i’m using a photomultiplier tube and the output is in voltage and i don’t know how to convert this to get intensity so that i can calculate beer-lambert law….
any help would be fab
Louise
I am using a Cadmium Sulphide (CdS) photoresistor. Its resistance is very high in the dark, dropping to about 6 kOhm next to an incandescant bulb.
As I understand photovoltaic tubes, they generate voltage when they encounter photons. (I generated a voltage signal by passing current through the CdS) This voltage is your Intensity. So for each sample, you’re going to want to take two data: the voltage that comes from passing the light source through a sample (I), and the voltage that comes from passing it through the blank (I0). These data can be used to calculate transmission, absorption, etc. I go through some of the equations here:
https://topologicoceans.wordpress.com/2011/01/29/diy-spectro-faq/
There are also some links to other projects, some of which are Beer-Lambert specific. You might also want to look into beam splitters/choppers for your reference intensity.
Good luck! let me know how it goes.
well, if voltage is proportional to intensity ie… U = k * I than by using the formula A = -log I/I(0) the proportionality constant k cancels and you can use the formula A = – log U/U(0)
…that is, if I am not mistaken
“than” should be “then”… my english sickens me 🙂
Anyway csoeder, I’ll try to finish my project in the following weekends before exams start and I’ll be sure to post a link or something…
Cheers
I’m curious, and having trouble understanding the general design. You’re rotating the light source, diffraction plate (cd, or..?), and sample and leaving the sensor fixed? Is it a standard photoreceptor?
Have you considered fixing the lighting, deffractor and sample, and then moving the photoreceptor linearly? Just a thought. Also any additional information on the motor and motor control, any arduino code, etc would be awesome to look over. I’m considering trying to build a usable desktop one for myself.
Here’s another image which might be more helpful:
The light source is the flashlight in the foreground. In the center foreground is the place where the sample is held; the flap in front of it is the beam narrowing slit. Underneath the flashlight is the motor; you can see the tiny gear attached directly to it. Underneath the sample holder is a series of gears terminating with the large one on the far left, on which the diffraction grating (a piece of a CD) sits in a holder. When the motor turns, the grating does as well, slowly changing the location of the rainbow it projects. The sensor (white object w/ black wires in the background) is held fixed as the rainbow is swept across it.
My first spectrophotometer did indeed hold the light source steady and move the detector:
https://topologicoceans.wordpress.com/2010/11/25/diy-spectro/
I considered such a design for this version, but I decided that for the time being it would be easier to rotate the grating. The gear assemblies available to me were much better suited to this purpose, and non-gear options typically involved rubber bands, which degrade, especially in polluted areas.
I do want and intend to post my code unfortunately I am notoriously inept at using version control software and I currently can’t get Mercurial working 😦 as soon as I do I will post it here.
Let me know how your project goes!
ps. The motor I am currently using is a Standard HiTec HS311
http://servocity.com/html/hs-311_standard.html
I think a stepper motor might be more appropriate, though.
Hi !
I’m also working on a diy spectrophotometer and I must say, good job !
I went for the open-circuit photodiode method rather than an LDR… seemed kinda cleaner… I’m also planning on moving the sensor using a 5.25″ floppy stepper (or a cdrom motor) and not turning the grating…
Just wondering, what did you use for the light source ? Judging by AAA batteries I assume it’s a power led ?
About the signal amplification : http://en.wikipedia.org/wiki/Operational_amplifier_applications#Non-inverting_amplifier
Cheers
Thanks for the comment! Photodiodes do look like a good option to investigate. I’ve also been directed towards CCDs as well – there’s lots of options to explore!
The first iteration of this project did move the sensor rather than the grating; I considered keeping it that way but decided that it would be more complicated given the materials and skills I had. Let me know how it goes!
The light source is a small flashlight with a large number of ‘white light’ LEDs, powered by three AAA’s.
Yeah, I’ve avoided op amps and transistors and the like because they sort of seem like magick to me but it is quickly becoming apparent that it is time for me to learn. I am on a hunt for some chips and some transistors to learn some things 😀
I love you for this (but not for this alone, of course)
love you tooooooo