Building an instrument with Scratch

No, there’s no typo in the title. While this post does describe building an instrument (a colorimeter) from scratch, it also uses the Scratch programming language to control the operation of the instrument. Read on to learn the why’s and how’s.

The need for Instrument design

In Science in the Twentieth Century, Paolo Brenni argues that the 20th century saw an enormous development of scientific instrumentation that helped to revolutionize the physical and life sciences. As scientific instrumentation, and the underpinning semiconductor technology, evolved, instruments became more sophisticated and smaller. While instrumentation itself became more accessible, since user interfaces became more practical and costs were less prohibitive, the inner workings of the instrumentation became less accessible. The science (and art) of scientific-instrumentation design gave way to the ease with which we can purchase and operate complex commercial instrumentation.

We are now well on our way into the 21st century, and the technology available at our fingertips is staggering. Daily, we rely on gadgets that we assume operate properly. Americans spend $70 billion dollars annually on sports and fitness electronics (READ: sensors) that tell us how many steps we’ve taken and calories we’ve burned, but very few of us understand how those sensor work and even fewer bother to ask themselves: “are these measurements correct?”

It is these concerns that have encouraged me to incorporate instrument design into my teaching. My hope is that students will take away two important points:

  • Sensors and instrumentation are not magic, and it is possible to create sophisticated instrumentation on your own.
  • While (some) instrumentation design is, in principle, straightforward, there are complexities that reduce the accuracy and precision of the reported results, even in commercially available products.

But why a colorimeter?

Visible spectroscopy is a technique that students in the standard Chemistry curriculum are exposed to throughout their academic career. Chances are, they have performed this technique in each of the laboratory classes they’ve taken. By their senior year, they should understand the theory and application of visible spectroscopy; therefore, we can add the complexities of instrument design (electronics, sources, detectors, data acquisition and visualization) without having to teach the basic principles of the technique.

Plus, it involves LEDs, and any Maker worth his weight in integrated circuits will gravitate towards projects that involve blinky lights.

But isn’t Scratch for 12 year olds?

Science is all about understanding and manipulating your environment. Within 10 minutes, I had a classroom of twenty-somethings, none of whom had previous programming experience, clicking buttons to move and flip a silly-looking cat sprite, and they were giggling and excited about it! Another 10 minutes later, and the same students were using the same code that flipped a cat sprite to toggle an LED on and off (all but one had ever built a circuit prior to this class period). The fact that I could completely ignore syntax, indentation, and cryptic punctuation use and focus on clicking and dragging grammatically coherent blocks to create code is in my opinion the biggest advantage to using Scratch as an introductory programming language. That the Raspberry Pi version allows users to engage in physical computing (reading and writing to the GPIO pins of the computer), is simply amazing.

Let’s just say I’m intrigued

I have done a number of projects dealing with colorimetry, and one of them was published in MagPi. I used this article as a basis for my classroom activity. A rudimentary colorimeter can be fabricated using an LED and a photoresistor. Add to the circuit a decent-size capacitor, and you have a source and detector that can be controlled by a computer without having to deal with issues such as analog-to-digital conversion. The Scratch program therefore requires just two routines: one to toggle on and off the source LED and one to read the detector (photoresistor in series with a capacitor).

The challenge I posed to my students was this: design an instrument that can be used to estimate the amount of red food coloring in a commercial beverage. Here’s a photo of an instrument recently created by my students.

scratchcolorimeter3

The blue sample holder is 3D printed (you can find the STL files here if you are really interested) and the rest of the setup is the same as I described in the MagPi article. I included the cell holder because I just finished a sabbatical in which I proposed I would build a 3D printer and incorporate 3D printing into my teaching activities. Mission accomplished.

This Scratch code looks like this

scratchcolorimeter2

Students were then provided with stock solutions of red food coloring, from which they created calibration curves and explored various aspects of instrument accuracy, precision, and robustness. All groups were able to establish a decent relationship between concentration and detector response, and all but one group was able to get reasonably accurate results (red commercial beverages in the US contain about 1-5 mg/L red dye).

The verdict?

Most of the students were engaged in the instrument design and several were visibly excited when they successfully controlled the LED and photoresistor using Scratch. They were equally frustrated when they couldn’t reproduce their results until they recognized the critical importance of a stable design (LED, sample holder and photoresistor not being moved in between sample measurements). The experiment reinforced concepts of spectrophotometry and calibration curves, and the information generated (the amount of food coloring in beverages they drink) had a real-world connection that provided relevance to the project. A couple of the students (outside of class, of course) revealed their inner geek by sharing with me the Raspberry Pi information they learned about on the internet or by talking to other friends, who happened to be closet geeks as well.

Published by

BoB

The guy who runs this show.

Leave a Reply

Your email address will not be published. Required fields are marked *