home automation Project

  1. when i turn on the supply of the board relay connected to D3 turns on for a fraction of second and then turns off, how to remove this problem??

  2. If all my devices are in ON state and if i turn off the power to the main board, after turning it ON again it gets reset means all the devices are in OFF state now how to remove this problem ??

  1. That fraction of a second is the time it takes for the software (your sketch) to turn the D3 at low state.
    The solution is to use inverse logic , ie logic zero is the ON state of the relay and logic 1 is the Off state
    If you had posted a schematic would have been easier to help.

  2. This problem is more difficult to solve. You need to somehow save the current state of the relay before power off. Provided this doesn't happen too often you can save the relay state in the MCU EEPROM and then at power on read the saved state and activate the relays accordingly.

ie add the following line to your loop:

 EEPROM.update(address, relayState);

EEPROM.update doesnt actually write to the EEPROM unless the value to be written is different from the current value. Therefore the EEPROM life doesnt get wasted.