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!

asked May 23, 2016 at 21:24
1
  • /r/learnprogramming? Are we Reddit now? Commented 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.

answered May 23, 2016 at 22:49
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. Commented May 25, 2016 at 2:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.