Go Down

Topic: Soil moisture meter. (Read 123 times) previous topic - next topic

SuperSanta

So im quit new to arduino and i only have worked with basic projects earlier. So im going off on vacation and im having a friend look after my plants and i thought it would be nice having a moisture detector. i've got everything hooked up but the code isn't quite working so id wonder if someone could help me fix the code.
i want the LED to constantly light up when i certain value is reached but also change LED depending on the different values that the moisture detector output.

I would sincerely appreciate if someone could help me with this project.

Code: [Select]
const int VAL_PROBE = 0; // Analog pin 0
const int MOISTURE_LEVEL = 0; // the value after the LED goes ON

void setup() {
    Serial.begin(9600);
}
void Dry(int state) {
    digitalWrite(11, state);
}
void Humid(int state) {
    digitalWrite(13, state);
}
void Water(int state) {
    digitalWrite(12, state);
}
void Air(int state) {
    digitalWrite(11, state);
    digitalWrite(12, state);
    digitalWrite(13, state);
}


void loop() {
    int moisture = analogRead(VAL_PROBE);
 
    Serial.println(moisture);
 
    if(moisture > 800) {
        Dry(HIGH);
    } else   {
        Dry(LOW);
    }

    delay(1000);
}

void loop2() {
int moisture = analogRead(VAL_PROBE);
 
    Serial.println(moisture);
 
    if(moisture > 300) {
        Humid(HIGH);
    } else   {
        Humid(LOW);
    }

    delay(1000);
}

void loop3() {
int moisture = analogRead(VAL_PROBE);
 
    Serial.println(moisture);
 
    if(moisture > 50) {
        Water(HIGH);
    } else   {
        Water(LOW);
    }

    delay(1000);
}
void loop4() {
int moisture = analogRead(VAL_PROBE);
 
    Serial.println(moisture);
 
    if(moisture > 1000) {
        Air(HIGH);
    } else   {
        Air(LOW);
    }

    delay(1000);
}

mistergreen

loop2(), loop3(), loop4() makes no sense. only loop() is automatically call.

take all of the loops code and put inside loop().

SuperSanta

Thanks it worked like a charm now  :)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy