-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.C
98 lines (85 loc) · 2.56 KB
/
main.C
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
/* Solar panel pump controller
* Starts a pump using a Relay when the temperature sensor
* of the panel measures a temperature higher than the bottom water tank
* temperature sensor
* 4x Temperature Sensors DS18B20
* 1x Relays (control pump)
* 1x LCD display 16 characters x 2 rows (display temperatures and statuses)
* 1x LED (when pump ON)
* Francois Gallard
*/
/*-----( Import needed libraries )-----*/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
/*-----( Declare Constants )-----*/
#define WIRE_BUS_TEMP 7 /*-(Connect to Pin 7 )-*/
#define RELAY_PIN1 8
#define N_TEMP_SENSORS 2
#define ON_PUMP_TRESHOLD 5. /* test tresholds */
#define OFF_PUMP_TRESHOLD 2./* test tresholds */
/*-----( Declare objects )-----*/
/* Set up a oneWire instance to communicate with any OneWire device*/
OneWire wireTemp(WIRE_BUS_TEMP);
/* Tell Dallas Temperature Library to use oneWire Library */
DallasTemperature tempSensors(&wireTemp);
/*Initialize lcd screen */
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
/*-----( Declare Variables )-----*/
/* temperatures array*/
float temperatures[4] = { 0., 0., 0., 0. };
String info = "";
bool pumpOn = false;
void setup() /*----( SETUP: RUNS ONCE )----*/
{
Serial.begin(9600);
/*-( Start up the DallasTemperature library )-*/
tempSensors.begin();
/* Sets the pin for the relay */
pinMode(RELAY_PIN1, OUTPUT);
/* set up the LCD's number of columns and rows:*/
lcd.begin(16, 2);
}/*--(end setup )---*/
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
/* Send the command to get temperatures*/
tempSensors.requestTemperatures();
for(int i=0;i<N_TEMP_SENSORS;i++){
temperatures[i]=tempSensors.getTempCByIndex(i);
}
/* Build the concatrnated string containing temp infos*/
info="";
for(int i=0;i<N_TEMP_SENSORS;i++){
info=info+"T"+i+"="+temperatures[i]+" ";
}
Serial.println(info);
//Col 0 line 0
lcd.setCursor(0, 0);
/* Displays info on LCD */
lcd.print(info);
/*Test if we should activate or deactivate the pump*/
if(!pumpOn && temperatures[1]>temperatures[0]+ON_PUMP_TRESHOLD){
pumpOn=true;
}
if(pumpOn && temperatures[1]<temperatures[0]+OFF_PUMP_TRESHOLD){
pumpOn=false;
}
/*Write info on pump status*/
if(pumpOn){
Serial.println("PUMP is ON");
/*Activate relay*/
digitalWrite(RELAY_PIN1,0);
//Col 0 line 1
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("PUMP is ON ");
}else{
//Col 0 line 1
lcd.setCursor(0, 1);
/*Deactivate relay*/
lcd.print("PUMP is OFF ");
Serial.println("PUMP is OFF ");
digitalWrite(RELAY_PIN1,1);
}
}/* --(end main loop )-- */
/* ( THE END ) */