I have used Arduino mega board. I have connected the circuit as shown, i.e. NO and NC of relay is connected to digital pin 2 and 3 of Arduino and common to 5V of arduino. By manually switching on and off the power supply we are checking the operating and release time. Instead of programmable power supply I am using a normal power supply.
The code I am using is not giving correct result. I should get 17 ms but I am getting 6 ms. Please hep me with a corrected code and please check the connection if it is correct.
How are you controlling the "normal" power supply? If you are turning it on (from being off) that will require the power supply to come up to voltage, could take a while.
This is he connection. When I on the power supply the relay switches and so operating time can be seen. Again by switching it off release time can be seen.
How do you know it should be 16 ms?
From the datasheet?
The number in the datasheet may very well be a max number. So 99.9% of the relays of this type will be faster....
I am not sure, but millis depends on interrupts and therefore should not be used inside interrupts...
Better use micros().
Even better would be to set a flag...
...and have micros read in loop after the flag was raised...
No, it can be used inside interrupts. But it's value will never change inside an interrupt. That's not really a problem, because an interrupt routine should always be as short as possible.
There is nothing incorrect with faster turn-over time. You get the first contact after 6 ms, most probably followed by bouncing. It may take 17 ms from turning relay power off until the NO contact settles after bouncing.
If you want to measure the turn-ON time you should take the relay power ON as the start time and the NO contact closing as the end time. Continue taking the end time whenever the NO contact bounces to OFF again..