Hacking STEMJen Fox
Published © MIT

Hacking STEM DIY Spectrometer

Build a simple spectrometer out of LEDs to see what wavelengths are in different types of light!

BeginnerFull instructions provided1 hour4,892
Hacking STEM DIY Spectrometer

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
IR LED
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
LED, Blue
LED, Blue
×1
UV LED
×1
Through Hole Resistor, 10 ohm
Through Hole Resistor, 10 ohm
×5
Jumper wires (generic)
Jumper wires (generic)
×7
sandpaper
×1
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Microsoft Data Streamer
Microsoft Data Streamer
Arduino IDE
Arduino IDE
Microsoft Excel

Story

Read more

Schematics

Spectrometer Diagram

Full Fritzing diagram for a 5-LED spectrometer: IR, red, green, blue, and UV

Code

Radiation.ino

Arduino
--------------------HackingSTEM EM Spectrum-------------------------------
This project is for use with the EM spectrum lesson plan available from Microsoft Education Workshop at http://aka.ms/hackingSTEM

Overview:
This sketch uses LEDs as light sensors (photodiode) to detect and measure different wavelengths in various types of light sources.
// --------------------HackingSTEM EM Spectrum-------------------------------
// This project is for use with the EM spectrum lesson plan 
// available from Microsoft Education Workshop at http://aka.ms/hackingSTEM 
// 
// Overview: 
// This sketch uses LEDs as light sensors (photodiode) to detect and measure 
// different wavelengths in various types of light sources.
//
// Pins:
// Pin A0: IR LED
// Pin A1: Red LED
// Pin A2: Green LED
// Pin A3: Blue LED
// Pin A4: UV LED
//
// This project uses an Arduino UNO microcontroller board. More information can
// be found by visiting the Arduino website: 
// https://www.arduino.cc/en/main/arduinoBoardUno 
//
// Comments, contributions, suggestions, bug reports, and feature requests 
// are welcome! For source code and bug reports see: 
// http://github.com/[TODO github path to Hacking STEM] 
// 
// Copyright 2019, Jen Fox, Microsoft EDU Workshop - HackingSTEM 
// MIT License terms detailed in LICENSE.txt 
// ----------------------------------------------------------------------------

// Program variables for project sensors --------------------------------------
const int kNumberOfLeds = 5;
int kledPins[kNumberOfLeds] = {A0, A1, A2, A3, A4};

// Excel variables for storing data sent to Excel -----------------------------
int colorSensors[kNumberOfLeds] = {1, 2, 3, 4, 5};

//Serial data variables
const char kDelimiter = ',';
const int kSerialInterval = 50;
unsigned long serialPreviousTime;


// SETUP ----------------------------------------------------------------------
void setup() {
  // Initializations occur here
  Serial.begin(9600);    
  _SFR_IO8(0x35) |= 0x10;   // A condensed method for disabling the internal 
                            // pull up resistors in the Arduino.

// This function changes the reference voltage for measuring the analog voltage
// of the LEDs to a 3.3V reference. This is why we added the jumper cable 
// between 3.3V to AREF!
  analogReference(EXTERNAL); 

}

// START OF MAIN LOOP --------------------------------------------------------- 
void loop()
{
  // Process sensors
  processSensors();

  // Process and send data to Excel via serial port (Data Streamer)
  processOutgoingSerial();

}

// SENSOR INPUT CODE-----------------------------------------------------------
void processSensors() 
{
  // Read analog value of LED inputs
  for(int i = 0; i < kNumberOfLeds; i++){
    colorSensors[i] = analogRead(kledPins[i]);
  }
  
  delay(10); //short delay to prevent the Arduino from overclocking
}

// Add any specialized methods and processing code here

// OUTGOING SERIAL DATA PROCESSING CODE----------------------------------------
void sendDataToSerial()
{
  // Send data out separated by a comma (kDelimiter)
  for(int i = 0; i < kNumberOfLeds; i++){
      Serial.print(colorSensors[i]);
      Serial.print(kDelimiter);
  }

  Serial.println(); // Add final line ending character only once
}

//-----------------------------------------------------------------------------
// DO NOT EDIT ANYTHING BELOW THIS LINE
//-----------------------------------------------------------------------------

// OUTGOING SERIAL DATA PROCESSING CODE----------------------------------------
void processOutgoingSerial()
{
   // Enter into this only when serial interval has elapsed
  if((millis() - serialPreviousTime) > kSerialInterval) 
  {
    serialPreviousTime = millis(); // Reset serial interval timestamp
    sendDataToSerial(); 
  }
}

Credits

Hacking STEM

Hacking STEM

10 projects • 39 followers
Build affordable inquiry and project-based activities to visualize data across STEM curriculum.
Jen Fox

Jen Fox

17 projects • 58 followers
Dabbled in dark matter, settled into engineering w/ a blend of inventing and education! Founder/CEO of FoxBot Industries

Comments