-
Notifications
You must be signed in to change notification settings - Fork 0
/
Temperature_Sensors-1.ino
174 lines (153 loc) · 3.49 KB
/
Temperature_Sensors-1.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal.h>
/* this is a controller for Evacuated solar heater*/
//Author: Vuyani Daweti
// This Code is creates to read Three temperature sensors and tranfer them to the Serial monitor
//This code runs along with Python code Named: Arduino_to_Python.
#include <Metro.h>
//VARIABLE ASSINGMENT--------------
int ledPinGreen1 = A4;
int ledPinRed1 = A3;
int PumpSwitch = A5;
int brightness;
const int chipSelect = 4;
Sd2Card card;
//int switch1 = 7;
int i = 0;
int j = 0;
int k = 0;
int m = 0;
int oldcelT = 0 ;
float analogOutputHeaterPin;
File myFile;
unsigned long time;
Metro serialMetro = Metro(1000);
LiquidCrystal lcd(A11, A10, A9, A8, A7, A6);
void setup()
{
pinMode(ledPinGreen1, OUTPUT);
pinMode(ledPinRed1, OUTPUT);
pinMode(PumpSwitch, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
// pinMode(switch1, INPUT);
}
void loop()
{
SD_CARD();
m=0;
int analogOutputHeaterPin = analogRead(A0); //READ TEMPERATURE OF THE HEADER PIPE INPUT
float voltageOH = analogOutputHeaterPin *(3300/ 1024.0);
float celOH = voltageOH/10;
int analogInputHeaterPin = analogRead(A1); //READ TEMPERATURE OF THE HEADER PIPE OUTPUT
float voltageIH = analogInputHeaterPin * (3300/ 1024.0);
float celIH = voltageIH/10;
int analogTankPin = analogRead(A2); //READ TEMPERATURE OF THE TANK
float voltageT= analogTankPin * (3300/ 1024.0);
float celT = voltageT/10;
//float work = celT;
// boolean SwitchMode = analogRead(A3);
// Serial.print("TEMPRATURE = ");
// Serial.print(celT);
// Serial.print("*C");
// Serial.println();
if (celT < 30.0 ) { //IF THE TEPMARATURE IS LESS THAN 30 DEGREES TURN THE PUMP ON.
digitalWrite(ledPinGreen1,HIGH);
digitalWrite(ledPinRed1,LOW);
digitalWrite(PumpSwitch,HIGH);
LDC_SCREEN(celT);
PUMP(celT);
}
if (celT >= 30.0) { //IF THE TEMPERATURE IS MORE THAN 30 DEGREES TURN OFF THE PUMP
digitalWrite(ledPinRed1,HIGH);
digitalWrite(ledPinGreen1,LOW);
digitalWrite(PumpSwitch,LOW);
LDC_SCREEN(celT);
}
// }
// if ( i < 210) {
// EEPROM.write(i , celT);
// i = i + 1;
// }
if (serialMetro.check() == 1 && j != 30){
// EEPROM.write(i, celT);
Serial.print(celT);
Serial.print(";");
Serial.print(celIH);
Serial.print(";");
j = j + 1;
if (j == 10){
Serial.print(celOH);
}
//if (SwitchMode != 1){
// Serial.print(celOH);
//}
else {
Serial.println(celOH);
}
}
if (j == 30){
Serial.println(0);
j = 0;
//if (SwitchMode == 1 ){
// Serial.println(00);
}
}
int LDC_SCREEN(float value)
{
if (k==0)
{
lcd.setCursor(0,0);
lcd.clear();
lcd.println("TANK_TEMPERATURE");
lcd.setCursor(0, 1);
lcd.print(value);
k=1;
oldcelT = value;
}
if (k!= 0)
{
if (oldcelT != value)
{
lcd.setCursor(0,1);
lcd.print(value);
}
}
}
int PUMP(int number)
{
brightness = -51*number +1530;
if (number <25)
{
analogWrite(PumpSwitch,255);
}
if (number >= 30)
{
analogWrite(PumpSwitch,0);
}
else
{
analogWrite(PumpSwitch,brightness);
}
}
int SD_CARD (void)
{
while (!card.init(SPI_HALF_SPEED, chipSelect)) {
if (m==0)
{
lcd.setCursor(0,0);
lcd.clear();
lcd.print("INSERT CARD!");
lcd.setCursor(0,1);
lcd.clear();
m =1;
k = 0;
}
else
{
lcd.setCursor(0,0);
lcd.print("INSERT CARD!");
}
}
}