Project showcase
MiniSpec

MiniSpec © GPL3+

Using an Arduino, light detecting resistors, and RGB LEDs, I made a fun to use, miniature spectrometer.

  • 3,080 views
  • 0 comments
  • 7 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

About this project

I had been wanting to build something like this for some time, but didn't have the impetus until given a class project for a chemistry lab. We were tasked with recreating an instrument from the lab and I chose to mimic the UV-VIS. While I did not incorporate a UV or IR LED in this project, it will scan from 380 nm to 780 nm. Recording light intensity into an array allows for easy output of absorbance values (after a calibration run). The switch toggles between calibration and determination modes and the button starts the cycle. The LEDs on the top of the box are status LEDs. Inside the box are 2 RGB LEDs and 2 LDRs. Check out http://bradmartinscience.com/minispec for the full story.

Code

MiniSpecArduino
Using an Arduino, light detecting resistors, and RGB LEDs, I made a fun to use, miniature spectrometer.
int buttonVal, toggleVal, cal = 0; 
int sample = 1;
int buzzer = 13;
int toggle = 8; int button = 7;
int redPin = 9; int greenPin = 10; int bluePin = 11; //RGB Led
int goodPin = 5; int statusPin = 6;
int sensorPinOne = A0; //LDR
int sensorPinTwo = A1;
int cellOne[2][41]; int cellTwo[2][41];
double wavelengths[41] = {380, 390, 400, 410, 420, 430, 440, 450, 
						  460, 470, 480, 490, 500, 510, 520, 530, 
						  540, 550, 560, 570, 580, 590, 600, 610, 
						  620, 630, 640, 650, 660, 670, 680, 690, 
						  700, 710, 720, 730, 740, 750, 760, 770, 780};
double colors[41][3] = 
	{	{97,  0,  97}, {121, 0, 141}, {131, 0, 181}, {126, 0, 219}, {106, 0, 255}, {61,  0, 255}, {0,  0,  255}, {0,  70, 255}, 
		{0, 123, 255}, {0, 169, 255}, {0, 213, 255}, {0, 255, 255}, {0, 255, 146}, {0,  255,  0}, {54,  255, 0}, {94,  255, 0}, 
		{129, 255, 0}, {163, 255, 0}, {195, 255, 0}, {218, 255, 0}, {255, 255, 0}, {255, 223, 0}, {255, 190, 0}, {255, 155, 0}, 
		{255, 119, 0}, {255,  79, 0}, {255,  33, 0}, {255,  0,  0}, {232,  0,  0}, {210,  0,  0}, {188,  0,  0}, {165,  0,  0}, 
		{143,  0,  0}, {237,  0,  0}, {219,  0,  0}, {200,  0,  0}, {181,  0,  0}, {161,  0,  0}, {141,  0,  0}, {119,  0,  0}, {97,   0,  0}	};
float transmittance[2]; float absorbance[2];
unsigned long previousMillis = 0; const long statusInterval = 300; //Debouncing

void setup() {
	Serial.begin(9600);
	pinMode(buzzer, OUTPUT);
	pinMode(toggle, INPUT); pinMode(button, INPUT);
	pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT);
	pinMode(goodPin, OUTPUT); pinMode(statusPin, OUTPUT);
	pinMode(sensorPinOne, INPUT); pinMode(sensorPinTwo, INPUT);
	Serial.println("--- MiniSpec ---"); Serial.println();
	tone(buzzer, 400, 150);
}

void loop() {
	toggleVal = digitalRead(toggle);
	analogWrite(goodPin, HIGH); analogWrite(statusPin, LOW);
	setColor(0, 0, 0);
	
	if (toggleVal == 0) {
		if (digitalRead(button) == 1) {
			stabalize();
			analogWrite(goodPin, LOW); 
			for (int x=0; x<41; x++) {
				analogWrite(statusPin, HIGH);
				setColor(colors[x][0], colors[x][1], colors[x][2]); delay(333);
				cellOne[0][x] = analogRead(sensorPinOne); cellTwo[0][x] = analogRead(sensorPinTwo); delay(10);
			}
			Serial.println("Calibration Complete"); Serial.println();
			cal++;
		}
	}

	if (toggleVal == 1) {
		if (digitalRead(button) == 1 && cal >= 1) {
			stabalize();
			analogWrite(goodPin, LOW); 
			for (int x=0; x<41; x++) {
				analogWrite(statusPin, HIGH);
				setColor(colors[x][0], colors[x][1], colors[x][2]); delay(333);
				cellOne[1][x] = analogRead(sensorPinOne); cellTwo[1][x] = analogRead(sensorPinTwo); delay(10);
			}
			setColor(0,0,0);
			analysis();
		} else if (digitalRead(button) == 1 && cal == 0) {tone(buzzer, 100, 200);}
	}
}

void stabalize(void) {
	setColor(255,255,255);
	for (int y=0; y<5; y++) {
		analogWrite(goodPin, LOW); delay(300);
		analogWrite(goodPin, HIGH); delay(300);
	}
}

void setColor(double red, double green, double blue) {
	analogWrite(redPin, (int)red);
	analogWrite(greenPin, (int)green);
	analogWrite(bluePin, (int)blue);
}

void analysis(void) {
	Serial.println(); Serial.print("Sample "); Serial.println(sample); Serial.println();
	previousMillis = millis();
	for (int x=0; x<41; x++) {
		transmittance[0] = (float)cellOne[1][x]/(float)cellOne[0][x];
		transmittance[1] = (float)cellTwo[1][x]/(float)cellTwo[0][x];
		absorbance[0] = log10(1/transmittance[0]);
		absorbance[1] = log10(1/transmittance[1]);
		float avgAbsorbance = ((absorbance[0] + absorbance[1])/(float)2);
		Serial.println(avgAbsorbance);
		delay(100);
		if (millis() - previousMillis >= statusInterval) {
			analogWrite(statusPin, LOW);
		}
		if (millis() - previousMillis >= statusInterval*2) {
			analogWrite(statusPin, HIGH);
			previousMillis = millis();
		}
	}
	sample++;
}

Schematics

MiniSpec
Using an Arduino, light detecting resistors, and RGB LEDs, I made a fun to use, miniature spectrometer.
Screenshot 2017 04 18 at 1 ysczf6umaf

Comments

Similar projects you might like

Temperature and Humidity Logger (Using Arduino)

Project showcase by lmsousa

  • 26,147 views
  • 12 comments
  • 49 respects

SIGFY (Sigfox Farm Yield) with Crop and Health Monitoring

Project tutorial by SIGFY

  • 10,383 views
  • 4 comments
  • 34 respects

Rover for Cave Exploration

Project tutorial by ACool

  • 7,049 views
  • 4 comments
  • 33 respects

Arduino And MQ2 Gas Sensor

Project showcase by Mahamudul Karim Khondaker

  • 29,355 views
  • 12 comments
  • 27 respects

Healthcare Skin Pressure Detector

Project tutorial by David Escobar

  • 15,831 views
  • 3 comments
  • 26 respects

LCD Screens and the Arduino Uno

Project tutorial by Mahamudul Karim Khondaker

  • 4,147 views
  • 1 comment
  • 3 respects
Add projectSign up / Login