Serial monitor isn't reading data

Hi there, I’m trying to combine multiple environmental sensors for a little gardening project of mine. The combined code compiles so I can upload it to my arduino mega with grove base shield but when I open the serial monitor to look at the data one of the sensors doesn’t read the environment and provide data. Here’s the code I have

Light_Temp_Humidity_pH_Sensor_test.ino (11.6 KB)

Post your code, don’t attach it and force us to download it before we can see it.
And please post it between code tags, </> in the “Reply” window. Don’t post it inline.

A bit more information wouldn’t hurt, too. You say “one of the sensors doesn’t read the environment and provide data”, but you give no clue as to which sensor is the problem.

OldSteve: Post your code,

In this case I don't think it will fit.

The request for more information is wholeheartedly supported. I am too lazy to study 11k of code without some pointers to where the problem lies.

...R

Robin2: In this case I don't think it will fit.

Quite right Robin. My bad. I overlooked the size. :(

Edit: @chandlerollitt, just to get the ball rolling while we wait to hear which sensor is the problem, you don't need multiple 'Serial.begin(9600);' statements in 'setup()'. Just the first one is needed.

You also don't need both of these:-

const int ledPin =  13;      // the number of the LED pin, added by DaveB
#define LED 13

or both of these:-

pinMode(ledPin, OUTPUT);        //Added by DaveB
pinMode(LED, OUTPUT);

Just pick one - 'LED' or 'ledPin', then use it right throughout the code to avoid confusion.

pH sensors are tricky and obviously, must be wired and used correctly. What "environment" is it in? Get it to work properly with a simple program before combining it with anything else.

As jremington says, you need to isolate the problem by getting the pH sensor working properly in a simpler program.

Did you do this prior to putting together your current code?

Edit: I just spotted your problem. You’ve just tacked the pH sensor code onto the end of the ‘read_dht_dat()’ function, after the ‘return’, so the pH sensor never actually gets read.
Note the ‘return result;’ line below. (I marked it.):-

byte read_dht_dat()
{
    //Collect 8 bits from datastream, return them interpreted
    //as a byte. I.e. if 0000.0101 is sent, return decimal 5.

    //Code expects the system to have recently entered the
    //dataline low condition at the start of every data bit's
    //transmission BEFORE this function is called.

    byte i = 0;
    byte result = 0;
    for (i = 0; i < 8; i++)
    {
        //We enter this during the first start bit (low for 50uS) of the byte
        //Next: wait until pin goes high
        while (digitalRead(dht_dpin) == LOW); //Was: while(!(PINC & _BV(dht_PIN)));
        //signalling end of start of bit's transmission.

        //Dataline will now stay high for 27 or 70 uS, depending on
        //whether a 0 or a 1 is being sent, respectively.
        delayMicroseconds(30);//AFTER pin is high, wait further period, to be
        //into the part of the timing diagram where a 0 or a 1 denotes
        //the datum being send. The "further period" was 30uS in the software
        //that this has been created from. I believe that a higher number
        //(45?) would be more appropriate.

        //Next: Wait while pin still high
        if (digitalRead(dht_dpin) == HIGH) //Was: if(PINC & _BV(dht_PIN))
            result |= (1 << (7 - i)); // "add" (not just addition) the 1
        //to the growing byte
        //Next wait until pin goes low again, which signals the START
        //of the NEXT bit's transmission.
        while (digitalRead(dht_dpin) == HIGH); //Was: while((PINC & _BV(dht_PIN)));
    }//end of "for.."
    return result;    // <<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE

    static unsigned long samplingTime = millis();
    static unsigned long printTime = millis();
    static float pHValue, voltage;
    if (millis() - samplingTime > samplingInterval)
    {
        pHArray[pHArrayIndex++] = analogRead(SensorPin);
        if (pHArrayIndex == ArrayLenth)pHArrayIndex = 0;
        voltage = avergearray(pHArray, ArrayLenth) * 5.0 / 1024;
        pHValue = 3.5 * voltage + Offset;
        samplingTime = millis();
    }
    if (millis() - printTime > printInterval)  //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
    {
        Serial.print("Voltage:");
        Serial.print(voltage, 2);
        Serial.print("    pH value: ");
        Serial.println(pHValue, 2);
        digitalWrite(LED, digitalRead(LED) ^ 1);
        printTime = millis();
    }
}

Have you fixed the problem pointed out by OldSteve?

@chandlerollitt, it's not particularly good form to delete a post just after someone responds to it. This is the deleted post that jremington was responding to:-

I had the pH sensor working by its self on a separate sketch before I tried combining it with the other two sensors.

So, after putting in the effort of downloading your code then finding and pointing out the multiple problems, I'd also be interested to know if you sorted out those problems and got it working? You've totally ignored everyone's attempts to help you out, and deleted both posts after the initial one. Why?

1) I'm working with a teacher at my school to try to do what you guys suggested. 2) I haven't deleted a single post. Your guy's input is TREMENDOUSLY appreciated. why would I ignore help that im asking for?

2) I haven't deleted a single post. Your guy's input is TREMENDOUSLY appreciated. why would I ignore help that im asking for?

Odd. Someone deleted a post, and the moderators don't do that without explanation.

My question remains: have you fixed the problem(s) OldSteve pointed out? We are happy to help if that doesn't fix all of them.

chandlerollitt: 2) I haven't deleted a single post.

Then where did your posts disappear to? First the one yesterday saying that the pH sensor was the problem, then the one you posted 1 1/2 hours ago, saying that you had tried the pH sensor in a separate sketch. (The notification for your earlier post is still sitting in my Inbox.):-

chandlerollitt: I had the pH sensor working by its self on a separate sketch before I tried combining it with the other two sensors.