Science With Rainbows! - Spectrophotometry




Introduction: Science With Rainbows! - Spectrophotometry

About: Where's the tea? (previously named 'dentdentarthurdent')

Rainbows, natural phenomena that produce beautiful spectrums of coloured light in the sky, inspire myth and legend and art and give happiness to millions of people. Just as natural rainbows are created by how sunlight plays through water droplets in the atmosphere, we can artificially create our own rainbows using prisms. There are many scientific applications of rainbows, and one is 'Spectrophotometry'!

A spectrophotometer is a scientific instrument used to measure how different wavelengths of light (the different colours of light seen in the rainbow are different wavelengths) are absorbed by a sample. This analysis can tell us all sorts of things, and these instruments (first made in the 1940s) have played a huge role in modern science, especially biochemistry.

In this Instructable, we're going to make a basic Arduino-powered spectrophotometer, using a little prism to create and use our own rainbow. We'll make a lot of use of 3D printing, and also learn about lots of other things along the way.

The project video gives a short overview of the project, but please read on through the Instructable for full instructions too!

Step 1: What You Will Need

These are the components I used to build my prototype. Please read onto the next step to read a more full explanation of how a spectrophotometer works, and how we can make our own at home!

Main Components

  • Triangular prism (30mm each side)
  • Arduino Uno
  • LDR (light dependent resistor)
  • 16-Bit LED pixel ring
  • 9g Servo
  • Mini Test Tubes
  • DC-DC boost converter 5V-9V
  • USB cable (one end cut off, and the power lines soldered to the boost converter)
  • Wall plug that can supply 5V DC 0.5A
  • USB cable to connect Arduino to PC

Minor Components

  • Ball bearings
  • Toggle switch
  • Momentary push button
  • E10 filament light bulb
  • Bulb holder
  • 10k ohm potentiometer (or larger)


  • Heatshrink
  • Header pins
  • Hookup wire
  • Solder
  • Electrical insulative tape
  • 3D printing filament


  • Windows PC
  • 3D printer (my print bed is 210x210mm)


  • Arduino IDE
  • CAD Software if you want to modify the files and view the assembly

Step 2: The Rainbow and Science

How does a Spectrophotometer work?
Fundamentally, a spectrophotometer measures the transmission properties of a substance with respect to wavelength. So what does this mean? Different colours of light (the colours of the rainbow that you can see) have different 'wavelengths', it is this that makes them appear to be different colours to our eyes. We know that different materials and chemicals absorb and transmit different wavelengths differently to each other - we see a green leaf appearing green because the green part of the spectrum is the main part that the leaf does not absorb, and hence it is passed onwards to our eyes. A spectrophotometer creates a light spectrum, and then selectively passes a portion of that spectrum (e.g. just red light) through the sample, and then measures the light intensity recorded. Doing this in turn for each band of wavelengths (or each colour) of light within the visible light spectrum allows you to measure how this substance absorbs each portion of the spectrum, from this data you can plot an absorption chart. This analysis can tell you a lot about a substance or chemical reaction, and it is why it is such a useful scientific tool! When researching this, I read that one Nobel prizewinner for Chemistry said that the spectrophotometer is "probably the most important instrument ever developed towards the advancement of bioscience." I have to admit, I don't really need a spectrophotometer at home, but I thought that it would be a really interesting project to try and replicate one using basic components and Arduino. So here goes!

The images above show me experimenting with the angles needed between the prism and the light source to create a spectrum of the right size and in the right place, within the planned dimensions of the housing.

Sidenote: Herschel's Infrared Experiment
Infrared is the component of the electromagnetic spectrum that lies just beyond the red end of our visible light spectrum. Invisible to the human eye, infrared light plays a huge part in our lives - over half of the energy from our Sun arrives on Earth as infrared light, which warms us and helps give our planet the conditions we need. William Herschel, the great German/British astronomer of the 18th century, was the first to notice the existence of infrared, and he did this by just using a simple prism, like the kind you'll have bought to work on this Instructable. If you like, you can try replicating this before using your prism for the spectrophotometer.

Herschel pointed a beam of strong sunlight into a darkened room, and angled his prism it so a beautiful rainbow shined out from it. He then took a thermometer, and noticed that when holding it in the dark region beyond the red part of the spectrum, there was a noticeable increase in temperature, although there was no visible light there at all! He wasn't looking for it, but with this simple observation he'd just discovered a whole previously unknown type of light!

Step 3: Richard of York Gave Battle in Vain

This little mnemonic is how I was taught to remember the colours of the rainbow in order 'Richard - Red, Of - Orange, York - Yellow, Gave - Green, Battle - Blue, In - Indigo, Vain - Violet' and references a tiny snippet of English history - referring to the defeat of the Richard, Duke of York, claimaint to the throne, at the Battle of Wakefield in 1460, in the early years of the Wars of the Roses. I find little historical references like this really satisfying to know, so I thought I'd share this one with you.

Our Spectrophotometer Design
Let's now have a look at our design, and discuss the main components.

  • The Prism - we shall use a simple triangular prism to generate our spectrum. The prism assembly will be held in bearings and be able to rotate, this will allow only a part (or single colour) of the light spectrum to be shined through through a narrow slot and into the sample.
  • Servo motor drive - a miniature 9g servo motor will rotate the prism assembly to point different parts of the spectrum through the slot towards the sample.
  • Test tube hole - a mini test tube holding the sample will be inserted into this deep hole in the housing. One one side of the test tube will be this narrow slot from which light will pass through the sample, and on the other side of the test tube will be mounted the light sensor which will record readings and pass those to the Arduino microcontroller. I initially used a BH1750, but later changed this to a Light Dependent Resistor (LDR).
  • Light source - for this design we shall use a 9V torch battery. It is mounted in a small assembly that adds a parabolic reflector behind the bulb (coated in tin foil) to held direct light, and has a small slot at the front so that only a narrow beam of light can emerge. This allows the light to be precisely directed into the prism.

So those are the key components for the design!

Step 4: She's a Rainbow

All the .stl files for printing, as well as .step files (which you can import into your CAD software if you want to make modifications to the design) are uploaded to this GrabCad page I created to store the files. I strongly recommend you open this assembly to see for yourself all the detail of the assembly, so it's easier to understand how it all fits together. As well as the files for the spectrophotometer itself, this also includes the mini test tube rack that I designed to hold my samples.

For me the most nerve-wracking part was printing the main case by far! Almost all of the complexity of the project is contained within that single part, and so printing this correctly was so fundamental. My 3D printer (a modified Anet A6) is quite basic and lacks certain safety features that more sophisticated printers have, so I am not comfortable running it overnight. As such, I had to use the settings in my slicer software (Ultimaker Cura) to keep the print time down to within the window of a single day. I eventually tuned it to take 12.5 hours, but if I was printing to more desired quality it would be 22+ hours!

The fun pack of filament colours (PLA filament) I bought came with about 30g of a whole variety of colours (even glow-in-the-dark which you'll definitely see appear in a future project!). This I used to add the rainbow spectrum decoration to the side of the casing, which I think adds a lot to the project in terms of aesthetics. The first photo shows how I built this up - you'll need to fettle the fits a little with a knife/file to make sure they all fit snugly, but I didn't actually need to glue them.

Step 5: Rainbow Connection

Electrical details!

The wiring in this project is actually relatively simple you'll be pleased to hear! I haven't included a schematic as it's very simple to describe, and you'll be able to replicate it without difficulty. Bear in mind that there are two distinct circuits within the project, the 9V DC circuit (powered from a wall plug) that runs the bulb, along with a toggle switch to turn this on and off, and also the Arduino circuit (powered via USB from a PC) that also provides 5V DC to run the LED pixel ring, and the LDR (light dependent resistor).

I recommend soldering all of the electrical connections together and building the wiring into the main casing before doing any other assembly. That way the wiring will already be laid before you add any other printed parts. You'll see I allowed plenty of slack in the cable lengths, and then laid it roughly into the recesses of the casing, held down with electrical tape. It doesn't need to be too neat as all this will be enclosed by the housing lid later!

The DC-DC boost converter needs to be trimmed (by rotating the screw and testing the output with a multimeter) to provide 9V, which is what the torch battery requires.

A tiny piece of stripboard was cut which was used to make a mini 5V rail and GND rail from the Arduino, to which the other electrical components are interfaced. Please follow the specific instructions for the specific LED Ring you purchase, as there are some very similar models that have slightly different wiring, so I wouldn't want to advise you incorrectly. A 10k potentiometer is used to connect the LDR in a voltage divider circuit, but a larger value would probably be better, as I used this set to the maximum 10k position.

Step 6: Assembly Time!

Time to complete the mechanical assembly. It's going to get quite tight inside the housing!

  • After the prism assembly in is inside, a rubber band is used to go to the servo motor head (the servo motor is super-glued in place on the rails that support it). Due to COVID-19 related lockdown, I couldn't go out to source another in time, so this is an old one from the kitchen that once was wrapped around a bunch of asparagus! This rubber band is a little loose, but it still works.
  • The nuts for the M2.5 bolts are embedded into 9 locations in the housing, and super-glued in place.
  • The Uno and boost converter are just pressed into place, which was nice and easy.
  • After passing the USB power cable through the housing, I wrapped a little electrical tape around it on the inside, to prevent it from being pulled through the hole and damage the connections.
  • The LDR fits into a little plate, that fits into the void originally designed for the form factor of the BH1750 light sensor. This pushes into the housing, but I decided to secure it with extra electrical tape.
  • Underneath, four little self-adhesive rubber feet make for a nice grippy base to the unit. I think this adds a nice touch of quality to the feel of the device.
  • The light source assembly, even when printed in black PLA still leaked some light through the sides, so I wrapped black electrical tape around it too, which properly insulated it

Step 7: Testing!

Please download the attached Arduino code and get it uploaded to your Uno, but make sure to pay attention to the libraries that the code references that you'll need to install into your Arduino IDE if you don't already have them. It's necessary to check the pin attachments too, so make sure they match to how you've wired your system.

Testing time, and running the code will produce the sequence seen in the video (Section 1 of this Instructable!). Copy the data that comes in from the Serial Monitor in the Arduino IDE into Excel or similar, and you can produce a plot similar to that shown above. This shows the traces from all 8 colour samples I tested (the ones shown in the test tube rack, which are paint in solution). The portion of the plot that is relevant is bounded by the vertical lines, which show the portion of the prism's rotation that the colour spectrum is shining through the sample. Outside of those bounds we're not interested in, and the light recorded is extraneous from other errant light sources. It's interesting to see how the LDR picks up different levels of the different colours of light, and how it shows variation within the spectrum for each colour too. I need to conduct more testing to further understand the response of the LDR to different wavelengths of light (there are different types of LDR which respond differently), and analyse more samples, but I think it's a promising result so far.

Step 8: Conclusion: Somewhere Over the Rainbow!

I very much enjoyed working on this project over the 1.5 months it took from start to finish, it's taught me a lot about design, and also about the use of light in experiments.

If I had the opportunity to make improvements, a version 2 of this project would use a brighter light source so that more light could reach the sensor. It would also employ a larger value (larger than 10k ohm) resistor alongside the LDR sensor so that the device would be more sensitive to variations in low light levels. I would find a better sized rubber band to drive the prism assembly rotation (mine was too loose), and also print the housing with thicker walls or paint the insides with matt black paint to minimise the capture of light from sources other than the prism.

Thank you very much for reading, I hope that this interested you. If you do your own experiments based on this design, I would love to hear from you how you got on, and improvements that you could make! Please also comment if there are details you need that I've missed out, and I'll do my best to help.

Colors of the Rainbow Contest

First Prize in the
Colors of the Rainbow Contest

Be the First to Share


    • Toys & Games Contest

      Toys & Games Contest
    • Home Decor Challenge

      Home Decor Challenge
    • Box Challenge

      Box Challenge



    10 months ago

    Rotating the prism rather than moving the slot is a nice space-saving trick (compared to commercial units like the Cary-60 I use at work)!


    Tip 10 months ago

    You would be better to use a photodiode rather then an LDR. LDR's are notoriously nonlinear, and prone to age. You will need an amplifier between the photodiode and the Arduino. To get more dynamic range, have several gain stages (gains factors of 2) and feed each one into different Arduino A/D input. The "highest" one that is not saturated is your output.


    10 months ago

    A couple thoughts:
    -using black filiment and/or spraypainting the interior of your body with flat black paint (I've been told Krylon flat black grill paint is the best cheap stuff out there) will significantly help improve your signal-to-noise in your readings
    -you can use a CFL bulb (or better yet a couple laser pointers of different colors), which has spikes in the spectrum of known wavelengths, to calibrate the wavelength scale of your system
    -take a "flat" reading, using a sample tube filled with water, or nothing at all, and then subtract out the flat from all your other scans. This will calibrate your system for the specific bulb you're using as well as the spectral sensitivity of the light sensor.


    10 months ago

    Thanks for the very detailed, well designed and interesting instructables. :)

    I also have a question: can a simple E10 bulb produce light throughout the entire spectrum (from IR to UV), or did you choose it with respect to the visible spectrum only. I ask because full spectrum lights, which are used, for example, in plant cultivation or phototherapy, look different.

    I guess it would be good to do a Herschel's Infrared Experiment here to find out ;)

    Reply 10 months ago

    A standard incandescent bulb will produce light from IR through the visible spectrum (no significant light in the UV though). Though, worth noting that the luminance by wavelength is not uniform, so it would be best to calibrate it (maybe using a test tube with plain water).


    10 months ago

    Great Instructable! Did you ever consider using a photodiode array? I have no idea what they cost but I know it reduces the ambient light problem and it would, potentially, be able to do full spectrum scans in milliseconds with fewer moving parts.


    Question 10 months ago

    Hello. I cannot find the electronic assembly diagram.
    Please let me know.


    10 months ago

    Great project, Daniel! The level of detail and polish on this is outstanding! (this doesn't look like something someone hacked together, but rather a full-blow product that was purchased). Some (hopefully helpful) comments about the UX, as I watched the video from 1:35-2:05...

    First, when the process starts, all of the lights turn green. My impression while watching, was there isn't a indication that it's doing anything. My suggestion would be to animate the LEDs while processing. Maybe display only one LED at a time, and animate it like a clock (every second, change to the next LED)

    Second, when finished, the LEDs turned red. Red usually means something wrong happened, so I suggest that when finished, change all of the LEDs to green.

    Other than some minor UX issues, I thought this project was great. (and fantastic job!) I'm going to now go and check out your other video on building it in Fusion 360.


    10 months ago

    Great instructabale. I like the "Pink Floyd” inspired design!


    10 months ago on Step 3

    Small detail nothing to do with the project but Richard was the legal king not a claimant. It was Henry who usurped the throne.


    10 months ago

    Open Scientific Instrumentation Initiative (OSII)
    The purpose of this initiative is to develop scientific instrumentation that can be freely built by anyone, using resources available virtually everywhere and following contributions from an open community.
    A license must be developed, based on GNU public license V3. The projects should be made publicly available through that license.
    Instrumentation documentation should be available on a public repository, managed by a version control system like GitHub, GitLab or BitBucket. It should include 3D information on an open format, description of methods of fabrication, comments from factories, bills of materials, etc.
    Projects must be downloadable by anyone.
    Anyone can join the community.
    Contributors could communicate through many means, but a official forum should be hosted somewhere online.
    Contributions could be submitted to the community as suggestions, requirements or as new branches of the project, like any open source software project. Contributors should keep in mind that more and new functionality can be aggregated to the project at any time.
    About the projects:
    Three dimensional CAD projects should be made using a software that can be easily monitored for modifications by a version control system. Please consider using OpenSCAD and use the forum to share your ideas.
    The projects should be developed with modularity and scalability in mind. Modules should, whenever possible, be interchangeable.
    Each project should be accompanied by CAD files, bill of materials, list of companies that can execute its parts, list of places to buy raw materials, list of contributors etc. The directory structure should follow some very basic template to be developed.
    Some basic structural elements, after accepted, should never be changed for that version or all the already developed modules would have to be changed too.
    Project branches:
    New branches can be created following the version control options. Every contributor can download a project, create its own branch and then, maybe, commit it to the main project.
    Interfaces should be well thought and developed with scalability, interchangeability and modularity in mind.
    Deadlines could be useful, but if something is not converging, ending a branch and starting a new one with basic element modification should be possible and encouraged.
    A good starting point would be a low temperature equipment, but the main initiative should be able to handle arbitrary seeds.
    Eduardo N Hering, physicist, PhD.
    Please share.

    Penolopy Bulnick
    Penolopy Bulnick

    10 months ago

    This is such a great project! What program did you use to design the 3D printed parts?


    10 months ago

    This is amazing! Thank you for sharing :D