Pi Spectrophotometer Tests Olive Oil

An RPi spectrophotometer distinguishes extra virgin olive oil from canola oil and light olive oil.

Similar projects worth following
I designed and built a spectrophotometer. I prioritized simplicity over accuracy; the project uses as few components as possible. An LED shines light through a paperboard slit. The light passes through the cuvette, then hits a diffraction grating. A camera captures the spectrum; the image is processed by a Pi Zero WH. A tkinter GUI was written to operate the device.

Some spectrophotometers are calibrated using lasers of known wavelength. But this would increase the component count, so I wanted another method. I used the following method:
(1) The user places a sample with a known spectrum in the device. (I used olive oil.)
(2) The GUI displays a graph of the measured spectrum. By comparing the meaured graph with the known graph, I determine what the x-axis should be.

The device isn't very precise. Nevertheless, the machine is capable of differentiating between extra virgin olive oil (which is sometimes illegally adulterated) and canola oil.

Code for the GUI is available at

Here is the main menu:

It is necessary to tell the software where the spectrum is in the image.  Here is the interface for this:

Here is the GUI for calibration.  (The process is discussed above.)


STL file for the attachment for the grating and slit. It gets printed twice.

Standard Tesselated Geometry - 18.34 kB - 08/28/2019 at 01:32



STL file for the camera holder.

Standard Tesselated Geometry - 86.21 kB - 08/28/2019 at 01:31



STL file for the base.

Standard Tesselated Geometry - 84.85 kB - 08/28/2019 at 01:31


  • 1 × Raspberry Pi Zero WH
  • 1 × Raspberry Pi Camera V2.1
  • 1 × Diffraction Grating Slide
  • 1 × Glass Cuvette (10mm)
  • 1 × Slit cut from paperboard The slit should be very thin!

View all 8 components

  • Testing The Updated/Fixed Spectrophotometer

    Daniel James Evans08/31/2019 at 16:41 0 comments

    After making the changes discussed in the previous posts, I tested the precision by measuring the same oil (Extra Virgin Sample 1) 3 times.  Here is the result:

    I also re-tested the different oils.  I'm surprised (and concerned?) by how little absorbance was detected in the canola and light samples.  But in general I think the results are decent.

    Lastly, here is an updated illustration of the spectrum-finding GUI.  The previous version shows inadequately collimated light; the issue is visible in the middle of the spectrum.  This version doesn't seem to have that issue.

  • More Improvements To Accuracy

    Daniel James Evans08/31/2019 at 00:50 0 comments

    I fixed the bug that caused the x-axis to be reversed.

    I realized that the light wasn't fully coherent when it reached the diffraction grating.  (The issue can be seen in the middle of the spectrum image; there is white where there should be green and blue.)  To fix this, I made a thinner slit and moved the LED back.

    I decreased the resistor from 1 k ohm to 330 ohm.  As expected, the LED is now brighter.

    The holder for the diffraction grating was slightly wobbly.  I glued it to the base.  The glue is still drying; I plan to perform new tests this weekend.

  • An Improvement and an Unfixed Bug

    Daniel James Evans08/29/2019 at 02:43 0 comments

    I changed the code so that it takes 3 images and averages them, instead of taking 1 image.  This dramatically improves the precision of the device.

    I found a major bug in the code: the x-axis was reversed!  This escaped detection because there are peaks on both edges of the olive oil spectrum.  But when I started averaging images (see above), it became apparent that the right-side peak was much bigger than the left-side peak.  This is incorrect; it caused me to investigate and find the bug.  I still haven't fixed the bug; I need to do this before taking more measurements.  The spectrophotometer is currently NOT accurate (because of the bug); it should NOT be used right now.  I hope to fix the issue soon.

  • Data Collection

    Daniel James Evans08/28/2019 at 01:28 0 comments

    I collected spectra from 3 brands of extra virgin olive oil.  I also collected spectra from light olive oil and canola oil.

    The right side of the spectrum shows a clear difference between the extra virgin samples and the other samples.  I'm worried that the left side of the graph is inaccurate.  I'm not convinced that canola oil should have that much absorbance at low wavelengths.

    Despite the possible issue on the left edge, I consider the test to be mostly successful.  The device shows a clear difference between extra virgin olive oil and other oils, demonstrating its usefulness for food inspection.

View all 4 project logs

Enjoy this project?



enricomelis1 wrote 10/06/2020 at 18:49 point

Wow, this project is gorgeous. I tried to replicate it and it gives satisfactory results. Now I would like to try to go down to 200nm.

  Are you sure? yes | no

Dan Maloney wrote 09/13/2019 at 15:33 point

Wow, there's so much difference between the spectra of EVOO and canola! I wouldn't have expected that. Wonder what species in the olive oil are responsible for the strong UV absorption, and the strong peak at 460-nm.

  Are you sure? yes | no

Daniel James Evans wrote 09/13/2019 at 21:55 point

I was also surprised by the magnitude of the difference between spectra.  The oils look different to the eye, but the difference is subtle.  I would have predicted a similarly subtle difference in spectra.

I've seen a few websites suggest that chlorophyll is a major contributor to EVOO's spectrum.  But chlorophyll has less of a peak at 460 nm than EVOO, so I suspect that additional pigments are involved.  I haven't seen much information about what these pigments are.

  Are you sure? yes | no

hubidrei wrote 09/01/2019 at 12:41 point

Woldn´t it be better to use a high cri led?

  Are you sure? yes | no

Daniel James Evans wrote 09/01/2019 at 22:09 point

I think that you are correct!  Thanks for the suggestion.  The only reason why I used the LED that I did, is because I already owned it.  If I build a better version of the spectrophotometer, I'll probably use a better light source (such as a high-cri led).

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates