loading
2 Comments

Tell us about yourself!

Complete Your Profile
  • DaveS101 commented on innovativetom's instructable Arduino Soil Moisture Sensor11 months ago
    Arduino Soil Moisture Sensor

    hey steve instead of using delay would it not be better to use a blink without delay method as not to tie up the processor if it is in the middle of a delay you lose all other functions till the delay is over, way better to time it with millis(); function then you can respond to interrupts like button pushes or sensor inputs it is always best to not use delaysetup long previousMillis = 0; long interval = 900000; // 15 minutesmain loop {unsignedlong currentMillis = millis();if(currentMillis - previousMillis > interval) {previousMillis = currentMillis;}else{get value from sensor once every 15 minutes }}

    //working program you can use more millis(); timers for the sensor delays i //just //did not have time to work it up yet i can post it later but the odds of //hitting the delay during a button push are 1 in 500 with 2ms delay i consider //this acceptable i have not noticed any trouble from it //By Dave Soderbloom//Quick sketch for water sensor reading without delay to tie up processor for other tasks like interrupts //pins I used on msp432 int led1 = 2; int led2 = 3; int led3 = 4; int led4 = 5; int led5 = 6; int probe = 8; int moistureSensor = A7; int sensorValue = 0; long previousMillis = 0; long interval = 10000; // 15 minutes900000 void setup(){ Serial.begin(9600); // setting the led pins to outputs pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(l...see more »//working program you can use more millis(); timers for the sensor delays i //just //did not have time to work it up yet i can post it later but the odds of //hitting the delay during a button push are 1 in 500 with 2ms delay i consider //this acceptable i have not noticed any trouble from it //By Dave Soderbloom//Quick sketch for water sensor reading without delay to tie up processor for other tasks like interrupts //pins I used on msp432 int led1 = 2; int led2 = 3; int led3 = 4; int led4 = 5; int led5 = 6; int probe = 8; int moistureSensor = A7; int sensorValue = 0; long previousMillis = 0; long interval = 10000; // 15 minutes900000 void setup(){ Serial.begin(9600); // setting the led pins to outputs pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT); pinMode(probe, OUTPUT); //get and display startup reading before main loop to the serial monitor digitalWrite(probe, HIGH); delay(1000); int sensorValue = analogRead(moistureSensor); Serial.println(sensorValue); digitalWrite(probe, LOW); }void loop(){ unsigned long currentMillis = millis(); int sensorValue = analogRead(moistureSensor); if(currentMillis - previousMillis > interval) { previousMillis = currentMillis; digitalWrite(probe, HIGH); delay(2); //super small delay may need to be higher depending on your arduino or launchpad board you are using some take 200 miliseconds to get accurate analog reading int sensorValue = analogRead(moistureSensor); // print out the value you read: Serial.println(sensorValue);//may have to adjust ranges depending on a few factors if (sensorValue >= 820) { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, HIGH); digitalWrite(led5, HIGH); } else if (sensorValue >= 615 && sensorValue < 820) { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, HIGH); digitalWrite(led5, LOW); } else if (sensorValue >= 410 && sensorValue < 615) { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, LOW); digitalWrite(led5, LOW); } else if (sensorValue >= 250 && sensorValue < 410) { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(led5, LOW); } else if (sensorValue >= 0 && sensorValue < 250) { digitalWrite(led1, HIGH); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(led5, LOW); } // Power-down the probe digitalWrite(probe, LOW); }}

    View Instructable »