PaulRB:
I don't think the problem is in your code, I think it is in your circuit. Please post a schematic.
Yes i also think probkem is somewhere in hardware.I red at various places this problem is Electro magnetic interference of relay or something like that and many people were telling many things to fix that i tried but nothing worked out.I will try to post schematics.