0

I am making a Soil Analysis system with an Arduino Uno, but I have run into a problem and was wondering if /r/learnprogramming could help!

The moisture sensor section of my code will not output the data to the Serial Monitor in Arduino 1.7.1 IDE. I am not sure why it's not working. Running the moisture sensor code by itself works, and I just copied and pasted that code into my combined code file since I'll I am running 4 sensors at once with my Arduino Uno.

These are the four values I need to output data on one baud rate:

  • pH value
  • EC
  • DHT temperature reading
  • Moisture Sensor Value
    I am currently missing Moisture Sensor Value when I run Combined1.ino

Here is the Combined1.ino code of the code from four sensors together that's uploaded to the Arduino: Combined Code Link
Moisture Sensor Link

Any help would be much appreciated!

1
  • /r/learnprogramming? Are we Reddit now?
    – Majenko
    May 23, 2016 at 22:44

1 Answer 1

1

Your second print section will always fail.

You have:

if(millis() - printTime > printInterval)   //Every 800 milliseconds, print a numerical, convert the state of the LED indicator

However, a bit before then you have:

if(millis()-printTime>=printInterval)
{
  printTime=millis();

So millis() - printTime can never be greater than printInterval since you have just set printTime to millis(). So millis() - printTime will always be somewhere between 0 and printInterval - 1.

Consider combining your different printing routines into one single printing routine so you are comparing (and changing) the printTime only once.

1
  • I got it to work. There is something happening with the DHT22 section that when the DHT22 is not connected, it fails and ends the loop. I just moved my moisture sensor code above that and it is now working. I will see if I can clean it up using this advice.
    – Phil Engel
    May 25, 2016 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.