-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode in C language
111 lines (95 loc) · 2.25 KB
/
Code in C language
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
#include <LiquidCrystal.h> //LCD Library
#define NOTE_C4 262
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_G4 392
#define NOTE_A4 440
#define NOTE_B4 494
#define NOTE_C5 523
int temp;
int T_Sensor = A3;
int M_Sensor = A0;
int W_led = 7;
int P_led = 13;
int Speaker = 9;
int val;
int cel;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
lcd.clear();
pinMode(13,OUTPUT);
pinMode(7,INPUT);
pinMode(9,OUTPUT);
val = analogRead(T_Sensor); //Read Temperature sensor value
int mv = ( val/1024.0)*5000;
cel = mv/10;
lcd.setCursor(0,0);
lcd.print("PROJECT BY");
lcd.setCursor(0,1);
lcd.print("Eng Moussine ");
delay(1000);
}
void loop()
{
lcd.clear();
int Moisture = analogRead(M_Sensor); //Read Moisture Sensor Value
lcd.setCursor(0,0);
lcd.print("TEMP:");
lcd.setCursor(5,0);
lcd.print(cel);
lcd.setCursor(7,0);
lcd.print("*C");
if (Moisture> 700) // for dry soil
{
lcd.setCursor(11,0);
lcd.print("DRY");
lcd.setCursor(11,1);
lcd.print("SOIL");
if (digitalRead(W_led)==1) //test the availability of water in storage
{
digitalWrite(13, HIGH);
lcd.setCursor(0,1);
lcd.print("PUMP:ON");
}
else
{
digitalWrite(13, LOW);
lcd.setCursor(0,1);
lcd.print("PUMP:OFF");
tone(Speaker, NOTE_C4, 500);
delay(500);
tone(Speaker, NOTE_D4, 500);
delay(500);
tone(Speaker, NOTE_E4, 500);
delay(500);
tone(Speaker, NOTE_F4, 500);
delay(500);
tone(Speaker, NOTE_G4, 500);
delay(500);
}
}
if (Moisture>= 300 && Moisture<=700) //for Moist Soil
{
lcd.setCursor(11,0);
lcd.print("MOIST");
lcd.setCursor(11,1);
lcd.print("SOIL");
digitalWrite(13,LOW);
lcd.setCursor(0,1);
lcd.print("PUMP:OFF");
}
if (Moisture < 300) // For wet soil
{
lcd.setCursor(11,0);
lcd.print("WET");
lcd.setCursor(11,1);
lcd.print("SOIL");
digitalWrite(13,LOW);
lcd.setCursor(0,1);
lcd.print("PUMP:OFF");
}
delay(1000);
}