1. [cm-0046] DHT11 Digital Temperature and Humidity Sensor DHT11 แบบ PCB พร้อมสายไฟ
2. [cm-0043] เซ็นเซอร์วัดความชื้นในดิน Soil Moisture Sensor
3. [cm-0019] 2-Channel 5V Relay Module
4. [cm-0002] Arduino UNO R3 แถมสาย USB Type A Male/B Male Cable
5. [cm-b3] บอร์ดทดลอง Breadboard 400
6. [cm-0030] Jump Wire Male to Male x 20
7. [cm-0031] Jump Wire Male to Female x 20
ตัวอย่างการต่อวงจร
*ในการต่อใช้กับ Module Relay ควรใช้ไฟแยกเพื่อมาต่อกับ Ralay ออกมาต่างหาก
Source Code Example
เพิ่ม Library 2 ตัว
1. Adafruit unified sensor library.2. DHT-sensor-library
// 1. Adafruit unified sensor library.
// 2. DHT-sensor-library
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
int sensorPin = A0;
int RELAY1 = 7;
int RELAY2 = 8;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
int sensorValue;
sensorValue = analogRead(sensorPin);
sensorValue = map(sensorValue, 0, 1023, 100, 0);
Serial.print("Soil moisture: ");
Serial.print(sensorValue);
Serial.println(" %");
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
if(sensorValue < 50 && t > 29){
digitalWrite(RELAY1, HIGH);
digitalWrite(RELAY2, HIGH);
}
else{
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, LOW);
}
if(sensorValue < 50){
digitalWrite(RELAY1, HIGH);
}
else{
digitalWrite(RELAY1, LOW);
}
if(t > 30){
digitalWrite(RELAY2, HIGH);
}
else{
digitalWrite(RELAY2, LOW);
}
delay(1000); //wait for half a second, so it is easier to read
}
คลิปวิดีโอสาธิตการใช้งาน
Keyword: Smart Farm, สมาร์ทฟาร์ม, iot smart farm, ชุดรดน้ำต้นไม้, รดน้ำต้นไม้
http://www.iot.codemobiles.com/product/280/%E0%B8%8A%E0%B8%B8%E0%B8%94-smart-farm-%E0%B8%A3%E0%B8%94%E0%B8%99%E0%B9%89%E0%B8%B3%E0%B8%95%E0%B9%89%E0%B8%99%E0%B9%84%E0%B8%A1%E0%B9%89
1 COMMENTS
Comments are closed.
Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from Gravatar.