Back to Parent

Code
int soilPin = A0;
int waterPinOut = D1;
int WaterPinIn = A1;
int motorPin = D0;
int thresholdUp = 400;
int thresholdDown = 250;
int wateringcount = 0;
char *message;

void setup(){
  pinMode(motorPin, OUTPUT);
  pinMode(waterPinOut, OUTPUT);
  Particle.variable("mess", "I'm on", STRING);
  delay(100);
}

void loop(){
  soil();
}

void soil(){
  int sensorValue;
  waterwarning();
  sensorValue = analogRead(soilPin);
  Particle.variable("soil", &sensorValue, INT);
  if(sensorValue>=thresholdUp){
    analogWrite(motorPin, 0);
    message = "Watered";
    Particle.variable("mess", message, STRING);
    delay(60000);
  }
  if(sensorValue<=thresholdDown){
    analogWrite(motorPin, 50);
    message = "Dry, Watering.";
    Particle.variable("mess", message, STRING);
    delay(5000);
    wateringcount = wateringcount + 1;
    Particle.variable("Count", &wateringcount, INT);
    delay(100);
    analogWrite(motorPin, 0);
  }
}

void waterwarning(){
  int waterlevel;
  digitalWrite(waterPinOut, HIGH);
  waterlevel = analogRead(WaterPinIn);
  if(waterlevel<5){
    Particle.variable("mess", "WARNING! REFILL WATER");
    delay(100);
  } else {}
  digitalWrite(waterPinOut, LOW);
  Particle.variable("water", &waterlevel, INT);
  delay(100);
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0