Achraf Oukheir
Published

Irrigation Sample

A sample tool to irrigate a plant by monitoring soil.

BeginnerShowcase (no instructions)4 hours1,054
Irrigation Sample

Things used in this project

Story

Read more

Schematics

SoilSensor

SoilSensor with a lamp as relay

Code

Untitled file

Arduino
//OUKHEIR Achraf
const int Soil = A1;//variable A0 rceive info fro sensor
int SoilValue= 0 ;//variable tha will store
const int PompePin =  10;      // the number of the LED pin
int Sisoil= 0 ; //l etat de soil est normal
int S1=800;
int S2=500;
void setup() {
Serial.begin(9600);
    // initialize Pmpe pin as an output:
  pinMode(PompePin, OUTPUT);
  // initialize soil as an input:
  pinMode(Soil, INPUT);
}

void loop() {
Serial.print("soil value = ");
Serial.println(ReadSoil());

Sisoil= WetDry();
if(Sisoil==1){
   Pompe(1);
}else {
  Pompe(0);
}

delay(1000);
}

//fonction de soil read
int ReadSoil(){
SoilValue =analogRead(Soil);
delay(100);
  return  SoilValue;
}

//fonction de check soil 
int WetDry(){
 //check if the soil is wet or dry
  if ( SoilValue  > S1) {
    // turn vibreur on:
    digitalWrite(PompePin, HIGH);
    return 1; 
  } else  if ( SoilValue  < S2){
    // turn vibreur off:
    digitalWrite(PompePin, LOW);
  
  return 0;
  }
  
}

//fonction de pompe
int Pompe(int act){
  if(act==1){
    digitalWrite(PompePin, HIGH);
  return 1;
  }else{
  digitalWrite(PompePin, LOW);
  return 0;
  }
  }

Credits

Achraf Oukheir

Achraf Oukheir

8 projects • 14 followers

Comments