Smart Garden IOT System
Smart Garden IOT System including automated watering system, Smart Surveillance system using PIR sensor, smart Gating system using ultsonic.
Components and supplies
1
LDR, 5 Mohm
1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
1
Grove - 4-Channel SPDT Relay
1
SparkFun Soil Moisture Sensor (with Screw Terminals)
1
PIR Motion Sensor (generic)
1
DHT11 Temperature & Humidity Sensor (3 pins)
1
ESP8266 ESP-01
1
Buzzer, Piezo
1
Ultrasonic Sensor - HC-SR04 (Generic)
1
SG90 Micro-servo motor
1
Arduino UNO
Apps and platforms
1
Arduino IDE
Project description
Code
Wi-fi code
c_cpp
1#include<Servo.h> 2#include <dht.h> 3 4 5 dht DHT ; 6 7#define DHT11_PIN 9 8 9int sensor_pin = A0; // Soil Sensor input at Analog PIN A0 10int output_value ; 11int Temp; 12int Humidity; 13int relayPin = A5; 14 15 16 17 18 19Servo motor; 20int pir; 21int pirstate= LOW; 22int ldr; 23int trigPin =8; 24int echoPin = 7; 25 26 27////////////////////////////////////////////// 28// RemoteXY include library // 29////////////////////////////////////////////// 30 31// RemoteXY select connection mode and include library 32#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT 33 34#include <RemoteXY.h> 35 36// RemoteXY connection settings 37#define REMOTEXY_SERIAL Serial 38#define REMOTEXY_SERIAL_SPEED 115200 39#define REMOTEXY_WIFI_SSID "Project Smart Garden" 40#define REMOTEXY_WIFI_PASSWORD "12345678@" 41#define REMOTEXY_SERVER_PORT 6377 42 43 44// RemoteXY configurate 45#pragma pack(push, 1) 46uint8_t RemoteXY_CONF[] = 47 { 255,4,0,33,0,12,1,14,24,1, 48 2,1,3,21,22,11,1,26,31,31, 49 79,78,0,79,70,70,0,2,1,3, 50 45,22,11,1,26,31,31,79,78,0, 51 79,70,70,0,2,1,36,21,22,11, 52 1,26,31,31,79,78,0,79,70,70, 53 0,2,1,36,45,22,11,1,26,31, 54 31,79,78,0,79,70,70,0,129,0, 55 7,3,49,6,31,83,77,65,82,84, 56 32,71,65,82,68,69,78,0,129,0, 57 1,15,25,3,31,87,97,116,101,114, 58 105,110,103,32,83,121,115,116,101,109, 59 0,129,0,31,15,31,3,31,83,117, 60 114,118,101,105,108,108,97,110,99,101, 61 32,83,121,115,116,101,109,32,0,129, 62 0,2,39,24,4,31,83,109,97,114, 63 116,32,76,69,68,39,115,0,129,0, 64 32,39,28,4,31,71,97,116,105,110, 65 103,32,83,121,115,116,101,109,0,67, 66 5,38,68,20,5,120,26,11,67,5, 67 38,78,20,5,120,26,11,67,5,38, 68 88,20,5,120,26,11,129,0,2,68, 69 28,4,31,84,101,109,112,114,97,116, 70 117,114,101,40,67,41,0,129,0,2, 71 78,24,4,31,72,117,109,105,100,105, 72 116,121,40,37,41,0,129,0,2,88, 73 23,4,31,77,111,105,115,116,117,114, 74 101,40,37,41,0 }; 75 76// this structure defines all the variables and events of your control interface 77struct { 78 79 // input variables 80 uint8_t switch_1; // =1 if switch ON and =0 if OFF 81 uint8_t switch_2; // =1 if switch ON and =0 if OFF 82 uint8_t switch_3; // =1 if switch ON and =0 if OFF 83 uint8_t switch_4; // =1 if switch ON and =0 if OFF 84 85 // output variables 86 char text_T[11]; // string UTF8 end zero 87 char text_H[11]; // string UTF8 end zero 88 char text_M[11]; // string UTF8 end zero 89 90 // other variable 91 uint8_t connect_flag; // =1 if wire connected, else =0 92 93} RemoteXY; 94#pragma pack(pop) 95 96///////////////////////////////////////////// 97// END RemoteXY include // 98///////////////////////////////////////////// 99 100#define PIN_SWITCH_1 A0 101#define PIN_SWITCH_2 A1 102#define PIN_SWITCH_3 10 103#define PIN_SWITCH_4 6 104 105 106void setup() 107{ 108 RemoteXY_Init (); 109 110 pinMode (PIN_SWITCH_1, OUTPUT); 111 pinMode (PIN_SWITCH_2, OUTPUT); 112 pinMode (PIN_SWITCH_3, OUTPUT); 113 pinMode (PIN_SWITCH_4, OUTPUT); 114 115 // TODO you setup code 116 117 pinMode(A5,OUTPUT); 118 pinMode(9,INPUT); 119 pinMode(A4,OUTPUT); 120 pinMode(10,INPUT); 121 pinMode(A1,INPUT); 122 pinMode(5,OUTPUT); 123 pinMode(trigPin, OUTPUT); 124 pinMode(echoPin, INPUT); 125 motor.attach(6); 126 motor.write(180); 127 pinMode(sensor_pin, INPUT); 128 pinMode(relayPin, OUTPUT); 129 // Serial.begin(9600); 130 131 132} 133 134void loop() 135{ 136 RemoteXY_Handler (); 137 138 digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH); 139 digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==0)?LOW:HIGH); 140 digitalWrite(PIN_SWITCH_3, (RemoteXY.switch_3==0)?LOW:HIGH); 141 digitalWrite(PIN_SWITCH_4, (RemoteXY.switch_4==0)?LOW:HIGH); 142 143 144 145 146 //DHT AND SOIL SENSOR WITH PUMP 147 int chk = DHT.read11(DHT11_PIN); 148 Temp= DHT.temperature; 149 Humidity=DHT.humidity; 150 output_value= analogRead(sensor_pin); 151 152 dtostrf(Temp, 0, 1, RemoteXY.text_T); 153 dtostrf(Humidity, 0, 1, RemoteXY.text_H); 154 dtostrf(output_value, 0, 1, RemoteXY.text_M); 155 delay(2000); 156 157 if(output_value<30){ 158 digitalWrite(relayPin, LOW); 159 160 } 161 else 162 { 163 digitalWrite(relayPin, HIGH); 164 165 } 166 167 delay(2500); 168 169 170 171 pir=digitalRead(10); 172 ldr=analogRead(A1); 173 174 175 //SURVILLENCE SYSTEM 176 // Serial.println(pir); 177 178 if(pir==1) 179 { 180 digitalWrite(A4,HIGH); 181 182 if(pirstate==LOW){ 183 pirstate== HIGH; 184 } 185 186 } 187 else 188 { 189 digitalWrite(A4,LOW); 190 191 if(pirstate==HIGH){ 192 pirstate== LOW; 193 } 194 195 196 } 197 delay(400); 198 199 200 //AUTOMATIC LIGHTS 201 //Serial.print("LDR"); 202 //Serial.println(ldr); 203 204 if(ldr<50) 205 { 206 digitalWrite(5,LOW); 207 208 } 209else 210 { 211 digitalWrite(5,HIGH); 212 } 213 delay(400); 214 215 216 217 //AUTOMATIC GATE 218 long duration, distance; 219 digitalWrite(trigPin,LOW); 220 delayMicroseconds(2); 221 digitalWrite(trigPin, HIGH); 222 delayMicroseconds(10); 223 digitalWrite(trigPin,LOW); 224 duration=pulseIn(echoPin, HIGH); 225 distance =duration*0.034/2; 226 //Serial.print(distance); 227 // Serial.println("CM"); 228 delay(10); 229 230 if(distance<=100) 231 { 232 motor.write(180); 233 } 234 235 else 236 { 237 motor.write(90); 238 } 239 delay(400); 240 241 242 243 244 245 246 247 248}
Wi-fi code
c_cpp
1#include<Servo.h> 2#include <dht.h> 3 4 5 dht DHT ; 6 7#define DHT11_PIN 9 8 9int sensor_pin = A0; // Soil Sensor input at Analog PIN A0 10int output_value ; 11int Temp; 12int Humidity; 13int relayPin = A5; 14 15 16 17 18 19Servo motor; 20int pir; 21int pirstate= LOW; 22int ldr; 23int trigPin =8; 24int echoPin = 7; 25 26 27////////////////////////////////////////////// 28// RemoteXY include library // 29////////////////////////////////////////////// 30 31// RemoteXY select connection mode and include library 32#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT 33 34#include <RemoteXY.h> 35 36// RemoteXY connection settings 37#define REMOTEXY_SERIAL Serial 38#define REMOTEXY_SERIAL_SPEED 115200 39#define REMOTEXY_WIFI_SSID "Project Smart Garden" 40#define REMOTEXY_WIFI_PASSWORD "12345678@" 41#define REMOTEXY_SERVER_PORT 6377 42 43 44// RemoteXY configurate 45#pragma pack(push, 1) 46uint8_t RemoteXY_CONF[] = 47 { 255,4,0,33,0,12,1,14,24,1, 48 2,1,3,21,22,11,1,26,31,31, 49 79,78,0,79,70,70,0,2,1,3, 50 45,22,11,1,26,31,31,79,78,0, 51 79,70,70,0,2,1,36,21,22,11, 52 1,26,31,31,79,78,0,79,70,70, 53 0,2,1,36,45,22,11,1,26,31, 54 31,79,78,0,79,70,70,0,129,0, 55 7,3,49,6,31,83,77,65,82,84, 56 32,71,65,82,68,69,78,0,129,0, 57 1,15,25,3,31,87,97,116,101,114, 58 105,110,103,32,83,121,115,116,101,109, 59 0,129,0,31,15,31,3,31,83,117, 60 114,118,101,105,108,108,97,110,99,101, 61 32,83,121,115,116,101,109,32,0,129, 62 0,2,39,24,4,31,83,109,97,114, 63 116,32,76,69,68,39,115,0,129,0, 64 32,39,28,4,31,71,97,116,105,110, 65 103,32,83,121,115,116,101,109,0,67, 66 5,38,68,20,5,120,26,11,67,5, 67 38,78,20,5,120,26,11,67,5,38, 68 88,20,5,120,26,11,129,0,2,68, 69 28,4,31,84,101,109,112,114,97,116, 70 117,114,101,40,67,41,0,129,0,2, 71 78,24,4,31,72,117,109,105,100,105, 72 116,121,40,37,41,0,129,0,2,88, 73 23,4,31,77,111,105,115,116,117,114, 74 101,40,37,41,0 }; 75 76// this structure defines all the variables and events of your control interface 77struct { 78 79 // input variables 80 uint8_t switch_1; // =1 if switch ON and =0 if OFF 81 uint8_t switch_2; // =1 if switch ON and =0 if OFF 82 uint8_t switch_3; // =1 if switch ON and =0 if OFF 83 uint8_t switch_4; // =1 if switch ON and =0 if OFF 84 85 // output variables 86 char text_T[11]; // string UTF8 end zero 87 char text_H[11]; // string UTF8 end zero 88 char text_M[11]; // string UTF8 end zero 89 90 // other variable 91 uint8_t connect_flag; // =1 if wire connected, else =0 92 93} RemoteXY; 94#pragma pack(pop) 95 96///////////////////////////////////////////// 97// END RemoteXY include // 98///////////////////////////////////////////// 99 100#define PIN_SWITCH_1 A0 101#define PIN_SWITCH_2 A1 102#define PIN_SWITCH_3 10 103#define PIN_SWITCH_4 6 104 105 106void setup() 107{ 108 RemoteXY_Init (); 109 110 pinMode (PIN_SWITCH_1, OUTPUT); 111 pinMode (PIN_SWITCH_2, OUTPUT); 112 pinMode (PIN_SWITCH_3, OUTPUT); 113 pinMode (PIN_SWITCH_4, OUTPUT); 114 115 // TODO you setup code 116 117 pinMode(A5,OUTPUT); 118 pinMode(9,INPUT); 119 pinMode(A4,OUTPUT); 120 pinMode(10,INPUT); 121 pinMode(A1,INPUT); 122 pinMode(5,OUTPUT); 123 pinMode(trigPin, OUTPUT); 124 pinMode(echoPin, INPUT); 125 motor.attach(6); 126 motor.write(180); 127 pinMode(sensor_pin, INPUT); 128 pinMode(relayPin, OUTPUT); 129 // Serial.begin(9600); 130 131 132} 133 134void loop() 135{ 136 RemoteXY_Handler (); 137 138 digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH); 139 digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==0)?LOW:HIGH); 140 digitalWrite(PIN_SWITCH_3, (RemoteXY.switch_3==0)?LOW:HIGH); 141 digitalWrite(PIN_SWITCH_4, (RemoteXY.switch_4==0)?LOW:HIGH); 142 143 144 145 146 //DHT AND SOIL SENSOR WITH PUMP 147 int chk = DHT.read11(DHT11_PIN); 148 Temp= DHT.temperature; 149 Humidity=DHT.humidity; 150 output_value= analogRead(sensor_pin); 151 152 dtostrf(Temp, 0, 1, RemoteXY.text_T); 153 dtostrf(Humidity, 0, 1, RemoteXY.text_H); 154 dtostrf(output_value, 0, 1, RemoteXY.text_M); 155 delay(2000); 156 157 if(output_value<30){ 158 digitalWrite(relayPin, LOW); 159 160 } 161 else 162 { 163 digitalWrite(relayPin, HIGH); 164 165 } 166 167 delay(2500); 168 169 170 171 pir=digitalRead(10); 172 ldr=analogRead(A1); 173 174 175 //SURVILLENCE SYSTEM 176 // Serial.println(pir); 177 178 if(pir==1) 179 { 180 digitalWrite(A4,HIGH); 181 182 if(pirstate==LOW){ 183 pirstate== HIGH; 184 } 185 186 } 187 else 188 { 189 digitalWrite(A4,LOW); 190 191 if(pirstate==HIGH){ 192 pirstate== LOW; 193 } 194 195 196 } 197 delay(400); 198 199 200 //AUTOMATIC LIGHTS 201 //Serial.print("LDR"); 202 //Serial.println(ldr); 203 204 if(ldr<50) 205 { 206 digitalWrite(5,LOW); 207 208 } 209else 210 { 211 digitalWrite(5,HIGH); 212 } 213 delay(400); 214 215 216 217 //AUTOMATIC GATE 218 long duration, distance; 219 digitalWrite(trigPin,LOW); 220 delayMicroseconds(2); 221 digitalWrite(trigPin, HIGH); 222 delayMicroseconds(10); 223 digitalWrite(trigPin,LOW); 224 duration=pulseIn(echoPin, HIGH); 225 distance =duration*0.034/2; 226 //Serial.print(distance); 227 // Serial.println("CM"); 228 delay(10); 229 230 if(distance<=100) 231 { 232 motor.write(180); 233 } 234 235 else 236 { 237 motor.write(90); 238 } 239 delay(400); 240 241 242 243 244 245 246 247 248}
Downloadable files
Circuit diagram
Circuit diagram

Comments
Only logged in users can leave comments