smit01
March 19, 2018, 8:00pm
1
Hey i am making this irrigation system, that detects the moisture in the soil then sends the water if their is low amount of soil. I need help to put the values in the program of this capacitive soil moisture sensor.
Values i want to put in is dry to wet: 520-350
Dry: (520 430]
Wet: (430 350]
Water: (350 260]
This is the sketch so far:
int digitalSensor = A0;
int pumpPin = 8; //relay pin
void setup() {
pinMode(digitalSensor, INPUT);
pinMode(pumpPin, OUTPUT);
}
void loop() {
if(digitalRead(digitalSensor) == HIGH){//turn water pump on
digitalWrite(pumpPin, HIGH);
delay(30000);
digitalWrite(pumpPin, LOW);
}
delay(21600000);
}
Other thread removed. Carry on.
Read the example code on that web-page you link to..:
use if (analogRead(A0)>nn) // open waterflow. delay short time . read again.
If no need for water now ... long delay
#define dry 400 // suitable limit for water pump
#define sensor A0
int pumpPin = 8; //relay pin
void setup()
{
pinMode(pumpPin, OUTPUT);
}
void loop()
{
while(analogRead(sensor) < dry) //turn water pump on ? may be > ??
{
digitalWrite(pumpPin, HIGH); // open waterflow
delay(500);
}
digitalWrite(pumpPin, LOW); // stop waterflow
delay(21600000); // loooong delay. can be shorter
}
smit01
March 19, 2018, 9:04pm
4
Thanks!
How does this one looks? Will this work?
int pump=2;
void setup(){
pinMode(pump,OUTPUT);
int sensorValue = analogRead(A0);
}
void loop(){
int sensorValue = analogRead(A0);{
Serial.println(sensorValue);
if(sensorValue>350) digitalWrite(pump, HIGH);
delay(30000);
digitalWrite(pump, LOW);
}
delay(36000);
}
void loop()
{
int sensorValue = analogRead(A0);
{
Serial.println(sensorValue);
if(sensorValue>350)
digitalWrite(pump, HIGH);
delay(30000);
digitalWrite(pump, LOW);
}
delay(36000);
}
It looks like that.
smit01
March 19, 2018, 9:41pm
6
GrooveFlotilla:
void loop()
{
int sensorValue = analogRead(A0);
{
Serial.println(sensorValue);
if(sensorValue>350)
digitalWrite(pump, HIGH);
delay(30000);
digitalWrite(pump, LOW);
}
delay(36000);
}
It looks like that.
sorry what do you mean by "It looks like that."
I mean "it looks like this correctly posted in code tags, and it looks like this when correctly indented, and as such, it looks a bit weird because of the place you put the {} braces"
system
March 20, 2018, 10:33am
8
then sends the water if their is low amount of soil.
If the soil is missing, add water. I must have missed something.
differences:
You pump water for 30sec, then wait 10hrs to check again.
My code pumps water until wet enough. Then wait a while...
Both will probably be OK
My code pumps water until wet enough. Then wait a while...
Why wait a fixed time ?
if (soil_too_dry)
run pump
else
stop pump
end if