Some links in this article are affiliate links. If you buy through them, LabprojectsBD may earn a small commission at no extra cost to you.
In this project, we detect faults on a single-phase power line and send an SMS alert to a mobile phone. We use a PIC16F73 microcontroller and a SIM300 GSM module. First, we look at why fault protection matters. Then we go through the circuit, the code and the PCB.
⚠️Disclaimer:
Working with electricity involves serious risk. Ensure you have the necessary skills and take proper safety precautions before attempting any electrical projects. Proceed at your own risk — the author assumes no responsibility for any damage, injury, or issues resulting from the use or misuse of the information provided.
All content on this website is original and protected by copyright. Please do not copy or reproduce content without permission. While most of the resources shared here are open-source and freely accessible for your learning and benefit, your respect for our intellectual effort is appreciated.
If you find our tutorials helpful, consider supporting us by purchasing related materials or sharing our work — it helps keep the content flowing.
Need help or have questions? Leave a comment below — the author is always happy to assist!
Table of Contents
Faults in single phase line
The most common fault on a single-phase line is a bad voltage. If the voltage goes too high or too low, it can damage home appliances. Most homes in Bangladesh get 220 V, although other countries use different values. In addition, sudden spikes on the line are dangerous, because a single spike can destroy an appliance. Therefore, we must watch the line voltage closely.

We can also add over-current protection. Most homes already have circuit breakers and fuses, which protect against short circuits. However, we can go further. When a load draws more than its rated current, we switch it off for a while. If the overload happens again and again, we switch it off permanently.
- Voltage divider & ADC scaling calculator – scale a voltage into your MCU ADC range
- CT burden resistor calculator – choose the burden resistor for a current transformer
Voltage and Current Sensing
Voltage sensing
Most control circuits work with signals of 0–5 V. Therefore, to measure the line voltage and the load current, we must scale them down into this range. The 220 V AC line is far too high for the PIC16F73 to measure directly. Instead, we use a small transformer, known here as a potential transformer (PT).
A simple 220:12 V transformer works well as the PT. It steps 220 V down to about 12 V, and one more stage then brings it into the microcontroller’s range.
Current Sensing
Similarly, to measure current, we use a current transformer (CT). It turns a large line current into a small, proportional secondary current.
To know more about the current transformer please check this.
A microcontroller can only measure voltage, not current. So we pass the CT secondary current through a burden resistor, which turns it into a voltage.

The calculation is simple: V = I × R. From the measured voltage and the known resistor and CT ratio, we can find the line current.
You can check these current transformers (CTs) at amazon.com :
PIC16F73 micro-controller
The PIC16F73 is a common 8-bit microcontroller in a 28-pin package with 22 I/O pins. It has a 5-channel, 8-bit ADC (AN0–AN4), which makes it easy to measure voltages. The image below shows its main features:

Every microcontroller has its own special features, and we use only the ones we need. In this project, we need the ADC to measure voltage and current. Later, we will also use the UART.
Analog to Digital Converter
An analog-to-digital converter (ADC) turns an analog voltage into a digital number. You can read more about ADCs here. The ADC features of the PIC16F73 are shown below.


A few registers control the ADC. We will set them up in the code section.
So far, we have covered the sensing. Next, the microcontroller processes the readings and decides what to do.
Load Control Device
To switch the load on and off while keeping the control circuit isolated, we use a relay.


A relay gives isolated switching and is easy to use. For this reason, we use it as the electromechanical switch in this project.
Communicating (GSM) Device
Another part of the project sends an SMS when a fault occurs. For this, we use a GSM module. We used a SIM300-based module, but any GSM module will do.
Here are some GSM modules that you can collect from amazon.com.
A GSM module talks over a UART and understands “AT” commands. You can get the SIM300 AT command set and the SIM800L AT command set from us on WhatsApp. Both modules use almost the same commands. The basic communication between the microcontroller and the GSM module looks like this:

The UART supports several baud rates, but most modules start at 9600 baud, so we use that. However, there is one important detail. Many GSM modules use 3.3 V logic, while the PIC runs at 5 V, which can damage the module’s RX pin. Therefore, use a voltage divider like this:
The divider drops the PIC’s 5 V TX signal to about 3.3 V. In this project, we only send SMS and never read the module’s replies, so we leave the module’s TX pin unconnected. If you do need it, note that the PIC’s RX pin has a Schmitt-trigger input that needs about 4 V for a reliable high. In that case, add a simple transistor level shifter.
Block Diagram
Here is the block diagram. We monitor the 220 V AC input with a CT and a PT, and a relay switches the load. The microcontroller reads the voltage and current and decides when to switch the relay through a driver transistor. Meanwhile, a 16×2 LCD shows the readings, and the GSM module sends SMS alerts. Finally, the power supply provides 5 V for the microcontroller and 12 V for the relay.
Circuit diagram
Here is the complete circuit diagram of the single-phase fault analyser:
You can see the transformers, the LCD, the microcontroller and the supporting parts.
Connection summery
As mentioned earlier, we use two transformers, the PT and the CT, to measure voltage and current. Starting from the supply, transformer TR1 gives 12 V AC. Then a bridge rectifier and capacitor C1 turn it into about 12 V of unregulated DC. This 12 V feeds the relay and the LM7805CV regulator (U3). Capacitor C2 smooths the regulator output. The regulated 5 V then powers the PIC16F73 and the LCD. The GSM module has its own supply.
Sensing
The PT (220:12) connects across the supply. In contrast, the CT and the relay (RL1) sit in series with the line and the load (L1), through a switch. In a real installation, you would connect several loads. Transistor Q2 (BC547) drives the relay coil. Diode D1 across the coil absorbs the back-EMF when the relay turns off, and capacitor C3 filters the coil supply.
After the PT, diode D2 rectifies the voltage. Resistor R3 gives the rectifier a small, steady load. Next, resistors R5 and R6 divide the voltage down, and ceramic capacitor C4 filters noise. The result goes to pin RA0 (AN0).
R4 is the burden resistor of the CT. It turns the CT secondary current into a voltage, which goes to pin RA1 (AN1).
With these two inputs, the ADC measures the line voltage and the load current.
Other parts
The LCD uses 4 data pins and 2 control pins, connected to RB0–RB5. On real hardware, add a resistor of about 2.7 kΩ between VEE and GND, or a potentiometer, to set the contrast.
The GSM module (U2) shares a common ground with the circuit. The PIC’s UART TX pin connects to the module’s RX pin through the R8/R9 divider, which lowers the logic level.
Finally, a buzzer gives an audible alarm. Transistor Q1 drives it, and both transistors (Q1 and Q2) use 10 kΩ base resistors.
The MCLR/Vpp pin connects to 5 V through a 10 kΩ resistor on real hardware. Also, the real board uses an 8 MHz crystal, which the circuit diagram does not show.
Flow chart
mikroC Code
/*******************************************************************************
* Program for, "1Ph fault analysis and senging sms through GSM" *
* Program Written by_ Engr. Mithun K. Das *
* MCU:PIC16F73B; X-Tal: 8MHz *
* Date:27-08-2016 *
*******************************************************************************/
// LCD module connections
sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;
// End LCD module connections
void Lcd_COut(char row, char col, const char *cptr)
{
char chr = 0; //first, it is used as empty string
Lcd_Out(row, col, &chr); //nothing to write but set position.
for ( ; chr = *cptr ; ++cptr ) Lcd_Chr_CP(chr); //out in loop
}
void UART_Write_CText(const char *cptr)
{
char chr;
for ( ; chr = *cptr ; ++cptr ) UART1_Write(chr);
}
unsigned int voltage=0,current=0;
char volt[]="V:000V ";
void Get_Voltage(void)
{
unsigned int temp0=0;
unsigned int maxpoint0=0;
unsigned int k=0;
ADCON0 = 0b00000001;// AN0 selected
for(k=0;k<1000;k++)
{
if(temp0 = ADC_Read(0),temp0>maxpoint0)
{
maxpoint0 = temp0;
}
}
maxpoint0 = abs(ceil(maxpoint0));
voltage = maxpoint0*3.477;// (5/255)*11.00*0.707*220/9*cal_factor;
volt[2] = (voltage/100) +48;
volt[3] = (voltage/10)%10 +48;
volt[4] = voltage%10 +48;
Lcd_Out(1,1, volt);
Delay_ms(20);
maxpoint0 = 0;
}
char curr[]="I:0.00A";
void Get_Current(void)
{
//char message4[] = "0.000A";
unsigned int temp1=0;
unsigned int maxpoint1=0;
int kk=0;
ADCON0 = 0b00000101;// AN1 selected
for(kk=0;kk<3000;kk++)
{
if(temp1 = ADC_Read(1),temp1>maxpoint1)
{
maxpoint1 = temp1;
}
}
current = maxpoint1*0.340;// get the load current
curr[2] = current/100+48;
curr[3] = '.';
curr[4] = (current/10)%10 +48;
curr[5] = (current/1)%10 +48;
Lcd_Out(1,9,curr);
Delay_ms(20);
maxpoint1 = 0;
}
void Send_SMS_Int(void)
{
UART1_Write_Text("AT\r\n");
Delay_ms(200);
UART1_Write_Text("AT+cmgf=1\r\n");
Delay_ms(200);
UART1_Write_Text("AT+cmgs=");
UART1_Write((char)'"');
UART1_Write_Text("xxxxxxx"); //add your mobile number here
UART1_Write((char)'"');
UART1_Write((char)13);
UART1_Write((char)10);
Delay_ms(2000);
}
#define Relay RC4_bit
#define Buzzer RC5_bit
unsigned int cnt_ol=0,trip_cnt=0;
bit permanent_trip,sms_cnt;
void main()
{
TRISA = 0xFF;//all input
TRISC = 0x00;//all output
ADCON1 = 0x00;//all analog in
Relay = 0;
Buzzer = 1;
Lcd_Init();//int LCD
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_COut(1,1,"1 Phase Fault");
Lcd_COut(2,1,"Analysis, GSM");
UART1_Init(9600);
Delay_ms(50); Buzzer = 0;
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
UART_Write_CText("AT\r\n");Delay_ms(100);
UART_Write_CText("AT\r\n");Delay_ms(100);
UART_Write_CText("AT\r\n");Delay_ms(100);//send AT command
permanent_trip=0;
sms_cnt=1;
while(1)
{
OERR_bit = 0;// clear Overrun Error bit
FERR_bit = 0;//clear Farming Error bit
UART_Write_CText("AT\r\n");
if(permanent_trip==0)
{
Get_Voltage(void);
Get_Current(void);
if(voltage>180 && voltage<240)// voltage is in between
{
if(current<75)//not overloaded
{
Relay = 1;
Lcd_COut(2,1,"Normal Condition");
Delay_ms(50);
sms_cnt = 1;//reset mask
}
else
{
cnt_ol++;
if(cnt_ol>5)
{
Relay = 0;//trip
trip_cnt++;
cnt_ol = 0;//clear cnt
Lcd_COut(2,1,"Tripped,Overload");
Buzzer = 1;
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Buzzer = 0;
Lcd_COut(1,1,"Sending SMS_");
Send_SMS_Int(void);
UART_Write_CText("System is Tripped due to overload.");
Delay_ms(300);
UART1_Write((char)26);
Delay_ms(300);
Lcd_COut(2,1,"SMS Sent_");
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
cnt_ol = 0;
}
}
}
else
{
Relay = 0;
if(voltage<=180)Lcd_COut(2,1,"Low Voltage");
if(voltage>=240)Lcd_COut(2,1,"High Voltage");
Delay_ms(1000);
trip_cnt++;
Lcd_COut(2,1,"Tripped, V_Error");
Buzzer = 1;
Delay_ms(2000);
Buzzer = 0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_COut(1,1,"Sending SMS_");
Send_SMS_Int(void);
UART_Write_CText("System is Tripped due to Voltage error.");
Delay_ms(300);
UART1_Write((char)26);
Delay_ms(300);
Lcd_COut(2,1,"SMS Sent_");
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
}
else
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_COut(1,1,"Permanently");
Lcd_COut(2,1,"Tripped");
Delay_ms(3000);
if(sms_cnt)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_COut(1,1,"Sending SMS_");
Send_SMS_Int(void);
Buzzer = 1;
UART_Write_CText("System is Permanently Tripped.");
Delay_ms(300);
UART1_Write((char)26);
Delay_ms(300);
sms_cnt = 0;
Lcd_COut(2,1,"SMS Sent_");
Delay_ms(1000);
Buzzer = 0;
Lcd_Cmd(_LCD_CLEAR);
}
}
if(trip_cnt>5)
{
permanent_trip = 1;
}
else
{
permanent_trip = 0;
}
}//while(1)
}//void main
Code Explanation
The code is simple and easy to follow.
// LCD module connections sbit LCD_RS at RB5_bit; sbit LCD_EN at RB4_bit; sbit LCD_D4 at RB3_bit; sbit LCD_D5 at RB2_bit; sbit LCD_D6 at RB1_bit; sbit LCD_D7 at RB0_bit; sbit LCD_RS_Direction at TRISB5_bit; sbit LCD_EN_Direction at TRISB4_bit; sbit LCD_D4_Direction at TRISB3_bit; sbit LCD_D5_Direction at TRISB2_bit; sbit LCD_D6_Direction at TRISB1_bit; sbit LCD_D7_Direction at TRISB0_bit; // End LCD module connections
This part sets up the LCD pins. The mikroC LCD library handles the rest.
void Lcd_COut(char row, char col, const char *cptr)
{
char chr = 0; //first, it is used as empty string
Lcd_Out(row, col, &chr); //nothing to write but set position.
for ( ; chr = *cptr ; ++cptr ) Lcd_Chr_CP(chr); //out in loop
}
This function stores the LCD text in program memory instead of RAM. As a result, we can show more messages.
void UART_Write_CText(const char *cptr)
{
char chr;
for ( ; chr = *cptr ; ++cptr ) UART1_Write(chr);
}
Similarly, this function saves RAM when sending text over the UART, so we can send longer messages.
unsigned int voltage=0,current=0;
char volt[]="V:000V ";
void Get_Voltage(void)
{
unsigned int temp0=0;
unsigned int maxpoint0=0;
unsigned int k=0;
ADCON0 = 0b00000001;// AN0 selected
for(k=0;k<1000;k++)
{
if(temp0 = ADC_Read(0),temp0>maxpoint0)
{
maxpoint0 = temp0;
}
}
maxpoint0 = abs(ceil(maxpoint0));
voltage = maxpoint0*3.477;// (5/255)*11.00*0.707*220/9*cal_factor;
volt[2] = (voltage/100) +48;
volt[3] = (voltage/10)%10 +48;
volt[4] = voltage%10 +48;
Lcd_Out(1,1, volt);
Delay_ms(20);
maxpoint0 = 0;
}
This function measures the line voltage. Since we sample the AC waveform directly, we need its peak. So the code takes 1000 samples and keeps the highest reading, which is the peak of the waveform.

Read our AC voltage measurement guide to learn more about this technique.
From the peak reading, the code calculates the RMS line voltage (peak divided by √2, times the scaling factor).
This function shows the reading on the LCD. Because the LCD works with ASCII characters, the code converts each digit to ASCII first.
char curr[]="I:0.00A";
void Get_Current(void)
{
//char message4[] = "0.000A";
unsigned int temp1=0;
unsigned int maxpoint1=0;
int kk=0;
ADCON0 = 0b00000101;// AN1 selected
for(kk=0;kk<3000;kk++)
{
if(temp1 = ADC_Read(1),temp1>maxpoint1)
{
maxpoint1 = temp1;
}
}
current = maxpoint1*0.340;// get the load current
curr[2] = current/100+48;
curr[3] = '.';
curr[4] = (current/10)%10 +48;
curr[5] = (current/1)%10 +48;
Lcd_Out(1,9,curr);
Delay_ms(20);
maxpoint1 = 0;
}
This function measures the load current, using the same peak technique as the voltage reading.
void Send_SMS_Int(void)
{
UART1_Write_Text("AT\r\n");
Delay_ms(200);
UART1_Write_Text("AT+cmgf=1\r\n");
Delay_ms(200);
UART1_Write_Text("AT+cmgs=");
UART1_Write((char)'"');
UART1_Write_Text("xxxxxxx"); //add your mobile number here
UART1_Write((char)'"');
UART1_Write((char)13);
UART1_Write((char)10);
Delay_ms(2000);
}
This function sends an SMS. It prepares the GSM module to send a text to the given number. Whenever we need an alert, we call it, print the message and send the end command.
#define Relay RC4_bit #define Buzzer RC5_bit unsigned int cnt_ol=0,trip_cnt=0; bit permanent_trip,sms_cnt;
This part declares the pins and variables.
TRISA = 0xFF;//all input
TRISC = 0x00;//all output
ADCON1 = 0x00;//all analog in
Relay = 0;
Buzzer = 1;
Lcd_Init();//int LCD
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_COut(1,1,"1 Phase Fault");
Lcd_COut(2,1,"Analysis, GSM");
UART1_Init(9600);
Delay_ms(50); Buzzer = 0;
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
UART_Write_CText("AT\r\n");Delay_ms(100);
UART_Write_CText("AT\r\n");Delay_ms(100);
UART_Write_CText("AT\r\n");Delay_ms(100);//send AT command
permanent_trip=0;
sms_cnt=1;
This part sets up the inputs and outputs, the ADC, the LCD and the UART. Then it shows the project name on the LCD and sends three “AT” commands to wake up the GSM module.
OERR_bit = 0;// clear Overrun Error bit
FERR_bit = 0;//clear Farming Error bit
UART_Write_CText("AT\r\n");
Here, the code clears the OERR and FERR error flags and sends “AT” regularly to keep the link with the GSM module alive.
if(permanent_trip==0)
{
Get_Voltage(void);
Get_Current(void);
if(voltage>180 && voltage<240)// voltage is in between
{
if(current<75)//not overloaded
{
Relay = 1;
Lcd_COut(2,1,"Normal Condition");
Delay_ms(50);
sms_cnt = 1;//reset mask
}
else
{
cnt_ol++;
if(cnt_ol>5)
{
Relay = 0;//trip
trip_cnt++;
cnt_ol = 0;//clear cnt
Lcd_COut(2,1,"Tripped,Overload");
Buzzer = 1;
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Buzzer = 0;
Lcd_COut(1,1,"Sending SMS_");
Send_SMS_Int(void);
UART_Write_CText("System is Tripped due to overload.");
Delay_ms(300);
UART1_Write((char)26);
Delay_ms(300);
Lcd_COut(2,1,"SMS Sent_");
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
cnt_ol = 0;
}
}
}
else
{
Relay = 0;
if(voltage<=180)Lcd_COut(2,1,"Low Voltage");
if(voltage>=240)Lcd_COut(2,1,"High Voltage");
Delay_ms(1000);
trip_cnt++;
Lcd_COut(2,1,"Tripped, V_Error");
Buzzer = 1;
Delay_ms(2000);
Buzzer = 0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_COut(1,1,"Sending SMS_");
Send_SMS_Int(void);
UART_Write_CText("System is Tripped due to Voltage error.");
Delay_ms(300);
UART1_Write((char)26);
Delay_ms(300);
Lcd_COut(2,1,"SMS Sent_");
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
}
else
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_COut(1,1,"Permanently");
Lcd_COut(2,1,"Tripped");
Delay_ms(3000);
if(sms_cnt)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_COut(1,1,"Sending SMS_");
Send_SMS_Int(void);
Buzzer = 1;
UART_Write_CText("System is Permanently Tripped.");
Delay_ms(300);
UART1_Write((char)26);
Delay_ms(300);
sms_cnt = 0;
Lcd_COut(2,1,"SMS Sent_");
Delay_ms(1000);
Buzzer = 0;
Lcd_Cmd(_LCD_CLEAR);
}
}
if(trip_cnt>5)
{
permanent_trip = 1;
}
else
{
permanent_trip = 0;
}
Inside the while(1) loop, the code first checks for a permanent trip. If one has occurred, the system stays off. Otherwise, it keeps checking the line voltage and current.
We used a normal range of 180–240 V for a 220 V line, which suits most appliances. For sensitive equipment, you can narrow this range.
The current limit is set to 75, which means 0.75 A. Above that, the system trips for overload. You can change it to suit your load.
PCB Design

This is an educational project, so the PCB is designed for learning. A commercial product would need a more robust design, with proper isolation and certification.
Thanks for reading. I hope this article helps with your own project. For more projects, don’t forget to subscribe.
Liked this article? Subscribe to our newsletter:
or,
Visit LabProjectsBD.com for more inspiring projects and tutorials.
Thank you!
See also: the electronics tools we recommend
Have a project in mind? LabProjectsBD designs power electronics, embedded firmware, IoT devices and production-ready PCBs for clients. Message us on WhatsApp, use the contact form, or see our services and portfolio.




3 Comments
enrique · 12/09/2020 at 3:41 pm
Excellent all your work, I am a faithful follower from Colombia, thank you very much for sharing your knowledge, I wish you many successes, I look forward to your next work
FANYOREAL · 18/04/2021 at 9:39 am
PERFECT work, I am a faithful follower from Nigeria, thank you very much for sharing your knowledge, I wish you many successes, I look forward to your next work
MKDas · 18/04/2021 at 10:11 am
It’s my pleasure. Thanks.