Update
2015-10-05 Wrong circuit diagram - Fixed
This is a very simple and accurate power guard circuit. This circuit is useful to guard the electronic or electrical devices from mains transients and spikes. Very high spikes can develop at power on due to sparking in the switch and more serious effects occur when power resumes after a power failure due to high magnetic field in the distribution transformer. This will damage your device permanently. To avoid such damages we can use this circuit.
This circuit used cheap PIC12F683 micro-controller. It controls all the functions of power guard. After power is applied, the green LED starts to blink. This circuit gives a time delay before giving power to the device. Default value is 30 seconds. However, you can change this value. See configuration for more details. After this delay, Green LED turns on permanently. Then Relay activates and connects power to the device.
When the power is abnormal Yellow or Red LED turns on and relay will turn off to protect our device. The Green LED will start to flash again and after delay time it check power status and turn relay on if the voltage is good. Yellow LED indicates low voltage and Red LED indicate high voltage. If all the LEDs are turn on, that indicates firmware error and pleases re-programmed micro-controller.
Connect multimeter to GP0 and check voltage. if it exceed 5v immediately turn off power and check the component and connections. (Typical value is 3 - 3.5v)
V = [Tp/12] x [(Vdd/1023) x Eeprom val x 4]
Tp = primary voltage
200 = [240/12] x [(5/1023) x Eeprom val x 4]
260 = [240/12] x [(5/1023) x Eeprom val x 4]
Eeprom value for low condition (200v) = 511 (1FF hex)
GP0 voltage = (2v4)
Eeprom value for high condition (260v) = 664 (298 hex)
GP0 voltage = (3v3)
Write those values to Eeprom.
V high = Eeprom (0)*256 + Eeprom (1) - (0x02 and 0x98)
V low = Eeprom (2)*256 + Eeprom (3) - (0x01 and 0xFF)
To change delay time simply changes the value of Eeprom address 4 (Default 0x3C)
Delay time in seconds = value of Eeprom address / 2
0 < value of Eeprom address < 255 (0 < Delay time in seconds < 127)
Minimum delay time is 0 seconds and maximum delay time is 2 minutes.
Not for the commercial purpose.
/***************************************************************************
Simple Power Guard
Copyright (C) 2014 Praneeth Kanishka
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses
>> Email: scorpionzblog@gmail.com
>> Web : http://scopionz.blogspot.com
***************************************************************************/
#define L_H GPIO.F1
#define L_L GPIO.F2
#define L_K GPIO.F4
#define RLY GPIO.F5
char idx, del=1, v_d, error;
int sense, v_h, v_l;
void main()
{
OSCCON = 0x70; // 8Mhz
ADCON0 = 0x00;
CMCON0 = 0x07; // Disable Comparators
CMCON1 = 0x00;
ANSEL = 0x01;
TRISIO = 0b00000001;
OPTION_REG = 0;
WPU=0;
Delay_ms(10);
GPIO = 0;
v_h = Eeprom_Read(1) + Eeprom_Read(0)*256;
v_l = Eeprom_Read(3) + Eeprom_Read(2)*256;
v_d = Eeprom_Read(4);
error = Eeprom_Read(5);
if(error>101) error=0;
Eeprom_Write(5, error+1);
Delay_ms(10);
//v_h = 664;
//v_l = 511;
//v_d = 10;
//error = 100;
while(1) {
if(error>99) {
RLY=0; L_K=1; L_H=1; L_L=1;
while(1);
}
if(del) {
for(idx=0; idx<v_d; idx++) { //60 = 30sec
L_K=~L_K;
Delay_ms(500);
}
del=0;
}
sense=Adc_Read(0);
if(sense>v_h) {RLY=0; L_K=0; L_H=1; del=1;}
else if(sense<v_l) {RLY=0; L_K=0; L_L=1; del=1;}
else {RLY=1; L_K=1; L_H=0; L_L=0;}
Delay_ms(500);
}
}
2015-10-05 Wrong circuit diagram - Fixed
Power Guard |
This is a very simple and accurate power guard circuit. This circuit is useful to guard the electronic or electrical devices from mains transients and spikes. Very high spikes can develop at power on due to sparking in the switch and more serious effects occur when power resumes after a power failure due to high magnetic field in the distribution transformer. This will damage your device permanently. To avoid such damages we can use this circuit.
This circuit used cheap PIC12F683 micro-controller. It controls all the functions of power guard. After power is applied, the green LED starts to blink. This circuit gives a time delay before giving power to the device. Default value is 30 seconds. However, you can change this value. See configuration for more details. After this delay, Green LED turns on permanently. Then Relay activates and connects power to the device.
When the power is abnormal Yellow or Red LED turns on and relay will turn off to protect our device. The Green LED will start to flash again and after delay time it check power status and turn relay on if the voltage is good. Yellow LED indicates low voltage and Red LED indicate high voltage. If all the LEDs are turn on, that indicates firmware error and pleases re-programmed micro-controller.
Circuit Diagram v2 |
Configuration and Calibration
For this circuit I used 12v step down transformer. Its output use to sense the power condition. Before using, you need to calibrate this circuit for working correctly. In my project, I choose 240v as normal, 260v as high and 200v as low voltage.Connect multimeter to GP0 and check voltage. if it exceed 5v immediately turn off power and check the component and connections. (Typical value is 3 - 3.5v)
V = [Tp/12] x [(Vdd/1023) x Eeprom val x 4]
Tp = primary voltage
200 = [240/12] x [(5/1023) x Eeprom val x 4]
260 = [240/12] x [(5/1023) x Eeprom val x 4]
Eeprom value for low condition (200v) = 511 (1FF hex)
GP0 voltage = (2v4)
Eeprom value for high condition (260v) = 664 (298 hex)
GP0 voltage = (3v3)
Write those values to Eeprom.
V high = Eeprom (0)*256 + Eeprom (1) - (0x02 and 0x98)
V low = Eeprom (2)*256 + Eeprom (3) - (0x01 and 0xFF)
Eeprom settings |
To change delay time simply changes the value of Eeprom address 4 (Default 0x3C)
Delay time in seconds = value of Eeprom address / 2
0 < value of Eeprom address < 255 (0 < Delay time in seconds < 127)
Minimum delay time is 0 seconds and maximum delay time is 2 minutes.
Not for the commercial purpose.