Go Down

Topic: Slow response - how to improve . . ? (Read 3093 times) previous topic - next topic

robtillaart

try to get the application right for 1 sensor first. Then increase it to multiple sensors and then use array's.

Also read the book Kerningham & RItchie C language 2nd edition. "Worth its weight in brains"
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

taz3m

hello,

I found that by using
Code: [Select]
#define moisture_input [] = {1,3,4,5}

whereby i was defining analog pin 1,pin 3, pin 4, pin 5  to be used to collect information from soil moisture probes.

Instead when i use

Code: [Select]

int moisture_input [] = {1,3,4,5};


It do compiles . .
tz
.....

AWOL

Quote
whereby i was defining analog pin 1,pin 3, pin 4, pin 5
No, you weren't. You were defining a strange macro.
Do the substitution, and you'll see why the compiler complained.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

taz3m


try to get the application right for 1 sensor first. Then increase it to multiple sensors and then use array's.


I already try the application for 1 sensor, it did work . . thats why i would like to extend to 4 now.

Anyway thanks for the reference book .

taz ..
tz
.....

taz3m


Do the substitution, and you'll see why the compiler complained.


Which thing do i need to substitute . . ??
tz
.....

AWOL

A #define is a macro.
When the C preprocessor sees the macro name it substitutes the macro value as a simple 1:1 text replacement.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

taz3m

just to see if i did understand the working of the array.

im i doing it right ?

Code: [Select]


/* Declaration of I/Os */

  int moisture_input [] = {1,3,4,5};        // Analog Input pin 1 connected to collect Soil Moisture reading.
  #define dcSource_top 13                      // Power source 5V top connected to digitsl pin 13
  #define dcSource_bottom 12                   // Power Source 5V bottom connected to digital pin 12



/*--------------------------------------------------------------------*/

   
   int Moisture[4];                 // Analogical value obtained from the experiment S.probes (1,2,3,4)
   

void setup (){


Serial.begin (9600);

}


int SoilMoisture(){
 
   
  // Variable to hold value from Moisture input.
  int reading[4];

 
  // Set driver pins to outputs
  pinMode(dcSource_top,OUTPUT);
  pinMode(dcSource_bottom,OUTPUT);

  // Drive a current through the divider in one direction
  digitalWrite(dcSource_top,LOW);
  digitalWrite(dcSource_bottom,HIGH);

  // Wait a moment for capacitance effects to settle
  delay(1000);

  // Take readings
 
  for (int i=0; i<4; i++)
  {
  reading[i] = analogRead(moisture_input[i]);
   //return reading[i]; 
    }


  // Reverse the current
  digitalWrite(dcSource_top,HIGH);
  digitalWrite(dcSource_bottom,LOW);

  // Give as much time in 'reverse' as in 'forward'
  delay(1000);

  // stop the current
  digitalWrite(dcSource_top,LOW);

}

void loop (){

for (int j=0; j<4; j++){
  Moisture[j] = SoilMoisture(); 
}
 
Serial.print ("value = ");

Serial.print (Moisture[0]);

}

tz
.....

Nick Gammon

Quote

Code: [Select]

#define moisture_input [] = {1,3,4,5}



You can't use defines like that. Change that line to:

Code: [Select]
const int moisture_input [] = {1,3,4,5};       // Analog Input pin 1 connected to collect Soil Moisture reading.


Quote
im i doing it right ?


Better.

Quote
Seems you did not like the phrase about clarification . . sorry about that .


As long as it made you smile. :)
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

PaulS

So, SoilMoisture() is defined as returning a value. There is no return statement, so there will be garbage on the stack that is popped off and stored in the array, each time the function ends. If that's what you want, carry on.

taz3m

Quote


Code: [Select]
const int moisture_input [] = {1,3,4,5};       // Analog Input pin 1 connected to collect Soil Moisture reading.


Here const means that the value assigned to the array wont change, like here the pin number, correct ?


Quote

Better.


Motivating.

Quote

As long as it made you smile. :)


I shall make the effort to always :)  ;)

Quote

So, SoilMoisture() is defined as returning a value. There is no return statement, so there will be garbage on the stack that is popped off and stored in the array, each time the function ends. If that's what you want, carry on.


oops i think i forget to remove the // coment line here :
Code: [Select]

for (int i=0; i<4; i++)
  {
  reading[i] = analogRead(moisture_input[i]);
   return reading[i]; >>  remove // coment 
    }


if that is correct i shall be moving towards the reading of the switch.
I did not yet upload, may be this afternooon after work.

Thanks

Taz ...
tz
.....

AWOL

#25
Jan 24, 2013, 09:35 am Last Edit: Jan 24, 2013, 10:05 am by AWOL Reason: 1
Code: [Select]
for (int i=0; i<4; i++)
 {
 reading[i] = analogRead(moisture_input[i]);
  return reading[i]; >>  remove // coment  
   }

You really don't want to remove the comment - think what will happen.

Edit: Or, more to the point, think what will not happen.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

GoForSmoke

Lux and lumens are units of brightness to human eyes which are most sensitive in yellow.

But plants reflect green and yellow, they absorb red and blue. What is best for plants does not appear so bright to human eyes or to your lux meter. You waste power on less useful wavelengths trying to increase lux, unless you're lighting for picture taking or best look. In general you want 4 red to 1 blue but you can change that some to better simulate different latitudes and time of year.

There are grow sites that you can verify this and maybe get numbers from. Red and blue leds with colored bulbs actually make good sensors for red and blue light, you need 2 pins and 1 resistor each.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

AWOL

Quote
human eyes which are most sensitive in yellow.

sp. "green" (550nm)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

GoForSmoke

Lumens still want a lot of yellow, color of the sun.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

taz3m

Quote

You really don't want to remove the comment - think what will happen.

Edit: Or, more to the point, think what will not happen.


Epp im starting to have an idea what really will not happen.  :~

Can you show me or more precisely give me a hint on the above please . .

Quote

Lux and lumens are units of brightness to human eyes which are most sensitive in yellow.

But plants reflect green and yellow, they absorb red and blue. What is best for plants does not appear so bright to human eyes or to your lux meter. You waste power on less useful wavelengths trying to increase lux, unless you're lighting for picture taking or best look. In general you want 4 red to 1 blue but you can change that some to better simulate different latitudes and time of year.

There are grow sites that you can verify this and maybe get numbers from. Red and blue leds with colored bulbs actually make good sensors for red and blue light, you need 2 pins and 1 resistor each.


Thats a really good piece of information. Thanks.

I think i shall be using the LDR to make known the condition of weather (Day, night, Rainy/Cloudy), so that i can switch on my T5 light based on the following:
http://learn.adafruit.com/photocells/using-a-photocell

Im pretty much interested in knowing how to get Red and Blue leds to act as good sensors. Any idea where should i start with !

tz
.....

Go Up