I'm working on a project regarding home automation. in this project we put a circuitry inside of the regular switch board to operate the home appliances over internet. one of the feature of this project is "Lock Access" means user can specifically lock one or more hardware switches of that switchboard. In code I just use a 8bit variable to specify the current lock status of each 8 individual nodes(switches), and it also have backup stored in external EEPROM. To detect the current on/off status of hardware switches, i used 8 GPIOs with internal pull-up on and if switch is on it connects these GPIOs to ground.
In normal condition (not inside the switchboard) the full hardware works without any problem with all function checked. But when i install hardware inside the switchboard then approximately 2/5 cases the nodes getting locked randomly and this happens only at boot-up if i unlock each nodes manually it works perfectly. but after another boot-up i faced same issue again. though if i disconnect the FRC cable of GPIOs (which connects hardware to physical switches), the lock problem disappears. also when i keep attached programmer this issue never happens.
1> The 8bit lock variable is initialized and successfully read from the EEPROM at boot-up every time this problem occur.
2> 8bit lock variable is not used anywhere in debounce and switches input code.
3> I2C bus @350k contains 24C512, DS3231 and ATmega32A with pullup of 4.7k.
4> hardware uses TRIACs to control appliances. though it includes zero crossing, interrupt and all stuff.
5> SMPS 5v 1A (1000uf at output) to power WiFi chip and ATmega32A at peak current of ~600/500 ma.
6> This hardware have another lock named "user lock" this lock have exact same code but issue didn't happen with this yet. (hardware have account system if user lock on then only Admin can access the node).
7> the code uses 3 external interrupts, 3 timers, Serial interrupt @ 9600 baudrate and on chip I2C interface.
8> the ground for hardware switches is not direct ground, it's through BC547.
Things i tried:
1> i checked hardware with more possible bypass capacitors (100n), additional delays to allow proper setup I2C devices (2 seconds).
2> me and my friend tried to find any bug in code but cant find one (though all works okay in normal condition).
I don't know this makes sense or not but once my friend soldered wires direct from hardware and switches which replaced old FRC cable. and this problem didn't showed up yet and its not sounds like proper solution, though i checked it on single hardware, and i'm not sure why re wiring effects this much. then i rechecked old FRC cable it passed continuity test and all. i have made these 10 hardware and this issue appeared in 4 unit (all shares same code same hardware same PCB structure and all component from same vendor) i tried faulty hardware at different location and problem remains same. the occurrence probability of this problem changes according to location, i mean at my home it occurs but rarely and at my friends home it happens like 50% of time.