-
Notifications
You must be signed in to change notification settings - Fork 0
/
Smart_Agriculture_System.ino
112 lines (95 loc) · 2.64 KB
/
Smart_Agriculture_System.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
#include "arduino_secrets.h"
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/83d65f35-a8cd-48df-bc2c-85e88f2a67a4
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudTemperatureSensor tEMPERATURE;
int lIGHT;
int sOIL_MOISTURE;
CloudRelativeHumidity hUMIDITY;
bool wATER_PUMP;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include "DHT.h"
#define MotorPin 12
#define LightSensor 34
#define SoilSensor 35
#define DHTPIN 13
#define DHTTYPE DHT11
DHT dht(DHTPIN,DHTTYPE);
void setup() {
Serial.begin(9600);
pinMode(MotorPin, OUTPUT);
pinMode(LightSensor,INPUT);
pinMode(SoilSensor,INPUT);
pinMode(DHTPIN,INPUT);
dht.begin();
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void TEMP_HUMI_READ() {
float t = dht.readTemperature();
tEMPERATURE = t;
float h = dht.readHumidity();
hUMIDITY = h;
Serial.print("Temperature: "); Serial.println(t);
Serial.print("Humidity: "); Serial.println(h);
delay(250);
}
void MOTOR_RUN(){
digitalWrite(MotorPin, HIGH);
delay(5000);
digitalWrite(MotorPin, LOW);
}
void SOIL_READ(){
int soilValue = analogRead(SoilSensor);
soilValue = map(soilValue, 0, 4095, 100, 0);
sOIL_MOISTURE = soilValue;
Serial.print("Soil Value : ");
Serial.println(soilValue);
if(soilValue <=30){
MOTOR_RUN();
}
delay(250);
}
void LIGHT_READ(){
int lightValue = analogRead(LightSensor);
lightValue = map(lightValue, 0, 4095, 100, 0);
lIGHT = lightValue;
Serial.print("Light Value : ");
Serial.println(lightValue);
delay(250);
}
void WATER_PUMP(){
if(wATER_PUMP == HIGH){
digitalWrite(MotorPin, HIGH);
}
else{
digitalWrite(MotorPin, LOW);
}
}
void loop() {
ArduinoCloud.update();
// Your code here
TEMP_HUMI_READ();
SOIL_READ();
LIGHT_READ();
WATER_PUMP();
}