Even though I have given AC power supply, bulb is not lighting up. But one small LED (Red coloured one) on relay is blinking according to timings in the code.
*Power LED (Green colored one) is also on as I have given 5v supply from Arduino.
Is it possible the bulb is blown? Check that you're getting power on the bulb base connector terminals using a multimeter. Also check the relays voltage ratings.
I did not use the AC battery, I have given the AC power supply from the power port (plug) in my home!
Some part of the problem was solved. It was problem with my AC power supply port. I have changed the port. Now bulb is glowing!
Now the remaining issue is
Bulb is not following the delay given in the code. For example: If we give 5 sec ON and 5 sec OFF, out put is 5 sec ON - 5 sec 0FF - 2 sec ON - 2sec OFF -2 sec ON - 2sec OFF - 5sec ON - 5sec OFF like that.
On monitor also, only first 3 actions are print after that no printing is observed.
Your code works fine. I would expect that the power to your arduino is not enough. Low voltage would cause unpredictable errors. One of the first signs is the serial port drops off and at the same time maybe enough power to run the relay.
Expect ~75mA for tose 5volt relays, and some for the LEDs, and the Arduino.
You could be looking at ~200mA when both relays are on.
That could be too much for a 9volt block battery, even when fresh.
Leo..
My PC with a 1500 watt power supply will not give me enough power through the USB port to power my relays and my display properly. I use a 10 volt 1 amp wallwart. My USB ports won't keep up with charging the older tablets.
USB spec is for 500mA, but it seems that no all laptops can deliver that. if the laptop power is on battery, then you are using a battery.
it would be best to power the relay from an external power supply and have a common ground with your Arduino.
Now that you have used Wawa/Leo's technique, and found out that the Arduino is being reset, you can do further tests to help find the cause.
Try running your sketch (with Wawa's addition), but don't have the lamp plugged into the wall socket.
The results of this test will tell you whether it is the Lamp's current increase and or wiring that is causing the problem, or whether it is due to the relay coil being energised/de-energised.
Photo shows Gnd, P1, P2. I assume that P1 controls relay 1, P2 controls relay 2.
PCB connector doesn't make sense. There is a power LED (green) but I don't see any 'Power" connection. I would assume that P1 and P2 would control the gates of the transistors. Am I missing something? Really need the spec sheet of the pcb to know what is going on here. My guess is the the Arduino power is sagging, forcing a power on reset.
@ shivaaprs
Try with the lightbulb removed.
If it still reboots, it must be the supply.
How do you supply your Arduino.
If you're sure the supply is ok, try a capacitor across the supply of the relay board.
Close to the relay board. Try 100-1000uF.
That will bridge supply dips and absorb relay kickback.
Leo..