-
Notifications
You must be signed in to change notification settings - Fork 0
/
Embryo, Temperature, CNC, and LED RGB Control .txt
84 lines (64 loc) · 4.86 KB
/
Embryo, Temperature, CNC, and LED RGB Control .txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//This code is basic for Temperature control for the incubator, plus, CNC movement control for the two cameras, also the RGB LED control under the incubator beaker
/* 0- General */
int decimalPrecision = 2; // decimal places for all values shown in LED Display & Serial Monitor
/* 1- Temperature Measurement */
int ThermistorPin = A1; // The analog input pin for measuring temperature
float voltageDividerR1 = 10000; // Resistor value in R1 for voltage devider method
float BValue = 3470; // The B Value of the thermistor for the temperature measuring range
float R1 = 100000; // Thermistor resistor rating at based temperature (25 degree celcius)
float T1 = 298.15; /* Base temperature T1 in Kelvin (default should be at 25 degree)*/
float R2 ; /* Resistance of Thermistor (in ohm) at Measuring Temperature*/
float T2 ; /* Measurement temperature T2 in Kelvin */
float a ; /* Use for calculation in Temperature*/
float b ; /* Use for calculation in Temperature*/
float c ; /* Use for calculation in Temperature*/
float d ; /* Use for calculation in Temperature*/
float e = 2.718281828 ; /* the value of e use for calculation in Temperature*/
float tempSampleRead = 0; /* to read the value of a sample including currentOffset1 value*/
float tempLastSample = 0; /* to count time for each sample. Technically 1 milli second 1 sample is taken */
float tempSampleSum = 0; /* accumulation of sample readings */
float tempSampleCount = 0; /* to count number of sample. */
float tempMean ; /* to calculate the average value from all samples, in analog values*/
void setup() {
Serial.begin(9600);
pinMode(A4,OUTPUT); //green
pinMode(A2,OUTPUT); //blue
pinMode(A3,OUTPUT); //red
pinMode(A5,INPUT);
}
void loop(){
analogWrite(A4,600);
delay(3000);
analogWrite(A4,0);
// delay(500);
analogWrite(A2,600);
delay(3000);
analogWrite(A2,0);
// delay(500);
analogWrite(A3,600);
delay(3000);
analogWrite(A3,0);
// delay(3000);
/* 1- Temperature Measurement */
if(millis() >= tempLastSample + 1) /* every 1 milli second taking 1 reading */
{
tempSampleRead = analogRead(ThermistorPin); /* read analog value from sensor */
tempSampleSum = tempSampleSum+tempSampleRead; /* add all analog value for averaging later*/
tempSampleCount = tempSampleCount+1; /* keep counting the sample quantity*/
tempLastSample = millis(); /* reset the time in order to repeat the loop again*/
}
if(tempSampleCount == 1000) /* after 1000 sample readings taken*/
{
tempMean = tempSampleSum / tempSampleCount; /* find the average analog value from those data*/
R2 = (voltageDividerR1*tempMean)/(1023-tempMean); /* convert the average analog value to resistance value*/
a = 1/T1; /* use for calculation */
b = log10(R1/R2); /* use for calculation */
c = b / log10(e); /* use for calculation */
d = c / BValue ; /* use for calculation */
T2 = 1 / (a- d); /* the measured temperature value based on calculation (in Kelvin) */
Serial.print(T2 - 273.15,decimalPrecision); /* display in Serial monitor the temperature in Celcius*/
Serial.println(" °C");
tempSampleSum = 0; /* reset all the total analog value back to 0 for the next count */
tempSampleCount = 0; /* reset the total number of samples taken back to 0 for the next count*/
}
}