-
Notifications
You must be signed in to change notification settings - Fork 1
/
TemperatureSensor.ino
144 lines (110 loc) · 3.76 KB
/
TemperatureSensor.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
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
//LCD pins
int lcdV = 8;
int lcdG = 9;
//Temperature Limit
int tempV = 13;
int tempG = 12;
float tempLimit;
int tempControllerPin = A2;
int readTempController;
//Motor Timings
int delayV = 11;
int delayG = 10;
float delayTime;
int delayTimePin = A3;
int readDelayTime;
// Relay Code
const int relay_Pin = 3;
void setup(void)
{
pinMode(relay_Pin, OUTPUT);
//TempController pin mode
pinMode(tempV,OUTPUT);//define a digital pin as output
digitalWrite(tempV, HIGH);// set the above pin as HIGH so it acts as 5V
pinMode(tempG,OUTPUT);//define a digital pin as output
digitalWrite(tempG, LOW);// set the above pin as LOW so it acts as Ground
//DelayTiming
pinMode(delayV,OUTPUT);//define a digital pin as output
digitalWrite(delayV, HIGH);// set the above pin as HIGH so it acts as 5V
pinMode(delayG,OUTPUT);//define a digital pin as output
digitalWrite(delayG, LOW);// set the above pin as LOW so it acts as Ground
//LCDPower
pinMode(lcdV,OUTPUT);//define a digital pin as output
digitalWrite(lcdV, HIGH);// set the above pin as HIGH so it acts as 5V
pinMode(lcdG,OUTPUT);//define a digital pin as output
digitalWrite(lcdG, LOW);// set the above pin as LOW so it acts as Ground
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
//LCD
lcd.init(); // initialize the lcd
lcd.backlight(); // open the backlight
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
Serial.print("Temperature is: ");
float temp = sensors.getTempCByIndex(0);
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
Serial.print("Temp is ");
Serial.println(temp);
// //Read Temperature for Setting Limit
readTempController = analogRead(tempControllerPin);
Serial.print("PR value is ");
Serial.println(readTempController);
tempLimit = (10./1023.)*readTempController + 35;
Serial.print("tempLimit ");
Serial.println(tempLimit);
// Read Time for Setting Motor Time
readDelayTime = analogRead(delayTimePin);
Serial.print("PRT value is ");
Serial.println(readDelayTime);
delayTime = ((300000.-60000.)/1023.)*readDelayTime + 60000;
float displayTime = delayTime/1000;
Serial.print("delayTime : ");
Serial.println(delayTime );
//LCD Display Code
lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print("CT:");
lcd.print(temp); // print the temperature in Celsius
lcd.print((char)223); // print ° character
lcd.print("C ");
lcd.setCursor(0, 1);// start to print at the second row
lcd.print("L:");
lcd.print(tempLimit); // print the temperature in Fahrenheit
lcd.print((char)223);
lcd.print("C ");// print ° character
lcd.print("M");
lcd.print("T:");
lcd.print((int)displayTime);
lcd.print("s");// print the temperature in Fahrenheit
if(temp > tempLimit)
{
Serial.println("Temperature above 38");
digitalWrite(relay_Pin, HIGH); // turn on pump 5 minutes
delay(delayTime);
digitalWrite(relay_Pin, LOW); // turn off pump 5 minuutes
delay(5000);
}
delay(100);
}