Вы находитесь на странице: 1из 26

Arduino Fun

with Light
and Spectrometers

Kenneth B. Moore
Copyright 2012 Kenneth B. Moore
All rights reserved.
ISBN:
ISBN-13: 978-1539695134
CONTENTS
1

Introduction
Requirements
Software
Components
2 Project 1 Live data to excel from an Arduino Light Sensor
Wiring Up
Arduino Code
Shielding the sensor
Experiment 1: Measuring light changes from day to night
Observations
Conclusion
Summary
Experiment 2: Trip Wire Laser Alarm
Game 1 - Avoidance
Game 2 - Race
3
Project 2 Single Beam Spectrometer
Definitions
Uses of Spectrometers
Why Black
Sample Holder
Slits
Diffraction grating
Light Source
Making a Light Shield
Wiring up the Arduino
Arduino Code
Collecting the data
Summary
4
About the Author

5
6
6
7
9
10
12
14
15
15
16
16
17
18
18
20
20
21
22
22
23
24
24
25
26
27
30
32
34

1 Introduction
I have always enjoyed tinkering, and when I discovered the Arduino it was great to be able to build
objects that could be programmed for control and movement without the need for constant connection to
a pc. I suppose as with anyone else having a hobby, I purchased or borrowed books on the subject.
Books on basic control, turning lights on using motors etc., but there did not seem to be anything that
covered the transmition of data back to the computer, they all covered the use of the board in standalone
configurations. This book is aimed at starting to bridge that gap and covers how to transfer captured data
back to the pc for more advanced manipulation.
To this end this book will cover in basic the following areas and projects:
1.

Software and requirements for transfer of data - while there may be a lot of packages available
for this kind of activity by the time you read this, I am only going to be using one and best of
all is that currently it is free - the package of choice is called PLX-DAQ and is and add in
along with suitable Arduino code that opens the U.S.B. port and allows Microsoft Excel to
capture the information.

2.

Project 1 - Light level sensor - This is really the first step towards the spectrometer and allows
you to monitor light levels while a sensor is directed towards the source.

3.

a.

Experiment 1 Measuring light changes from day to night demonstrates how the
sensor can be used to monitor light levels as well as picking up abnormal changes in
light, say for example a security light coming on

b.

Experiment 2 Light Game - Taking the Light Level Sensor one step further this
exercise uses a light trip wire to create a game as well as demonstrating another user
for monitoring light levels

Project 2 - Single Beam Spectrometer - This one builds on the previous activities to as well as
some hobbyist skills to make a functioning spectrometer capable of measuring a range of
spectral conditions to produce charts that can then be manipulated to the measurement of
concentrations of solution for any number of applications

Requirements
Software
The Arduino IDE There are three software requirements for the projects in this book to allow
information to pass from the Arduino to the computer. The first is the Arduino IDE which is free to
download from the following location and comes as either an install of zip file. There are benefits to
both options, the install file gives you a dedicated setup on your computer making it simpler to install
add ins for the IDE, while the zip file allows you to make the IDE portable enabling it to run directly
from a flash drive. The portable is my preferred option, but either will work just fine.

The address for the Arduino software is - http://arduino.cc/en/main/software - just type this into your
browser and select the IDE version that you wish to work with this is usually the most up to date one,
however previous releases are also available simply scroll down the page to find the previous releases
link
Microsoft Excel Unfortunately this is not free not free which makes it rather restricting as it is a
specific requirement of the data transfer process.
Parallax Excel add-on Finally the most important piece of software is called Parallax Data Acquisition
(PLX-DAQ) from Parallax inc. and is the add-in that allows Excel to acquire up to 26 channels of data
from your microcontroller. As before the address is shown simply copy this into your browser
http://www.parallax.com/downloads/plx-daq and select the PLX-DAQ.zip download file.
The PLX-DAQ file runs as a macro from inside Excel and is a great little file as it can be used to
monitor any serial port and gather the resultant data sent through it. All that is required is some specific
lines of code in the Arduino sketch to tell it the send data to your pre-defined cells in Excel. You also
need to specify the port speed and ensure that the Arduino is set to the same speed I initially used
9600, and although this worked for the test spreadsheet that only sent text to excel from the Arduino, I
needed to set it to 128000 for the final project as I would be monitoring the response times for the LED's
dependent upon the resistance of the light dependent resistor at any given time.

Figure 1 Excel control form for the PLX-DAQ add-in

Components

Arduino Uno
Jumper wires
Jumper Board
Resistor
Potentiometer

1
Various lengths and number
1
10 x 33 ohm (approx.)
1

Project 2 - Single Beam


Spectrometer
1
Various lengths and number
1
10 x 33 ohm (approx.)
1

Light Dependant Resistors

AAA for the light source

AAA for the light source


9 volt in the event you make the
project portable

Project 1 - Light level sensor

Batteries

LED Light source

Lazer Pointer

Paint

-- Plastic tube
Material for base I used plastic,
Construction Materials
but anything to secure the tube
will do

Cheap LED tourch or head


inspection lamp
Black Poster Paint
5 mm MDF
Black Card
Double sided sticky tape
Hot melt glue gun

The LED's are low values and the Potentiometer was one I had laying around while the LDR was one
salvaged from an old toy so the value for these, is not important as far as being able to transfer data.
However playing with different ratted components will allow you to fine tune the calibration.
Initially I tried these projects using a number of different resistors and found a great site by Danny
Goodman for calculating there values, the address for which is http://www.dannyg.com/examples/res2/
resistor.htm - see figure 2 the site is simple to use just select the colours for the resistor bands and it
displays the value for the resistor. I eventually settled on 33 ohm resistors - these where considerably
smaller than my first attempt using some a rescued from an old alarm system which were way too big
leaving me wondering why nothing worked when I switched the "finished thing on"?.
Figure 2 Danny Goodmans graphical resistor calculator

A light source is also required for project 3, the spectrometer for this I chose a battery powered head
inspection lamp, which was purchase from the pound shop and came complete with the AAA batteries
required.

2 Project 1 Live data to excel from an Arduino


Light Sensor
I started this little project as a way to show how to use a basic sensor with the Arduino, however its
turned out to be a bit more interesting. The original idea was to take a very simple project (examples in
one form or another are available all over the web) add a sensor and reprogram it in a way that would
allow the sensor (a Light Dependent Resistor) to control the lights. After all, a lot of the wiring on
projects can be the same its the programming that changes the way it works.
Once wired up I realized that this was quite a sad project, so decided to try to link the serial port back to
the computer to send real time data to a graphing package.
There are a lot of uses for this:

As a diagnostic tool to monitor and display results from your robotic sensors to ensure that
they perform as required on your projects.

Monitoring light levels to see how they change throughout the day, comparing different
weather conditions to see how light effects our environment e.g. plant growth.

Security sensors to track access and egress from a room

Yes you can do this in the monitor window of the Arduino software, but you cannot save or trend the
data in that application.
The final set up will look like the image in figure 4 with some typical output data shown in figure 5
Figure 3 Completed light sensor project

Figure 4 Example data from the light sensor

Wiring up
Set up you Arduino as per the images to follow.
Connect jumper wires using digital pins 4 to 13 connecting these to one side of a resistor, on the other
side of the resistor connect the positive side of the LED (dont worry too much if you get the odd LED
that does not light when the project is up and running simply turn the LED around and that should solve
your issue.) The Resistors are in place to stop power surge from damaging the Light Emitting Diodes,
the potentiometer is used to adjust the rate of the LEDs change from Off to On.
All of the far side connections from the LED go to one side of the potentiometer. This will allow you to
control the rate at which the LEDs are lit in sequence and is important as depending upon how fast the
cycle is you can flood the LDR resulting in the LEDS cycling so fast that they appear to be on all the
time. What you are looking for is a cycle that produces a range of values to fast and the range is to
small to slow and you fall asleep waiting for the next light to come on. It is this time related value that
is sent to the computer and can later be plotted assuming you have set up data capture in some way.
So in summary the POT is used to calibrate the data rate through to Excel.

Figure 5 Initial Arduino connections

Figure 6 Attaching LEDs and resistors

Figure 7 Line diagram for Wire connections

Arduino Code
Parallax The Parallax install file creates a couple of example spreadsheets which are really all you
need on the Excel side. Once installed all you need do is open the example file and accept the use of
macros- at which point the PLX DAQ control will open. Set it up as per Figure 1 ensuring that you
select your com port and not the one I have used (unless yours happens to be COM 3 as well)

Arduino The following is the code allows the Arduino to read the potential difference between the
Arduino pins 5 volt and A2. The potential value first being calibrated using the Potentiometer to make it
readable.
To calibrate the setup completely cover the LDR so that its resistance drops to as close to nothing as is
possible (this makes the LEDS change very quickly) then adjust the POT until the cycle rate reaches a
point where you can see each LED turning on and off in sequence. The more you adjust the POT the
great you can make the time changes registered at Excel, but be careful not to go too far or you will not
see data at the other end of the scale (i.e. when you expose the LDR to light again)
Type the code on the next page into the Arduino IDE editor as per Figure 8

//Declarations - set up the variables to be used in the application


byte ledPin[] = {4, 5, 6, 7, 8, 9, 10,11,12,13}; // Create array for LED pins
int potPin = 2; // select the input pin for the potentiometer
int ledDelay; // Set a delay period LED Change
int delayData = 80; // Set a delay period for the data transferred to Excel and attempt to reduce data
volumes
int direction = 1;
int currentLED = 0;
int x = 0; //Set the initial counter for LED OUTPUT
int row = 0; // Set the starting Excel row
unsigned long changeTime;
//---------------------------------------------------------------------------------------------------// Setup Arduino Serial-rate, clear data/send headings for the data transfer to excel
void setup() {
Serial.begin(128000); // opens serial port, sets data rate128000 bps
Serial.println("CLEARDATA"); //clears any residual data
Serial.println("LABEL,Time,Pin,Light Level");
// Reset all pints for the LEDs to digital output
for (int x=0; x<10; x++) {
pinMode(ledPin[x], OUTPUT); }
changeTime = millis();
}
void loop() {
ledDelay = analogRead(potPin); // read the value from the pot
if ((millis() - changeTime) > ledDelay) { // if it has been ledDelay ms since last change
changeLED();
changeTime = millis();
}
}
void changeLED() {
for (int x=0; x<10; x++) { // turn off all LED's
digitalWrite(ledPin[x], LOW);
}
digitalWrite(ledPin[currentLED], HIGH); // turn on the current LED
currentLED += direction; // increment by the direction value
// change direction if we reach the end
if (currentLED == 9) {direction = -1;}
if (currentLED == 0) {direction = 1;}
// Send the data to excel and delay the next step for teh set period of time
Serial.print("DATA,TIME,"); Serial.print(currentLED); Serial.print(","); Serial.println(ledDelay);
row++;
x++;
delay (delayData);
}
Figure 8 Arduino IDE editor example

Shielding the sensor


When I carried out the initial testing the LDR worked well by itself, but I found that the chart produced
in excel was very noisy - this was due to too much light getting to the sensor - it was picking up not only
the light being measured but also the ambient light in the room.
The solution was to place the LDR in a tube, I also mounted it on a little base. This shields the sensor
from the light in the room making the sensor more directional.
Figure 9 Sensor Shielding

Now that you have it all put together its time to have a play The following are two of many potential
experiments for this setup.

Experiment 1: Measuring light changes from day to night


Set up the circuit so that the LDR is pointing towards a window (See Figure 10).
When ready open the Excel file and then connect the USB cable - once the Arduino has been recognized
the LEDs will start to cycle. To start collecting data in Excel select the Connect button on the PLX-DAQ
panel (Figure 11)
Leave the whole thing running for however long you wish (keep in mind that the longer its left the more
data will be collected) however due to the nature of this experiment it will need to be a long time as a
small amount of data will not tell you anything.
Test conditions:

Readings were taken from 18:59:04 until 20:51:37 approximately 2 hours

During the collection period 15164 readings were taken

Weather fine with no rain

The information was plotted on a chart (Figure 12) the data plot is the blue line on the chart with the
orange line being a manipulation of the data and shows the difference between the current and preceding
value i.e. a differential value
Observations:
There are four areas on the chart that show points of change. As follows

Point 1:- This is a test section to make sure that the sensor was working - I put my hand
over the end of the tube

Point 2:- The blue line starts to decrease as light levels drop - from the differential plot
you can see that the line starts to get more noisy - I think this is due to the fact that while
the sun is up the sensor is still getting flooded with light and as the levels drop the LDR is
able to pick up more changes in light levels - possible causes stars/side lights from
neighbors houses etc.

Point 3:- There is a definite increase in light levels at 20:43:19 where the response time of
the sensor increases from 59 milliseconds to 110 milliseconds this does not seem much,
but if you look at the Differential change it goes from -2 to 41 an increase of 43
milliseconds and marks the start of the light increase.

Point 4:- At 20:44:33 the readings go from 134 to 79 a differential drop of 58 milliseconds
and marks a return to the normal light level reduction seen in the rest of the data.

Conclusion:
Light levels drop evenly over time, but it is possible to pick up smaller changes as it becomes darker due
to increased sensitivity of the sensor.
The increase in levels over a 1 minute 14 second period starting at 20:43:19 is due to a security light at
the end of our garden a distance of 20 m away. The light is set to come on and stay on for approximately
1 minute which fits with the duration on the chart.
Summary
I think the sensor works great, it detects light changes far better than expected, and was able to pick up
changes at quite a distance, it would be good to try other types of sensor possible a Diode Array
(basically LDR set to detect different frequencies of light). It might also be possible to increase
sensitivity by making the inside of the shielding black instead of the white plastic tube currently used.
Figure 10 Completed Light sensor set-up

Figure 11 PLX-DAQ console window as see in Excel

Figure 12 Chart of data for the daylight monitouring exercise

Experiment 2: Trip Wire Laser Alarm


The aim of this exercise is to see if you can detect the breaking of the laser trip wire as well as being
able to calculate the length of time it was interrupted for.
For this you will need a few players, I enlisted my son as he has one of those SPY kids laser light alarms
sets and at eight years old he thought it would be impressive to do. As well as one of my daughters and
her friend.
Together we set up the laser and bounced it down the corridor using the set mirrors that came with the
toy, (Note you can do this with just a laser pointer directed straight at the sensor although this will make
the game short) the only bit we did not use from the toy wad then alarm pickup replacing this with the
Arduino Sensor.
Because of the shield around the LDR we were able to ensure that the laser hit the surface of the sensor.
This time I think the white tube helped as it reflected some of the beam inside and made it easier to get
the most light onto the LDR as possible.

Figure 13 Laser trip set up to provide three lines to break

My Daughter had a friend around so we made it a game in two parts.

Game 1 - Avoidance
To see if they could move up the corridor without breaking the beam. (See figure 14 Data Chart)
You can see on the chart that person 1 was the most hesitant going through the beams from the length of
time between reading changes, but got quicker as she moved along. (This was my daughters friend)
My daughter took the longest time getting through and seems to take the least time breaking the beams
when she did and my son was the fastest and did not break as many of the beams as the girls did, but he
did have the advantage of having helped to set the mirrors up in the first place.
Figure 14 Game 1 trip wire data

Game 2 - Race
Who could do the journey fastest by first breaking the initial beam (marking the start) and then making it
to the end and back without breaking any more then finally breaking the same beam as before to mark
the end of the run? (See figure 15)
You can see a difference in the scale of the two charts, with the game one chart spanning 60 milliseconds
while the Game 2 chart only 14 milliseconds - I have put this down to a possibility that the mirrors may
have moved slightly during the first game (quite possible as its a laminate floor that has a little flex in it
due to the insulation under it. This resulted in a lower response from the sensor, but still readable. I have
not included the differential this time as it hides the run data.
My son went first and did better than last time not breaking any beams except the initial bean at start and
finish of his run, however he did take the longest
My Daughters friend went next and had a faster run - I think the variation in her run was due to the
reducing sensitivity as she bounced past the mirrors
My daughter won the race she seems to have been more carful than her friend with the line being more
stable she did not break any beams other than the ones she was supposed to, however she did spend a

fair amount of time in the last beam, but as I marked the end as being the first change in levels she was
the quickest.
Figure 15 Speed trial data

This was a fun use for the setup and quite a simple one that occupied the kids all afternoon, Im sure
there are others.

3 Project 2 Single Beam Spectrometer


In this exercise I wanted to add a diode array in place of the LDR, unfortunately I have not been able to
get hold of one, so the LDR stays and this will be a scanning spectrometer.
Figure 16 Completed Spectrometer

Definitions
Diode array spectrometers These work generally by having no moving parts. The light passes through
the sample and is split into its separate spectral components using a prism or similar device.
The separate wavelengths then fall onto the detector where each absorbance value is measured at the
same time.
Figure 17 Diagram for the light path in a Diode Array Spectrometer

Scanning spectrometers These work slightly differently in that the light is first split by the prism, it
then passes through a narrow slit which helps to reduce the number of wavelengths of light that can pass
through the sample and hence fall onto the detector at any given time. In this type of system there is a
single detector that has to measure each value in turn and because of this the light splitting device has to
rotate to direct the sequence of wavelengths onto the sample and so onto the detector.
The spectrometer we will build will use a diffraction grating, in this case a hologram printed onto a
piece of glass, I got this from work (a spare from a service visit), but if you dont have access to
something like that then you can get the same effect using a piece of DVD cut to a suitable size.
Figure 18 Diagram for the light path in a Scanning Spectrometer

Uses for Spectrometers


The usefulness of this instrument is limited only by your imagination examples are as follows:

Analysis of the light spectrum (measuring the amount and color of available light)
Measurement of spectral reflectance transmittance and absorbance of materials
Food colorants analysis
Environmental analysis - pollution in water - its inexpensive and connects to a laptop for
portability
Training tool (educational) A great way to get your children into programming and developing
imaginative solutions.

The above and many more would of course all require calibration of the equipment
Figure 19 Light Spectrum

Why Black
Spectrometers work by taking measurements of light, either the transmittance or the absorbance. So
allowing any additional light into the sensor while in use would adversely affect the results.
Painting everything mat black helps to eliminate reflection and reduce stray light
Figure 20 Paint it Black

Sample Holder
The sample holder is just that. When you are performing an analysis your sample solution is held in
what is called a Cuvette, a glass container that is as optically pure as possible. This Cuvette is placed in
the instrument in a holder that is in the path of the light coming from the diffraction grating.
For this exercise I have made one on a lathe. I started by turning one end which would later be held in
the jaws on the lathe chuck, this would ensure that it was centered. Once flipped I drilled a hole in the
end that would hold the Cuvette - see the third picture of figure 21 - and went on to drill two holes one
opposite the other at the square end of the piece. This would be the path through the sample for the light
reaching the sensor.
As I wanted as much light to reach the sensor as possible I made one of the holes slightly larger. I tidied
the piece up and cut a Tenon just below where the bottom of the Cuvette sat in the central hole and
parted it off.
Figure 21 Making the sample holder

The sample holder was then painted black inside and out once I used a hot melt glue gun to secure the
LDR sensor in place, because the glue is slightly translucent this was also painted black. I had put a hole
into the corner of a piece of MDF intended for the base and held the sample holder in place using a
wooden washer and screw this would allow me to rotate the sample holder to improve alignment with
the light beam.

Figure 22 Attaching the sensor

Slits
Once the light is split by the diffraction grating there is a need to limit the portion of the spectrum that
hits the sample. To do this you use a device called a slit and as it sounds this is just a very thing parallel
gap which is placed in front of the sample holder. For mine I hot glued two Stanley knife blades over an
opening in a small panel that would be glued in front of the sample holder along with another piece to
form a small "dark room" around the sample. This too was painted black.
Figure 23 Slit construction

Diffraction Grating
The diffraction grating was mounted onto an R.C. servo and hot glued in front of the slit at a slight
angle. The exact angle is not important as the software used later will control the direction/angle of the
grating.
You will see on the pictures (figure 24) that I cut a hole to take the servo, but in the end this was not
required as the servo needed to be lifted up so that the grating was in front of the slit and not below it.
The hole was filled with hot met glue which also held the servo solid.
Figure 24 attaching the servo and grating

Light Source
For the light source I started using a simple torch, but found that the incandescent bulbs produced a very
diffuse spectrum (pattern of split color) once the light left the grating. So a quick visit to the local pound
shop and I had one of those battery powered led lights that you strap to your head.
To hold it again I turned to the lathe to make a hollow tube and support, which would be kept in place by
another Tenon through the base.

I had only intended to take one of the LED lights from the torch, but when I took the head lamp apart
found that just about the whole cluster fit into the tube and as it held itself in place quite securely there
was no stray light issue.
With all the parts made, or in place I used the hot melt glue to fix the sides in place to complete the box
and then painted all of it black.
Figure 25 Mount the light source

Making a Light Shield


Once I started collecting data I found that too much light reached over the sides of the dark room and
reduced the sensitivity of the instrument so I decided the spectrometer needed additional light shielding.
Enter my wife's hobby - card making - I borrowed her scoring board to make creases in the cardboard
used for the shield. If you dont have card scoring kit then a ruler and the back of a pair of scissors will
do just as well
I have not included a template for this as its shape and size will depend upon the dimensions of your
construction. Just to say that I used double sided sticking tape to hold the joints together and when I
came to cutting the hole for the Cuvette I put the cover in place then pressed on the top to make an
indentation for the hole I needed to make, then a craft knife was used to make the cut.
Just a word of caution make sure you line up the slit carefully or you will block the source.
Figure 26 making the light shield

Wiring up the Arduino


Please see the images for the wire diagrams
You will note that I have given two options one includes a battery, a better way to power the system than
relying on the USB power from a computer, although you will still need to attach the USB cable as it is
needed to collect the live data as you carry out experiments.
Figure 27 Completed wiring

Figure 28 Option one using the USB connection for power

Figure 29 Option two make it more portable using a battery

Arduino Code

The Parallax install file creates a couple of example spreadsheets which are really all you need on the
Excel side. Once installed all you need do is open the example file and accept the use of macros- at
which point the PLX DAQ control will open. Set it up as per the previous image in step 1 making sure
that you select your com port and not the one I have used (unless yours happened to be COM 3 as well)
The attached code allows the Arduino to read the potential difference between the Arduino pins 5 volt
and A2. The potential value first being calibrated using the Potentiometer to make it readable. As well as
moving the servo so as to all different regions of the spectrum to fall on the sample and sensor.
The calibration is done by completely covering the LDR so that its resistance drops to as close to
nothing as possible (this makes the LEDS change very quickly) then you adjust the POT until the
cycling light change from the LEDs is visible.
The more you adjust the POT the greater you can make the time changes registered at Excel, but be
careful not to go too far or you will not see data at the other end of the scale (i.e. when you expose the
LDR to light again)

//-Tittle:.......... Scanning Light Spectrometer----------------------------------//-By:.............. Kenneth B. Moore---------------------------------------------byte ledPin[] = {4, 5, 6, 7, 8, 9, 10,11,12,13}; // Create array for LED pins
int ledDelay;
// delay between changes
int direction = 1;
// set the initial direction of the indicator LEDs
int currentLED = 0;
// zeros the count for the position of the LED
int x = 0;
int row = 0;
unsigned long changeTime; // variable for value of time taken for LED change
int potPin = 2;
// select the input pin for the potentiometer
int delayData = 80;
//--------------------------------------------------------------------------------#include <Servo.h>
Servo servoMain;
// Define our Servo
int servoCount=0;
int servoMove=0;
//--------------------------------------------------------------------------------void setup() {
Serial.begin(128000);
// opens serial port, sets data rate128000 bps
Serial.println("CLEARDATA");
//clears any residual data
Serial.println("LABEL,Time,Pin,Light Level");//set the headings for the data transfer to excel
servoMain.attach(13);
//Set pin 13 as then signal pin for the servo
for (int x=0; x<10; x++) { // set all pins to output
pinMode(ledPin[x], OUTPUT);
}
changeTime = millis();
}
//---------------------------------------------------------------------------------void loop() {
ledDelay = analogRead(potPin);
// read the value from the pot
if ((millis() - changeTime) > ledDelay) { // if its been led Delay ms since last
//change
changeLED();
changeTime = millis();
}
}
//--------------------------------------------------------------------------------void changeLED() {
servoCount=servoCount+1; // counts 18 light changes then the servo moves to the
//next position
if (servoCount>=18) { // test the servo loop if greater than or equal to 18 it starts
servoMain.write(servoMove); // move servo to next position
servoMove=servoMove+1;
// increase the servo position setting for next time
if(servoMove>=20) {
// tests to see if servo has reached 48 degrees rotation
servoMove=0; // at 48 degrees zero the position setting - next time loop executed

//the servo will move to 0 degrees and start again


}
servoCount=servoCount+1;
// increase the servo count for this loop as the loop
// starts at 18 this will push it to 19
if(servoCount>=19){
// test the servo loop to see if it is at 19
servoCount=0;
// if at 19 zero the count ready to start again
}
}
for (int x=0; x<10; x++) {
// turn off all LED's
digitalWrite(ledPin[x], LOW);
}
digitalWrite(ledPin[currentLED], HIGH);
// turn on the current LED
currentLED += direction;
// increment by the direction value
//-------------------------------------------------------------------------------- // change direction if we reach the
end
if (currentLED == 9) {
direction = -1;
}
if (currentLED == 0) {
direction = 1;
}
//-------------------------------------------------------------------------------Serial.print("DATA,TIME,");
Serial.print(currentLED);
Serial.print(",");
Serial.println(ledDelay);
//-------------------------------------------------------------------------------row++;
x++;
delay (delayData);
}

Collecting the data


The system was tested a number of times (see the charts) the tests were performed on the following
Figure 30 Completed setup along with expected spectrum

Figure 31 Sample loaded into a cuvette

Air with no obstruction

Through a cuvette

Through yellow dye

Through red dye

Through green dye

Through green dye, but adjusting the degrees of rotation to one per step

Figure 32 Data charts for the performed tests

The additional chart is an enlargement of the red dye data due to the scale of the data points.
You will note on the charts that there is a definite difference between the different sample types, you
need to look at differences between the samples and the air blank, and then compare things like missing
steps in the charts or the ratios between the steps. Look at the yellow dye chart as well as the enlarged
red chart.
Also if you take a look at figure 33 you will see that its possible to get a lot more data because the
number of steps increases quite a lot. Unfortunately with my current servo I was unable to go lower than
1 degree. I did try but the servo just sat there not moving, so at present until I get a small enough stepper
motor my limit is 1 degree of rotation per step.

Figure 33 Data chart for sample at 1 degree of rotation per servo step

From figure 34 you can see that for the most part they are quite uniform, except near to the end this was
during the readings for the darker blue light from the diffraction grating - you can clearly see a step
change (the last chart shows this the best).
Figure 34 Step change in spectra examples

Figure 35 Charts showing comparison of data plotted against reading number

Summary
This is a good basic spectrometer, however everything can be improved on and for this I think the
addition of adjustable slits to enable better discrimination between wavelengths, as well as some means
of focusing the light from the LED's more accurately onto the grating, possibly using curved mirrors to
direct and concentrate the light to improve selectivity and sensitivity of the readings. But that is for
another project possibly a dual beam model, for now have a play and see what uses you can put your
spectrometer to.
Thanks for reading.

ABOUT THE AUTHOR

Hi I like to have a go at anything that's interesting, from CNC to toy making, recently I have been
dismantling an old Cybot to link to Arduino using Scratch for Arduino as the initial language. I have
three children and a small workshop all keep me fairly busy. My web site is the first non-work related
one Ive created and holds details of the things I have been making as well as some download links for a
number of scroll-saw patterns
Authors web site www.handycrafted.net

Вам также может понравиться