bootloader delay

i need a sketch on my arduino uno to start exactly five seconds after i turn on the power.
is there a way to see how long the bootloader waits to see if a sketch will be uploaded before starting the currently loaded sketch?
my plan is to add a delay at the very end of void setup that way the sketch start time would be
(bootloader) plus (delay) = 5 second delay before void loop
this way if i know the bootloader delay i can then do the math for the added delay

I think the easiest way is going to be to put delay(5000) at the first line of setup. You can of course tweak it for the bootloader delay, I can't remember where I saw it, but I think it's documented on the Arduino reference somewhere.

vini_i:
i need a sketch on my arduino uno to start exactly five seconds after i turn on the power.

The approach seems reasonable - the bootloader delay will depend what bootloader you're using but should be fixed as long as you don't burn a new bootloader. How exactly do you need to get the delay? As a starting point you could just write a sketch that writes a character to the serial port and see how much delay there is between releasing the reset button and that output appearing.

Alternatively try to track down which bootloader you are using (it should be possible to work it out), or simply get rid of the bootloader altogether - you'd need to upload using ICSP subsequently.

tobyb121:
I think the easiest way is going to be to put delay(5000) at the first line of setup. You can of course tweak it for the bootloader delay, I can't remember where I saw it, but I think it's documented on the Arduino reference somewhere.

And this of course is the best method. Keep the 'customization' delay in the specific sketch that requires it rather then a custom bootloader that will effect every sketch ever run with it.

Lefty

how can i find out what bootloader i am using and where do i find the delay for that boot loader.

i'm using an arduino uno rev3 with ATmega328
the boot loader was installed by arduino software version 1.0.4

(i have a programmer and i have removed and replaced the bootloader many times. but in my current project the arduino board is buried beneath a shield so i can't access the programming connector without major disassembly. i do have easy access to the regular usb port and that is the way i would like to program it in this case.)

I wouldn't bother messing with the bootloader. As has been suggested, start with delay(5000) at the end of setup(), turn on an LED at the end of the delay() and tweak the value to make the total startup delay exactly what you want. How accurate does the 5 second delay have to be ?

as accurate as possible.
i'm competing in a sumo bot competition and there is a five second delay before starting.
if i start too early i'm disqualified.
if i start a second late the other bot has a jump on me.

To find the delay accurately, get a second Arduino, make a sketch on the one you want to measure the delay for to set a pin high in the first line of setup, then on the other Arduino make a sketch that will reset the first one, pull the rst pin low, and have it measure the time until it pin goes high. If you do it this way you could probably get the boot time accurate to micro seconds

vini_i:
as accurate as possible.
i'm competing in a sumo bot competition and there is a five second delay before starting.
if i start too early i'm disqualified.
if i start a second late the other bot has a jump on me.

How accurately, and by what method, is the delay being measured in the competition ?

The bootloader delay is about 1.6 seconds, from a RESET. It might or might not be different from a powerup (it's supposed to be zero, from powerup, but that doesn't seem to always work.)
The 1.6s is approximately 0.6 seconds of making the LED flash, and 1s of timeout waiting for upload-like serial activity.

2 Likes