-
Notifications
You must be signed in to change notification settings - Fork 0
/
bioreactor.ino
122 lines (103 loc) · 3.45 KB
/
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
FONCTIONNEL
Picobrewery Project
Code by Dearcham 07/01/2013
Other code with lib
http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20
SSr http://www.homeroasters.org/php/forum/viewthread.php?thread_id=2268&rowstart=0
Simple code to test temperature probe, interpret it with the apporpriate librairies (see under) and send the value to Serial
Circuit :
SensorShield on Arduino 2560 bought on Yourduino
T°probe DS18b20 bought on Yourduino (Wiring : 1Vcc 5V 1Grnd 1Signal on digital 2)
A pull up resistor 4,7Komh between signal (yellow) and Vcc(+) (red)
Can be juiced up by arduino with sensor shield
------->PLUG ON A DIGITAL ENTRY<-------
DEPENDANCES
:Library “DallasTemperatureControl” (change the lib directory for this name) AND
Library “OneWire”
http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_372Beta.zip
http://www.pjrc.com/teensy/arduino_libraries/OneWire.zip
*/
/* YourDuino Electronic Brick Test
Temperature Sensor DS18B20
- Connect cable to Arduino Digital I/O Pin 2
/*-----( Import needed libraries )-----*/
#include <OneWire.h>
#include <DallasTemperature.h>
/*-----( Declare Constants )-----*/
#define ONE_WIRE_BUS 6 /*-(Connect to Pin 2 )-*/
/*-----( Declare objects )-----*/
/* Set up a oneWire instance to communicate with any OneWire device*/
OneWire ourWire(ONE_WIRE_BUS);
/* Tell Dallas Temperature Library to use oneWire Library */
DallasTemperature sensors(&ourWire);
/*-----( Declare Variables )-----*/
String ph_sensor_string = "";
String oh_sensor_string = "";
String t_sensor_string = "";
boolean ph_sensor_string_complete = false;
boolean oh_sensor_string_complete = false;
void setup(void) /*----( SETUP: RUNS ONCE )----*/
{
/*-(start serial port to see results )-*/
delay(1000);
Serial.begin(38400);
Serial2.begin(38400); // OH Sensor
Serial3.begin(38400); // PH Sensor
delay(1000);
/*-( Start up the DallasTemperature library )-*/
sensors.begin();
}/*--(end setup )---*/
// OH sensor
void serialEvent2() {
if (!oh_sensor_string_complete) {
while(Serial2.available()) {
char in_char = (char)Serial2.read();
if (in_char == '\r') {
break;
}
oh_sensor_string += in_char;
}
if (oh_sensor_string.length() != 5) { // Avoid trash data sent sometimes by the sensor
oh_sensor_string = "";
return;
}
oh_sensor_string = "OH : " + oh_sensor_string;
oh_sensor_string_complete = true;
}
}
//PH sensor
void serialEvent3() {
if (!ph_sensor_string_complete) {
while(Serial3.available()) {
char in_char = (char)Serial3.read();
ph_sensor_string += in_char;
if (in_char == '\r') {
break;
}
}
if (ph_sensor_string.length() != 5) { // Avoid trash data sent sometimes by the sensor
ph_sensor_string = "";
return;
}
ph_sensor_string = "PH : " + ph_sensor_string;
ph_sensor_string_complete = true;
}
}
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
sensors.requestTemperatures(); // Send the command to get temperatures
t_sensor_string = "T : " + (String)sensors.getTempCByIndex(0);
Serial.println(t_sensor_string);
if (ph_sensor_string_complete && oh_sensor_string_complete ) {
Serial.println(ph_sensor_string);
Serial.println(oh_sensor_string);
ph_sensor_string = "";
oh_sensor_string = "";
ph_sensor_string_complete = false;
oh_sensor_string_complete = false;
}
Serial.println();
}/* --(end main loop )-- */
/* ( THE END ) */