กลับไปหน้ารวมไฟล์
smart-garden-iot-system-84fe13.md

ชื่อโปรเจกต์: ระบบสวนอัจฉริยะ Smart Garden IOT (หล่อเท่สไตล์วิศวะ)

โค้ดสำหรับสาย Wi-Fi (จัดไปวัยรุ่น):

#include<[Servo](https://s.shopee.co.th/7fUgFAWSki).h>

#include <dht.h>

dht DHT ;

#define DHT11_PIN 9

int sensor_pin = A0; // Soil [Sensor](https://s.shopee.co.th/7VBG2rX65j) input at Analog PIN A0

int output_value ;

int Temp;

int Humidity;

int relayPin = A5;

Servo motor;

int [pir](https://s.shopee.co.th/7VBG2YelxK);

int pirstate= LOW;

int [ldr](https://s.shopee.co.th/1BHCUqb0Tt);

int trigPin =8;

int echoPin = 7;

//////////////////////////////////////////////

// RemoteXY include library //

//////////////////////////////////////////////

// RemoteXY select connection mode and include library

#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT

#include <RemoteXY.h>

// RemoteXY connection settings

#define REMOTEXY_SERIAL Serial

#define REMOTEXY_SERIAL_SPEED 115200

#define REMOTEXY_WIFI_SSID "Project Smart Garden"

#define REMOTEXY_WIFI_PASSWORD "12345678@"

#define REMOTEXY_SERVER_PORT 6377

// RemoteXY configurate

#pragma pack(push, 1)

uint8_t RemoteXY_CONF[] =

{ 255, 4, 0, 33, 0, 12, 1, 14, 24, 1,

2, 1, 3, 21, 22, 11, 1, 26, 31, 31,

79, 78, 0, 79, 70, 70, 0, 2, 1, 3,

45, 22, 11, 1, 26, 31, 31, 79, 78, 0,

79, 70, 70, 0, 2, 1, 36, 21, 22, 11,

1, 26, 31, 31, 79, 78, 0, 79, 70, 70,

0, 2, 1, 36, 45, 22, 11, 1, 26, 31,

31, 79, 78, 0, 79, 70, 70, 0, 129, 0,

7, 3, 49, 6, 31, 83, 77, 65, 82, 84,

32, 71, 65, 82, 68, 69, 78, 0, 129, 0,

1, 15, 25, 3, 31, 87, 97, 116, 101, 114,

105, 110, 103, 32, 83, 121, 115, 116, 101, 109,

0, 129, 0, 31, 15, 31, 3, 31, 83, 117,

114, 118, 101, 105, 108, 108, 97, 110, 99, 101,

32, 83, 121, 115, 116, 101, 109, 32, 0, 129,

0, 2, 39, 24, 4, 31, 83, 109, 97, 114,

116, 32, 76, 69, 68, 39, 115, 0, 129, 0,

32, 39, 28, 4, 31, 71, 97, 116, 105, 110,

103, 32, 83, 121, 115, 116, 101, 109, 0, 67,

5, 38, 68, 20, 5, 120, 26, 11, 67, 5,

38, 78, 20, 5, 120, 26, 11, 67, 5, 38,

88, 20, 5, 120, 26, 11, 129, 0, 2, 68,

28, 4, 31, 84, 101, 109, 112, 114, 97, 116,

117, 114, 101, 40, 67, 41, 0, 129, 0, 2,

78, 24, 4, 31, 72, 117, 109, 105, 100, 105,

116, 121, 40, 37, 41, 0, 129, 0, 2, 88,

23, 4, 31, 77, 111, 105, 115, 116, 117, 114,

101, 40, 37, 41, 0 };

// this structure defines all the variables and events of your control interface

struct {

// input variables

uint8_t switch_1; // =1 if switch ON and =0 if OFF

uint8_t switch_2; // =1 if switch ON and =0 if OFF

uint8_t switch_3; // =1 if switch ON and =0 if OFF

uint8_t switch_4; // =1 if switch ON and =0 if OFF

// output variables

char text_T[11]; // string UTF8 end zero

char text_H[11]; // string UTF8 end zero

char text_M[11]; // string UTF8 end zero

// other variable

uint8_t connect_flag; // =1 if wire connected, else =0

} RemoteXY;

#pragma pack(pop)

/////////////////////////////////////////////

// END RemoteXY include //

/////////////////////////////////////////////

#define PIN_SWITCH_1 A0

#define PIN_SWITCH_2 A1

#define PIN_SWITCH_3 10

#define PIN_SWITCH_4 6

void setup()

{

RemoteXY_Init ();

pinMode (PIN_SWITCH_1, OUTPUT);

pinMode (PIN_SWITCH_2, OUTPUT);

pinMode (PIN_SWITCH_3, OUTPUT);

pinMode (PIN_SWITCH_4, OUTPUT);

// TODO you setup code

pinMode(A5, OUTPUT);

pinMode(9, INPUT);

pinMode(A4, OUTPUT);

pinMode(10, INPUT);

pinMode(A1, INPUT);

pinMode(5, OUTPUT);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

motor.attach(6);

motor.write(180);

pinMode(sensor_pin, INPUT);

pinMode(relayPin, OUTPUT);

// Serial.begin(9600);

}

void loop()

{

RemoteXY_Handler ();

digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);

digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==0)?LOW:HIGH);

digitalWrite(PIN_SWITCH_3, (RemoteXY.switch_3==0)?LOW:HIGH);

digitalWrite(PIN_SWITCH_4, (RemoteXY.switch_4==0)?LOW:HIGH);

//DHT AND SOIL SENSOR WITH PUMP

int chk = DHT.read11(DHT11_PIN);

Temp= DHT.temperature;

Humidity=DHT.humidity;

output_value= analogRead(sensor_pin);

dtostrf(Temp, 0, 1, RemoteXY.text_T);

dtostrf(Humidity, 0, 1, RemoteXY.text_H);

dtostrf(output_value, 0, 1, RemoteXY.text_M);

delay(2000);

if(output_value<30){

digitalWrite(relayPin, LOW);

}

else

{

digitalWrite(relayPin, HIGH);

}

delay(2500);

pir=digitalRead(10);

ldr=analogRead(A1);

//SURVILLENCE SYSTEM

// Serial.println(pir);

if(pir==1)

{

digitalWrite(A4, HIGH);

if(pirstate==LOW){

pirstate== HIGH;

}

}

else

{

digitalWrite(A4, LOW);

if(pirstate==HIGH){

pirstate== LOW;

}

}

delay(400);

//AUTOMATIC LIGHTS

//Serial.print("LDR");

//Serial.println(ldr);

if(ldr<50)

{

digitalWrite(5, LOW);

}

else

{

digitalWrite(5, HIGH);

}

delay(400);

//AUTOMATIC GATE

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration=pulseIn(echoPin, HIGH);

distance =duration*0.034/2;

//Serial.print(distance);

// Serial.println("CM");

delay(10);

if(distance<=100)

{

motor.write(180);

}

else

{

motor.write(90);

}

delay(400);

}

โค้ดเช็คผ่าน Serial Monitor (ดู Log กันให้ตาแฉะนะน้อง):

#include<Servo.h>

#include <dht.h>

dht DHT ;

#define DHT11_PIN 9

int sensor_pin = A0; // Soil Sensor input at Analog PIN A0

int output_value ;

int Temp;

int Humidity;

int relayPin = A5;

Servo motor;

int pir;

int pirstate= LOW;

int ldr;

int trigPin =8;

int echoPin = 7;

void setup() {

pinMode(A5, OUTPUT);

pinMode(9, INPUT);

pinMode(A4, OUTPUT);

pinMode(10, INPUT);

pinMode(A1, INPUT);

pinMode(5, OUTPUT);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

motor.attach(6);

motor.write(180);

pinMode(sensor_pin, INPUT);

pinMode(relayPin, OUTPUT);

Serial.begin(9600);

}

void loop() {

pir=digitalRead(10);

ldr=analogRead(A1);

//DHT AND SOIL SENSOR WITH PUMP

int chk = DHT.read11(DHT11_PIN);

Temp= DHT.temperature;

Humidity=DHT.humidity;

output_value= analogRead(sensor_pin);

output_value = map(output_value, 550, 10, 0, 100);

Serial.print("Temp: ");

Serial.print(Temp);

//Serial.print((char)223);

Serial.println("C");

Serial.print("Humidity: ");

Serial.print(Humidity);

Serial.println("%");

delay(1500);

Serial.print("Mositure: ");

Serial.print(output_value);

Serial.println("%");

delay(1500);

if(output_value<30){

digitalWrite(relayPin, LOW);

}

else

{

digitalWrite(relayPin, HIGH);

}

delay(2500);

//SURVILLENCE SYSTEM

Serial.print("PIR:");

Serial.println(pir);

if(pir==1)

{

digitalWrite(A4, HIGH);

if(pirstate==LOW){

pirstate== HIGH;

}

}

else

{

digitalWrite(A4, LOW);

if(pirstate==HIGH){

pirstate== LOW;

}

}

delay(400);

//AUTOMATIC LIGHTS

Serial.print("LDR:");

Serial.println(ldr);

if(ldr<50)

{

digitalWrite(5, LOW);

}

else

{

digitalWrite(5, HIGH);

}

delay(400);

//AUTOMATIC GATE

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration=pulseIn(echoPin, HIGH);

distance =duration*0.034/2;

Serial.print("UTSO:");

Serial.print(distance);

Serial.println("CM");

delay(10);

if(distance<=100)

{

motor.write(180);

}

else

{

motor.write(90);

}

delay(400);

}

เจาะลึกรายละเอียดทางเทคนิค (อ่านหน่อยนะน้อง จะได้เทพๆ)

ระบบเกษตรแม่นยำด้วยพลัง Cloud

โปรเจกต์นี้คือศูนย์บัญชาการดูแลสวนแบบครบวงจร โดยใช้พลังของ IoT มาช่วยบริหารจัดการพื้นที่หลายโซนพร้อมกัน

  • การรวมพลังข้อมูล Sensor: เจ้า Arduino ของเราจะทำหน้าที่รวบรวมข้อมูลจากสารพัด Sensor ทั้ง Capacitive Soil Moisture Sensor (วัดความชื้นดินแบบไม่พังง่าย), DHT22 (วัดอุณหภูมิ/ความชื้นในอากาศ) และ LDR (วัดแสง) ข้อมูลพวกนี้จะถูกยิงผ่าน WiFi ขึ้นไปบนแพลตฟอร์ม Cloud แบบหล่อๆ
  • ตรรกะการรดน้ำสุดล้ำ (Predictive Irrigation Logic): เราไม่ได้ใช้แค่ Timer กากๆ ตั้งเวลารดน้ำนะน้อง แต่ระบบเราจะวิเคราะห์ "เทรนด์ความชื้นในดินย้อนหลัง" ถ้าดินมันเริ่มแห้งไวกว่าปกติสัก 20% ระบบจะสั่งเพิ่มเวลารดน้ำในรอบถัดไปให้เองอัตโนมัติ โคตรสมาร์ท!

ประสิทธิภาพและพลังงาน

  • รักษ์โลกด้วยพลังงานแสงอาทิตย์: (สำหรับตัวท็อป) เรามีออปชันเสริมใส่ Solar Panel 6V พร้อมชุดควบคุมชาร์จ Li-Ion Battery ทำให้ระบบสวนอัจฉริยะนี้ทำงานแบบ Off-grid ได้เลย ไม่ต้องลากสายไฟบ้านให้เกะกะ จัดไปวัยรุ่น!

ข้อมูล Frontmatter ดั้งเดิม

title: "Smart Garden IOT System"
description: "Smart Garden IOT System including automated watering system, Smart Surveillance system using PIR sensor, smart Gating system using ultsonic."
author: "vipulbhardwaj785"
category: ""
tags:
  - "iot"
  - "arduino"
  - "agriculture"
views: 3201
likes: 0
price: 699
difficulty: "Intermediate"
components:
  - "1x LDR, 5 Mohm"
  - "1x Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White"
  - "1x Grove - 4-Channel SPDT Relay"
  - "1x SparkFun Soil Moisture Sensor (with Screw Terminals)"
  - "1x PIR Motion Sensor (generic)"
  - "1x DHT11 Temperature & Humidity Sensor (3 pins)"
  - "1x ESP8266 ESP-01"
  - "1x Buzzer, Piezo"
  - "1x Ultrasonic Sensor - HC-SR04 (Generic)"
  - "1x SG90 Micro-servo motor"
  - "1x Arduino UNO"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "d0ecac30016f95adffbdf98c8237fedc40bf54f7c9d7974f9a6f396894979abf"
encryptedPayload: "U2FsdGVkX1+1wq7oq75uAghNi6K7QAU4vfcUN8/tEAAGlYDKe2u4W/L0JxdGL5vJsG8g4f3USR74pgL6P4cV8f1rUpLCIcRr/D8QT2vJxKs="
seoDescription: "Smart Garden IOT System with automated watering, Smart Surveillance using PIR sensor, and smart Gating system using ultsonic."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/smart-garden-iot-system-84fe13_cover.jpg"
lang: "th"