-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ino
62 lines (49 loc) · 1.29 KB
/
main.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
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into digital pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
double Temp;
int RELAY_PIN = 5;
int HA = 7;
int HB = 8;
void setup(void)
{
sensors.begin(); // Start up the library
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT);
pinMode(HA, OUTPUT);
pinMode(HB, OUTPUT);
}
void loop(void)
{
// Send the command to get temperatures
sensors.requestTemperatures();
Temp = sensors.getTempCByIndex(0);
//print the temperature in Celsius
Serial.print("Temperature: ");
Serial.print(Temp);
Serial.print("º");//shows degrees character
Serial.print("C | ");
Serial.print("\n");
digitalWrite(HA, HIGH);
if (Temp > 0) {
if (Temp > 25 and Temp <= 28) {
digitalWrite(RELAY_PIN, HIGH);
digitalWrite(HB, LOW);
Serial.print("Peltier \n");
} else if (Temp > 28) {
digitalWrite(RELAY_PIN, LOW);
digitalWrite(HB, HIGH);
Serial.print("Relay \n");
} else {
digitalWrite(RELAY_PIN, HIGH);
digitalWrite(HB, HIGH);
Serial.print("Nada \n");
}
}
delay(3000);
}