Any one pls tell me how to build a automatic irrigation system using pic microcontroller. & It's programming
Any one pls tell me how to build a automatic irrigation system using pic microcontroller. & It's programming
My latest attempt at a solution:
I just wasted about 1 hour documenting my work in this blog when everything was suddenly lost, so i have no intention of wasting more time in this way. This is going to be a "quick and dirty" posting. If this attempt also fails then i will give up.
Parts used:
Schematic Drawing:
Solid State Relay Datasheet:
HUZZAH code:
#include <ESP8266WiFi.h>
const char* ssid = "<your ssid here>";
const char* password = "<your password here>";
const int LED = 0;
const int PUMP = 4;
// Max value is approx. 825 - bone dry
// Min value is approx. 406 - drowning in water
const int THRESHOLD = 700;
int moisture = 0;
int tmp = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(100);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// supstitute the ipaddresses below with your desired static ip, router ip, and dhcp ip
WiFi.config(IPAddress(192, 168, 1, 50), IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1));
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
Serial.println();
Serial.println("Soil moisture sensor");
pinMode(PUMP, OUTPUT);
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
digitalWrite(PUMP, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
tmp = analogRead(A0);
if (tmp != moisture) {
moisture = tmp;
Serial.print("moisture = ");
Serial.println(moisture);
if (analogRead(A0) > THRESHOLD) {
digitalWrite(LED, LOW);
digitalWrite(PUMP, LOW);
Serial.println("Threshold reached - water the plant!");
} else {
digitalWrite(LED, HIGH);
digitalWrite(PUMP, HIGH);
}
}
delay(1000);
}
Comments:
Everything appears to be stable with this solution so far. In the future i plan on implementing the following changes:
- sensor to detect when the water supply is empty
- send email when detected that water supply is empty, and do not attempt to pump water if the water supply is empty
Forgot to mention a couple of other changes i plan to make to the code:
- Introduce another (lower) threshold and use it for turning off the water pump
- introduce a longer time delay (1 day) to wait before checking soil moisture immediately after turning off the pump.
These changes will have to wait as i have other activities pending which require my immediate attention.
-raymond
Forgot to mention a couple of other changes i plan to make to the code:
- Introduce another (lower) threshold and use it for turning off the water pump
- introduce a longer time delay (1 day) to wait before checking soil moisture immediately after turning off the pump.
These changes will have to wait as i have other activities pending which require my immediate attention.
-raymond