-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDIY_Bioreactor.ino
93 lines (81 loc) · 1.75 KB
/
DIY_Bioreactor.ino
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
85
86
87
88
89
90
91
92
93
#include <Time.h>
#include <TimeLib.h>
#define DELAY 60000 // 60s
#define PH_MIN_VALUE 3.6
#define PH_CALIBRATION 2.2
#define PH_OFFSET -1
//L298N driver //Motor A
const int motorPin1 = 9;
const int motorPin2 = 10;
// Motor B
const int motorPin3 = 6;
const int motorPin4 = 5;
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
pinMode(12, INPUT_PULLUP); //float switch, which measures the liquid level
Serial.begin(9600);
}
void loop(){
time();
turbidity();
PHsensor();
Serial.print(",liquid level:");
prLevel();
stirrer();
pumpingControl(measurePH2(), liquidLevel());
}
// setting time
void time(){
Serial.print(hour());
Serial.print(":");
Serial.print(minute());
Serial.print(":");
Serial.print(second());
Serial.print(":");
}
// liquid level
int liquidLevel(){
return digitalRead(12);
}
// printing liquid level
void prLevel(){
Serial.print(liquidLevel());
delay(DELAY);
}
// pumping
void pumpingControl(float PH, int liquidLevel){
if (PH<=PH_MIN_VALUE && liquidLevel != 1){
analogWrite(motorPin3, 255);
analogWrite(motorPin4, 0);
}
else{
analogWrite(motorPin3, 0);
analogWrite(motorPin4, 0);
}
}
// stirrer
void stirrer(){
analogWrite(motorPin1, 100);
analogWrite(motorPin2, 0);
}
// turbidity
void turbidity(){
Serial.println(analogRead(A5)*(5.0/1023.0));
delay(DELAY);
}
// pH sensor
float measurePH2(){
int pH_sensorValue = analogRead(A2);
float pH_voltage = pH_sensorValue * 5.0 / 1023.0;
float pH_value = PH_CALIBRATION * (28.2 + PH_OFFSET - 6.5 * pH_voltage);
return pH_value;
}
void PHsensor(){
Serial.print(",");
Serial.print("pH: ");
Serial.print(measurePH2());
delay(DELAY);
}