Last stage debugging - Help !![SolveD]

void loop () {
 if (TempRead == true){
float temperatureRead (){
. . . 
}

That won't work. You can't define a function inside a function.

ok .. i do get it ..

in anyhow, how would i remove this damm bug which is preventing my voltage from flipping..

im trying all combination since then, but any of them is not working..

do you think that the voltage flipping which is under case 0, is being missed or anything likewise.. i wanna try to put that on a different case say case 1 . .

thansks for any sugestion . ..

taz..

You've made some code changes, hopefully. Now, you need to post the current code.

taz3m:
soil moisture sensor ... pin 13

I haven't looked at your code at all, but this comment above caught my eye. If you are implementing a resistive moisture sensor then you will probably be trying to set up a voltage divider with some high resistances. In that case, the integral LED that most Arduinos have connected to pin13 might be acting as a pull-down which prevents your circuit from dividing the voltage correctly. You could try using any pin other than 13; if that then works correctly it suggests this was the problem.

hello . .

Been working a bit with the code. .

I haven't looked at your code at all, but this comment above caught my eye. If you are implementing a resistive moisture sensor then you will probably be trying to set up a voltage divider with some high resistances. In that case, the integral LED that most Arduinos have connected to pin13 might be acting as a pull-down which prevents your circuit from dividing the voltage correctly. You could try using any pin other than 13; if that then works correctly it suggests this was the problem.

I agree with you that the pull down resistor willbe adding up in the voltage divider circuit, even though changing the pin from 13 to 8 still results in my voltage not flipping. however, i did observed some more stable values.

I bring some changes here with the code, but still stick to my bug :

// Function to run water pump on conditions of soil moisture

if (FuncActive == true){
  if (pump_Status == false){
pumpControlON ();
  }
}

// Function to run off pump based on conditions
if ( pump_Status == true){
pumpControlOFF();
}

// Function to Activate LightSwitch for plants on conditions of ambient light
if (ReadPhoto == true){
LightAction ();
}
 // Function in taking Temperature Readings and saving to global variable Actualtemp
if (TempRead == true){
Actualtemp = temperatureRead ();
TempRead = false;
}

i think i will be changing the switch case variable, the itemIdx from incrementing directly as a parameter function, rather incrementing it through each case, any suggestion towards that approach.

Thanks

I tried to post this earlier but the site seems to have junked my reply - sorry if you end up with two copies.

Look here:

 if( currentTimer >= (timerLast + timerRate) ){
   timerLast = currentTimer;
 switch(++itemIdx){

Firstly, that's not a very good way to compare the times because it doesn't cope with timer overflow.

You would be better changing the code to this:

if(millis() - timerLast >= timerRate)
{
  timerLast += timerRate;
  // ...

That's not going to stop your sketch from blinking, though. I suspect the reason for that is here:

switch(++itemIdx){

This increments itemIdx but does not wrap back from five to zero. It would be better to do it like this:

const int NUM_ITEMS = 6;
itemIdx = (itemIdx + 1) % NUM_ITEMS;
switch(itemIdx)
{
  ...

Whatever you do though, once you've made any of the suggested changes, please post the entire sketch that's giving you problems - attach it if necessary rather than posting it inline.

hi peter ..
thanks for your kind response, i appreciate it loads..

i did read about the stack memory being overflow after around 50 days, but did not really know how to aproach for its preventive measures .. here you showed to me..

i was suspecting the itemIdx being my culprit the way it was incrementing.. thanks for confirming ..

i shall try out these changes once im back home, n will update all here with the entire code as attachment as requested by wildbill also ..

thanks again..

see ya ..

Hello,

Thanks for the great help peterH . .

Now my voltage pin do flip like a charm, my moisture values are quite stable and im happy that my sensors work as expected.

The modulo function do great in the switching of the case, great idea . . thanks load peterH.

I attached the source code for reference, and if any other changes and improvements can be made, i will be glad to review it and make necessary changes, while getting to learn more and new things at the same time.

Thanks again for all the responses towards this post.

My next step is to implement an LCD , to display all the real values and essential information with a pushbutton to change the mode Display.
Im looking forward to be using another switch Case function again, hope i dont run into much trouble.

However, troubles are here for us to learn more , . . . and Learning never ends . . .

Regards

Tazlim . . .

GreenHouse_Rev_F_02.ino (7.37 KB)

When are you going to fix -

	if ( FanStatus )
	    ;
	{
		FanControlOFF();
	}

And didn't you mean -

    if ( ! FanStatus )
    {
        FanControlON();
    }
    else
    {
        FanControlOFF();
    }

This section (and others like it) could be improved/shortened:

  if (pump_Status == true)
    {
      Serial.print(" Pump Status : ACTIVE ");
      Serial.println();
    }

  else if (pump_Status == false)
    {
      Serial.print(" Pump Staus : INACTIVE ");
      Serial.println();
    }

If you're testing a boolean, you can simply use

if (pump_Status)

Since it's a boolean, if it's not true, no need to test if it's false.

You have some very repetetive code there. Consider adding a function that takes a boolean and a string. Let the function print the string, test the boolean, and println "active" or "inactive" depending on its value. Then use if for all that conditional printing you're doing.

Amongst other things -

Serial.print(" Pump Status : ");    Serial.println((pump_Status ? "ACTIVE " : "INACTIVE "));
Serial.print(" Light Status : ");   Serial.println((LightStatus ? "ACTIVE " : "INACTIVE "));
Serial.print(" Fan Status : ");     Serial.println((FanStatus ? "ACTIVE " : "INACTIVE "));

hello!

Thanks for the suggestions..

Ok i did get it, i will work to shortened and remove some repetitive codes further up, but will have to do some more reading what i see :%

The serial print for now is just to test if code is running properly, however i will be using LCD.print to display all these stuffs which is in serial.print for now.

Serial.print(" Pump Status : ");    Serial.println((pump_Status ? "ACTIVE " : "INACTIVE "));

Serial.print(" Light Status : ");  Serial.println((LightStatus ? "ACTIVE " : "INACTIVE "));
Serial.print(" Fan Status : ");    Serial.println((FanStatus ? "ACTIVE " : "INACTIVE "));

One question here, how will the code know that if pump_Status is 'true' to display ACTIVE or INACTIVE . .

thanks
taz . .

'false' is always zero, not false is alway not 'zero' yet not 'exactly' 'true' while 'true' is only 'true'.

To answer the question read -

http://www.cplusplus.com/articles/1AUq5Di1/

You have some very repetetive code there. Consider adding a function that takes a boolean and a string. Let the function print the string, test the boolean, and println "active" or "inactive" depending on its value. Then use if for all that conditional printing you're doing.

Thats seems interesting, i will try to do this . . any help or source where i can start to grasp a good comprehension about the subject. I think i will be starting with Arduino Reference for string in the meanwhile . .

Thanks . .

'false' is always zero, not false is alway not 'zero' yet not 'exactly' 'true' while 'true' is only 'true'.

Seems confusing, but i shall read it for a proper understanding, i shall keep things posted here, and in time of trouble, i shall ask for a push from time to time . . :wink:

I am actually editing my code for implementation with a 16X2 lcd, and display all my serial print to the latter.

Thanks for your precious time and support . .

See ya ..

taz ...

What I'm suggesting is that the sections like this:

  if (pump_Status == true)
    {
      Serial.print(" Pump Status : ACTIVE ");
      Serial.println();
    }

  else if (pump_Status == false)
    {
      Serial.print(" Pump Staus : INACTIVE ");
      Serial.println();
    }

Could be replaced by a call like this:

DisplayStatus("Pump",pump_Status);

Where the DisplayStatus Function is:

void DisplayStatus (char* Title,boolean Status)
{
Serial.print(Title);
if(Status)
  Serial.println(" ACTIVE);
else
  Serial.println(" INACTIVE");
}

It's simple really. Conditional tests such as used in 'if', 'while', 'do while', and several others, evaluate to zero as false and not zero as not false.

The 'bool' values 'false' and 'true' have specific values - 'false' is always zero while 'true' may be any non-zero value depending upon the language version.

Here is an easy to read article concerning conditionals in C++

http://www.cplusplus.com/forum/articles/3483/

Hello,

Im back again after some workings on the code.

I added up from the previous revision, an lcd 16x2, with some new lines in the code, but here im stuck with some bugs in the code.

My temperature part of the code is not giving me values. I suspected some wiring went wrong, however, when i test the temperature code alone, it works as nice as it should be. . .

With this new revision i added the lcd, and some menu to be displayed like, intro menu, soile percentage menu and LDR Raw reading. . I went through a pushbutton to swap between menus.

Here also without pressing my button, the lcd is changing menu.

Find herewith attached my code. Any suggestions where i can tackle for this bug.

Thanks in advance . .

GreenHouse_Rev_F_03.ino (10.3 KB)

I'm curious why this continues to linger in your code -

if (FanStatus == true);{
FanControlOFF ();
}