So I have this project I am working on for a thin film solar cell research lab at my university…
Using this equation: t = (ln(It/Io))/-a) {where It is the light transmitted, Io is the initial light (light incident on the material) and a is a known constant} you can come up with a pretty decent measurement of the thickness of the thin film layer deposited on the substrate (glass).
So here’s the layout of what I want to do…
I believe I have the design and concept worked out pretty well. I just suck at programming…trying to learn tho!
Grove digital light sensor in a black box. Led faces sensor. Slot to drop sample slide in question in between LED and sensor. All scattering of light will be minimized in design of the black box…those details are not important here. Adafruit LCD display on the front to display measurement values.
So this is how I want the program to run:
Turn unit on
LCD display(“Calibrate? Press a button…”)
Press a button on LCD to begin
get calibrationValue /calibration value will be light transmitted without slide in box (Io) LED turns on milliseconds before sensor. Senor “turns on” starts collecting light data for 5 seconds. Average of data collected (data point each second/5) is stored in calibrationValue/
LCD display(“Ready for Transmission. Press any button…”) /Program stops and waits for user input so user can load slide in box/
Press Button
get testValue /* (It)/*
display(calibrationValue)
display(testValue)
thickness= (log(It/Io)/log(2.71828))/-100000) /ln(x) is not a usable function with arduino but log(x) is. ln(x)=log(x)/log(2.71828). 100000 is the a we will be using./
display(thickness)
display (“Run another test?”)
If yes
repeat program
else do nothing
So I haven’t yet bought the LCD screen. I will cross that bridge of code when it comes. For now I have been trying to use the serial monitor, but to no avail.
Here is the code I have come up with so far:
#include <Wire.h>
#include <Digital_Light_TSL2561.h>
#include <math.h>
int ledPin = 13;
int inputRead = 0;
int calcThickness(int trans, int initial)//It = I transmitted; I0 = I initial
{
int result;
result = (log(trans/initial)/log(2.71828))/-100000;
}
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("Begin calibration? y/n");
pinMode(ledPin, OUTPUT);
}
void loop()
{
while (Serial.available())
{
inputRead = Serial.read();
if (inputRead == 'y')
{
while (millis () <10200<0)
{
digitalWrite (ledPin, HIGH);
delay(5);
while (millis () <10000<0)
{
TSL2561.init();
digitalWrite (ledPin, HIGH);
unsigned long Lux;
TSL2561.getLux();
}
}
int initI = ((TSL2561.calculateLux(0,0,1))/10);
Serial.print("Calibration light value is: ");
Serial.println(initI);
Serial.print("Test sample? y/n");
while (Serial.available())
{
inputRead = Serial.read();
if (inputRead == 'y')
{
while (millis () <10200){
digitalWrite(ledPin, HIGH);
delay(5);
while (millis () <10000) {
TSL2561.init();
digitalWrite (ledPin, HIGH);
unsigned long Lux;
TSL2561.getLux();
}
}
digitalWrite (ledPin, LOW);
int testI = ((TSL2561.calculateLux(0,0,1))/10);
Serial.print("Transmission light value: ");
Serial.println(testI);
int thickness;
thickness = calcThickness(testI, initI);
Serial.print("Sample Thickness: ");
Serial.println(thickness);
}
}
}
else {
digitalWrite(ledPin, LOW);
Serial.print('Waiting for input');
}
}
}
I tried setting up the calculation as a function as one tutorial out there showed me. But other tutorials have shown me other ways of doing math within the program that might be easier. I might revert to doing it a different way.
Also, I tried just purely making this raw calculation with the arduino and it seems the variable I am using are not correct. In one attempt I used int for “thickness” or the result of the equation and got a serial print of inf (infinity). Changed it to a float and it gave me a really long negative number.
Also, I believe there is an issue with all my if and while functions and using serial commmands.
ANY help would be GREATLY appreciated! Been messing with this for a few weeks now with not much success.
Thanks,
Tim