Back to Parent

int rainPin = A0;
int greenLED = D4;
int redLED = D3;
// you can adjust the threshold value
int thresholdValue = 2000;
int sensorValue = 0;

void setup(){
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Particle.variable("moisture", sensorValue);

void loop() {
  // read the input on analog pin 0:
  sensorValue = analogRead(rainPin);
  if(sensorValue < thresholdValue){
     Particle.publish("water-level-changed", "I need water"); 
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, HIGH);
  else {
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
Click to Expand

Content Rating

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