Power flicker arduino

Whenever I power my Arduino on, reset it, or send a new sketch to it, the power and led on the board flicker for about 1 or 2 seconds.

I thought putting a delay in the setup() would fix it, but it did not. Any ideas?

void setup(){

pinMode (13, OUTPUT);
delay(5000);

}

When the reset occurs, the bootloader does some stuff, listening for an attempt to upload a new sketch. Putting a delay after the bootloader has finished doing its thing, and waiting, will not stop whatever is causing the lights to flash.

It actually won't accomplish squat. No one should be using delay(). Especially not like that.

How are you powering the Arduino? What else do you have attached to the Arduino?

Without this BASIC information, that you would have thought would be an OBVIOUS requirement for getting an answer, we can't have a snowball's chance of giving an answer.

Given the lack of information you have provided, my best guess is that neutrinos are passing through the core of the chip causing excitation of the silicon atoms resulting in power drain in the second quadrant of the glimbart module of the fnergle wang.

I think I figured it out. If I immediately apply power to the pin that's driving the relay (connected to a water pump) the power will flicker for a second at startup.

I just need to move the delay to the start of the loop.

Thanks

Rather than moving the "delay"... find out what, when the relay is activated is causing the display to flicker. Moving the "delay" is only going to change when the display flickers. The display is flickering because of a marginal power supply or an improperly wired relay (Missing the back-emf protection diode) or both. The display should never flicker unless you are actively writing to it and then only the written text should flicker, Never the whole display.

Doc

I think it's normal. On the Arduino board, whenever I send a sketch, reset, or power it on, the TX and RX leds flash a few times along the built in pin 13 led. I think the problem I'm having is that I'm using pin 13 to switch my relay on and off.

Maybe I should switch pins!? I would try it now, but I'm testing a self waterer for the weekend.

Do you think that's the issue?

Thanks

command_z:
I think it's normal. On the Arduino board, whenever I send a sketch, reset, or power it on, the TX and RX leds flash a few times along the built in pin 13 led. I think the problem I'm having is that I'm using pin 13 to switch my relay on and off.

Maybe I should switch pins!? I would try it now, but I'm testing a self waterer for the weekend.

Do you think that's the issue?

Pin 13 is "flashed" by the bootloader to indicate that the bootloader has started.

You cannot safely use pin 13 for driving things like relays and such - it is only safe for use with simple indicators (LEDs, etc) or in combination with other pins (such as part of the SPI pin set) where it cannot actively do anything without other pins being set right.

The only way you can safely use pin 13 is to isolate the pin from whatever you are driving until such a time as your sketch can take over control of that pin. Typically you would use a tri-state buffer and control it with another pin. Pointless for just one pin, as you need another pin to control it - you might as well just use that "other" pin instead of pin 13.

Interesting. I did not know that.

I think I'll rewrite the sketch to use pin 12 as the control for the relay.

Thank you very much

//plug in at 10pm

#define SECOND 1000UL
#define MINUTE (SECOND * 60UL)
#define HOUR (MINUTE * 60UL)

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

void loop() {
  
  delay((HOUR*9));                        // 10pm

  digitalWrite(12, HIGH);  
  delay(SECOND*45);                       // on for 45 Seconds              
  digitalWrite(12, LOW);    
  
  delay((HOUR*10)-(SECOND*45));           // 7 00 45am
  
  digitalWrite(12, HIGH);                 // 5pm
  delay(SECOND*45);                       // on for 45 Seconds              
  digitalWrite(12, LOW);                  // 5 00 45pm   
  
  delay((HOUR*5)-(SECOND*45));            //10pm
  
}

Are double parenthesis a problem for the Arduino?

delay((HOUR*9))

Are double parenthesis a problem for the Arduino?

No, but missing semicolons are.

I'm had an issue with my relay yesterday and I thought the double parens might be the problem.

I have the Beefcake Relay kit from Sparkfun, connected on the low voltage side to 5v, ground and pin 12 (control) on the arduino. I'm powering the arduino with a 9V DC regulated wall adapter. The relay is switching on and off a waterpump.

I uploaded the code below to the Arduino last night (at 10pm), but this morning (at 7am), the relay did not click on for 25 seconds. After it did not switch on, I tested the relay with much shorter delay times and it worked fine.

Any idea of what the problem could be? I'm leaving town this afternoon, this may be my last chance to save my poor tomatos! Thank you all very much.

 //plug in at 10pm

#define SECOND 1000UL
#define MINUTE (SECOND * 60UL)
#define HOUR (MINUTE * 60UL)

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

void loop() {
  
  delay((HOUR*9));                        // 10pm

  digitalWrite(12, HIGH);  
  delay(SECOND*25);                       // on for 25 Seconds              
  digitalWrite(12, LOW);    
  
  delay((HOUR*10)-(SECOND*25));           // 7 00 25am
  
  digitalWrite(12, HIGH);                 // 5pm
  delay(SECOND*25);                       // on for 25 Seconds              
  digitalWrite(12, LOW);                  // 5 00 25pm   
  
  delay((HOUR*5)-(SECOND*25));            //10pm
  
}
  delay((HOUR*9));                        // 10pm

The comment notwithstanding, the delay() has no idea what time it starts or what time it ends. It knows when it starts and when to end relative to the time time that the Arduino has been running.

Yes, I understans that. I designed system to be powered on at 10pm. Sorry I should have said that.

Last night at 10pm, I had the sketch uploaded and wired to the relay (3 wires: 5v, ground and control). Then I connected the wall adapter to the arduino at exactly 10pm.

Then I did something I never did in testing: AFTER I powered the arduino on at 10pm, I plugged the water pump into the relay outlet. In testing I always had the water pump plugged in before I powered the arduino on. Could this of made something go haywire?

Thanks Paul

I know this post is over 5 years old, but someone might just stumble over it. And if you are making a similar project with timing, I recommend getting an RTC module. They are very easy to handle and such great helpers!
Google Arduino RTC or DS3231.