Introduction: Science With Rainbows! - Spectrophotometry

About: Where's the tea?

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)

Consumables

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

Supporting

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

Software

  • 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