delay function

Hello

I have a question about the delay() function . what I know is that this function stops the program for the specified period before allows to run the program again and again . But what is happening during the delayed period ?

for example , if the code as below :

int outPin = 13;                

void setup()
{
  pinMode(outPin, OUTPUT);      
}

void loop()
{
  digitalWrite(outPin, HIGH);   
  delay(2000);       
  digitalWrite(outPin, LOW);   
  delay(5000);        
}

During the delayed period ( 5 seconds ) , Does the component consume an amount of current equals to what it is consuming during the activation period ( 2 seconds ) or less ?

Regards,

If the question concerns power consumption, then you don't use delay() statements to attempt to minimise this because these would have an insignificant effect, you look at the sleep and power down options. E.g. Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors

During the delayed period ( 5 seconds ) , Does the component consume an amount of current equals to what it is consuming during the activation period ( 2 seconds ) or less ?

Similar like during the activation period. During the delay, just the test for time condition is performed in loop.

6v6gt:
If the question concerns power consumption, then you don't use delay() statements to attempt to minimise this because these would have an insignificant effect, you look at the sleep and power down options. E.g. Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors

thanks for your reply ,
I'm asking because sometimes I don't want from the sensor to take measurements every second in this way I think that I can save a power . In the illustrated code maybe the delayed period is not that effective to save power but what if I expand the delayed period ( 20 to 25 seconds ) , with the time the neglected amount of saved power will be worth , especially if you used more than one sensor .

Budvar10:
Similar like during the activation period. During the delay, just the test for time condition is performed in loop.

Thanks for your comment ,

Can I put the sensor in sleep mode ( timer as interrupt ? ) what I read is that there is away to put the Arduino UNO in sleep , put what I want is to put the sensor only in the sleep mode not the UNO .

Regards,

The actual function delay() (wiring.c) runs a continuous loop while checking the elapsed time in millis() to see when to return. What it also does, that I believe few people are aware of, is within that loop makes a call to yield(). yield() is declared as a weak function (hooks.c) which essentially means that you can declare a function or the same name in your code without conflict. The function in your code will override the weak declaration and gives you the opportunity to do something while in delay, without losing your place in the program.

Generally, with a Uno, your power savings options are limited. It consumes about 50mA simply by being powered up because of the regulator, the power led, the USB interface etc. etc. which more or less rules out extended battery operation.

What sensor are you using ?

If you want some power saving, check out the Narcoleptic library.

Thanks all for your comments ,
what if I deactivate the signal pin of the component ( LED, Buzzer, or sensor )? How much does that effect on the power consumption ?
digitalWrite(....., HIGH);
digitalWrite(....., LOW);

Regards,

Try Google - arduino power saving techniques

Hello,

You could try power the sensor by a digital output of your arduino (using a transistor if necessary), so that you can completely turn off the sensor when you don't need it.

Also look example sketch "Blink Without Delay".