Back to Parent

int sensorPin = A0;
int thresholdUp = 3000;
int thresholdDown = 350;

int LedPin1 = D0;
int LedPin2 = D2;
int LedPin3 = D4;



void setup(){
  Serial.begin(9600);
  pinMode(sensorPin,INPUT);
  pinMode(LedPin1, OUTPUT);
  pinMode(LedPin2, OUTPUT);
  pinMode(LedPin3, OUTPUT);


  Particle.subscribe ("SoilStatus",sensorPin);


}


void loop(){
  int sensorValue = analogRead(sensorPin);
  Serial.println("\nSensor Value: ");
  Serial.print(sensorValue);
  if (sensorValue <= thresholdDown){
    digitalWrite(LedPin1, HIGH);
    digitalWrite(LedPin2, LOW);
    digitalWrite(LedPin3, LOW);
    Particle.publish("SoilStatus","Dry! Water me!",60,PUBLIC);


  } else if (sensorValue > thresholdDown && sensorValue < thresholdUp){

     digitalWrite(LedPin1, HIGH);
     digitalWrite(LedPin2, HIGH);
     digitalWrite(LedPin3, LOW);


  } else if (sensorValue >  thresholdUp){

     digitalWrite(LedPin1, HIGH);
     digitalWrite(LedPin2, HIGH);
     digitalWrite(LedPin3, HIGH);

    
  }
    delay(5000);
}
Click to Expand

Content Rating

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

0