In this article, we are going to make a Simple Component Detector using PIC16F877A microcontroller. Using the basic working principles of different semiconductors, we can identify the devices. Here, we are using some simple and basic techniques, using these techniques, we can measure/detect resistors, diodes, LEDs, transistors, MOSFETs, Logic Gates, and so on. So let’s start!

Disclaimer:

Electricity poses inherent risks. Adequate skills are crucial for handling it safely. Undertake tasks at your own risk; the author disclaims responsibility for misuse, harm, or errors. Website content is unique and copyrighted; refrain from unauthorized copying. Most articles are open-source for your benefit. Feel free to use the knowledge freely, and consider purchasing available resources. For assistance or guidance, comment below; the author aims to help. Some articles may contain affiliate links, having no impact on you but supporting the author with a commission. Thank you for your understanding.

Advertisements

Table of Contents

The basic principle of Component Tester using PIC16F877A:

Each electronic component has its own properties and behaviors. Like a resistor simply resists the current flow through it. A Diode is uni-directional, a transistor is biased by its base, and so on. When we need to detect a particular device, we have to check the individual properties one by one.

Once the properties are matched with one component, then we can check other properties if match or not. And finally, we can clarify the device identification and value if possible.

To keep the working mechanism simple, we have divided the components into groups. The two legs components, the three legs components, and the logic gates.

Resistor checking:

In the two-leg categories, the resistor, diodes, LEDs can be checked. For the resistor, we can simply check if the voltage divider rule is working with it or not. If works, then the value can be calculated from the voltage.

Diode checking:

Diodes are not bi-directional like a resistor. So, to detect a diode we can simply check if the current is following bidirectionally. I mean supply to one leg and check the voltage on the other and then alter the leg and check the result. If the uni-direction properties are found, we can assure it is a diode.

Transistor (BJTs) checking:

Checking a transistor is not simple like a resistor or diode. Each transistor is actually two diodes one of which is activated by the base.

In a NPN transistor, if the base is high, it triggers the Collector to Base diode and output flows through the emitter. And if a PNP, when the base is low, it triggers the base to collector diode, and the current flows from emitter to collector. Based on this basic principle, we can detect the BJTs. How?

Simple, supply to any two pins and measure the other one. If the BJT is NPN, the other pin will have a voltage. Again supply any one pin high and keep another low and measure the other. If the BJT is PNP, the other pin will have a voltage.

Although there are other properties we may need to measure but first, you have to identify them. Once you master this, you can add the other properties checking mechanism.

MOSFETs?

MOSFETs are basically following a common pin configuration, GDS. To detect a MOSFET, we can pull up the drain and trigger the gate. If the source is low and the Drain responds with a gate, it is a N-Channel MOSFET. On the other hand, if it is a P-Channel, then we can keep the drain high and measure the source with a pull-down. If the source responds with gate (=0), it is a P-Channel confirmation.

How to detect Logic Gates?

Detecting a logic gate is the easiest task. First, check if it is an inverter/buffer gate by checking any serially two pins, then if not, trigger the input two and check the output. Compared with the logic chart, we can identify the gate id.

Circuit Diagram of our detector:

Circuit explanation:

As we are supplying, triggering, measuring different pin behaviors, so we used some resistors in series with each test pin keeping some pull-down resistors. J1 is for the two legs components, J2 for 3, and J3 is for the logic gates. There are no such complex circuits in this project.

mikroC code:

The code is written in mikroC pro for PIC.

/*******************************************************************************
*                  Program for 'Common Semiconductor Tester'                   *
*                       Written By_ Engr. Mithun K. Das                        *
*                          MCU:PIC16F877A; X-Tal: 8MHz                         *
*                                Date:02-03-2014                               *
*******************************************************************************/
// LCD module connections
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;

sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_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
}

#define      Buzzer     RD2_bit
#define      LED        RB1_bit

short test = 0;
short Pin2A=0,Pin2B=0,Pin3A=0,Pin3B=0,Pin3C=0,LogicA=0,LogicB=0,LogicC=0;
short test1=0,test2=0,test3=0,test4=0;



/************************ Functions for PIN 2A*********************************/
void Set_Pin2A_Out()
{
      TRISA0_bit = 0;//set as output
      RA0_bit = 1;
      Delay_ms(100);
}
void Read_2A()
{
      Pin2A = RA0_bit;
}
void Clear2A()
{
   RA0_bit = 0;
}
void Set_Pin2A_In()
{
      RA0_bit = 0;
      TRISA0_bit = 1;//set as input
      Delay_ms(100);
}
/************************ Functions for PIN 2B ********************************/

void Set_Pin2B_Out()
{
      TRISA1_bit = 0; //set as output
      RA1_bit = 1;
      Delay_ms(100);
}
void Read_2B()
{
      Pin2B = RA1_bit;
}
void Clear2B()
{
   RA1_bit = 0;
}
void Set_Pin2B_In()
{
      RA1_bit = 0;
      TRISA1_bit = 1;
      Delay_ms(100);
}

/************************ Functions for PIN 3A ********************************/
void Set_Pin3A_Out()
{
      TRISA2_bit = 0;
      RA2_bit = 1;
      Delay_ms(100);
}
void Read_3A()
{
      Pin3A = RA2_bit;
}
void Clear3A()
{
   RA2_bit = 0;
}
void Set_Pin3A_In()
{
      TRISA2_bit = 1;
      Delay_ms(100);
}

/************************ Functions for PIN 3B ********************************/
void Set_Pin3B_Out()
{
      TRISA3_bit = 0;
      RA3_bit = 1;
      Delay_ms(100);
}
void Read_3B()
{
      Pin3B = RA3_bit;
}
void Clear3B()
{
   RA3_bit = 0;
}
void Set_Pin3B_In()
{
      TRISA3_bit = 1;
      Delay_ms(100);
}

/************************ Functions for PIN 3C ********************************/
void Set_Pin3C_Out()
{
      TRISA5_bit = 0;
      RA5_bit = 1;
      Delay_ms(100);
}
void Read_3C()
{
      Pin3C = RA5_bit;
}
void Clear3C()
{
   RA5_bit = 0;
}
void Set_Pin3C_In()
{
      TRISA5_bit = 1;
      Delay_ms(100);
}

/************************ Functions for LogicA ********************************/
void Set_LogicA_Out()
{
      TRISC0_bit = 0;
      RC0_bit = 1;
      Delay_ms(100);
}
void Read_LogicA()
{
      LogicA = RC0_bit;
}
void Clear_LogicA()
{
      RC0_bit = 0;
}
void Set_logicA()
{
      RC0_bit = 1;
}
void Set_LogicA_In()
{
      TRISC0_bit = 1;
      Delay_ms(100);
}
/************************ Functions for LogicB ********************************/
void Set_LogicB_Out()
{
      TRISC1_bit = 0;
      RC1_bit = 1;
      Delay_ms(100);
}
void Read_LogicB()
{
      LogicB = RC1_bit;
}
void Clear_LogicB()
{
      RC1_bit = 0;
}
void Set_logicB()
{
      RC1_bit = 1;
}
void Set_LogicB_In()
{
      TRISC1_bit = 1;
      Delay_ms(100);
}
/************************ Functions for LogicC ********************************/
void Set_LogicC_Out()
{
      TRISC2_bit = 0;
      RC2_bit = 1;
      Delay_ms(100);
}
void Read_LogicC()
{
      LogicC = RC2_bit;
}
void Clear_LogicC()
{
      RC2_bit = 0;
}
void Set_logicC()
{
      RC2_bit = 1;
}
void Set_LogicC_In()
{
      TRISC2_bit = 1;
      Delay_ms(100);
}
/********************** Button at Interrupt ***********************************/

void Interrupt() iv 0x0004 ics ICS_AUTO
{
   if(INTF_bit)
   {
        INTF_bit = 0;
        if(!RC3_bit) test = 1;//Test for 2 leg devices
        if(!RD0_bit) test = 2;//Test for 3 leg devices
        if(!RD1_bit) test = 3;//Test for Logic Gates
   }
}
void TwoLegTest(void);
void ThreeLegsTest(void);
void LogicGateTest(void);
void MOSFET_Test(void);
void Resistor_Calculation(void);
short cnt_led=0;
void main()
{
    TRISA = 0b00111111;//all input
    TRISC = 0b00001111;//all out
    TRISD = 0b00001011;
    TRISB1_bit = 0;//set as output
    ADCON1 = 0x07;// all Digital I/O
    ADCON0 = 0x00; //turn off ADC

    GIE_bit = 1;//Enable global interrupt
    INTE_bit = 1;//Enable INT interrupt
    INTEDG_bit = 0;//Falling edge int
    INTF_bit = 0;//clear flag
    
    LED = 1;
    cnt_led = 0;
    
    Lcd_Init();//initialize LCD
    Lcd_Cmd(_LCD_CLEAR);//clear display
    Lcd_Cmd(_LCD_CURSOR_OFF);// cursor off
    Lcd_COut(1,1,"Semicond. Tester");
    Lcd_COut(2,1,"labprojectsbd.cm");
    Delay_ms(1000);
    Lcd_Cmd(_LCD_CLEAR);//clear display
    while(1)
    {
         if(test==1)
         {
              LED = 1;
              cnt_led = 0;
              Buzzer = 1;
              Lcd_Cmd(_LCD_CLEAR);//clear display
              Delay_ms(100);
              Buzzer = 0;
              TwoLegTest(void);
              test = 0;
              Buzzer = 1;
              Lcd_Cmd(_LCD_CLEAR);//clear display
              Delay_ms(100);
              Buzzer = 0;
         }
         if(test==2)
         {
              LED = 1;
              cnt_led = 0;
              Buzzer = 1;
              Lcd_Cmd(_LCD_CLEAR);//clear display
              Delay_ms(100);
              Buzzer = 0;
              ThreeLegsTest(void);
              test = 0;
              Buzzer = 1;
              Lcd_Cmd(_LCD_CLEAR);//clear display
              Delay_ms(100);
              Buzzer = 0;
         }
         if(test==3)
         {
              LED = 1;
              cnt_led = 0;
              Buzzer = 1;
              Lcd_Cmd(_LCD_CLEAR);//clear display
              Delay_ms(100);
              Buzzer = 0;
              LogicGateTest(void);
              Buzzer = 1;
              Lcd_Cmd(_LCD_CLEAR);//clear display
              Delay_ms(100);
              Buzzer = 0;
              test = 0;
         }
         
         if(cnt_led<155)cnt_led++;
         if(cnt_led>50)
         {
             if(cnt_led==51)Lcd_Cmd(_LCD_CLEAR);//clear display
             if(cnt_led==54)LED = 0;
             if(cnt_led<100)
             {
                Lcd_COut(1,1,"For more, Visit:");
                Lcd_COut(2,1,"labprojectsbd.cm");
             }
             else
             {
                if(cnt_led==101)Lcd_Cmd(_LCD_CLEAR);//clear display
                Lcd_COut(1,1,"FB_ facebook.com");
                Lcd_COut(2,1,"  /LabProjectsBD");
             }
             Delay_ms(100);
         }
         else
         {
             Lcd_COut(1,1," Insert Device  ");
             Lcd_COut(2,1," & Press Button ");
             Delay_ms(100);
         }
    }//while(1)
}//void main

void TwoLegTest(void)
{
    Lcd_COut(1,1,"Scannig 2 Legs_");
    Set_Pin2B_In();
    Set_Pin2A_Out();
    Read_2B();
    if(Pin2B==1)//C is high
    {
       Set_Pin2A_In();
       Set_Pin2B_Out();
       Read_2A();
       if(Pin2A==1)
       {
          Resistor_Calculation(void);
       }
       else
       {
          Lcd_Cmd(_LCD_CLEAR);//clear display
          Lcd_COut(1,1,"Possible Device_");
          Lcd_COut(2,1,"Diode K-A  OK");
          Delay_ms(3000);
       }
    } //Diode
    else
    {
       Set_Pin2A_In();
       Set_Pin2B_Out();
       Read_2A();
       if(Pin2A==1)
       {
          Lcd_Cmd(_LCD_CLEAR);//clear display
          Lcd_COut(1,1,"Possible Device_");
          Lcd_COut(2,1,"Diode A-K  OK");
          Delay_ms(3000);
       }
       else
       {
          Lcd_Cmd(_LCD_CLEAR);//clear display
          Lcd_COut(1,1,"Result_");
          Lcd_COut(2,1,"Open/No device");
          Delay_ms(3000);
       }
    }//Diode
}

void Resistor_Calculation(void)
{
    unsigned long resistor = 0;
    unsigned int adc_rd = 0;
    short kk;
    char mess_resistor[] = "R:000.000 KOhm";
    TRISA0_bit = 1;//set as input
    ADCON1 = 0b00001110;//AN0 only
    ADCON0 = 0x01;//Read AN0
    adc_rd = 0;//clear previous data
    resistor=0;
    for(kk=0;kk<10;kk++)
    {
        adc_rd = ADC_Read(0);//take sample and add
        Delay_ms(10);
        resistor += ((560000*1023/adc_rd)-560680);
    }
    resistor/=10;


       //Display the value
        mess_resistor[2] = resistor/100000 + 48;
        mess_resistor[3] = (resistor/10000)%10 + 48;
        mess_resistor[4] = (resistor/1000)%10 + 48;
        mess_resistor[5] = '.';
        mess_resistor[6] = (resistor/100)%10 + 48;
        mess_resistor[7] = (resistor/10)%10 + 48;
        mess_resistor[8] = (resistor)%10 + 48;


    Lcd_Cmd(_LCD_CLEAR);//clear display
    Lcd_COut(1,1,"Result_ Resistor");
    Lcd_Out(2,1,mess_resistor);
    Delay_ms(5000);
    ADCON1 = 0x07;// all Digital I/O
    ADCON0 = 0x00; //turn off ADC
}
void ThreeLegsTest(void)
{
   Lcd_Cmd(_LCD_CLEAR);//clear display
   Lcd_COut(1,1,"Scannig 3 Legs_");
   //Find the base first...
         //Check for N-P-N first
         Set_Pin3A_Out();
         Set_Pin3B_In();
         Set_Pin3C_In();
         Read_3B();
         Read_3C();
         if(Pin3B==1 && Pin3C==1)//Base at pinA
         {
            //Base at pinA
               //check if pinB is emitter...
               Set_Pin3B_In();//emitter
               Set_Pin3C_Out();//collector high
               Set_Pin3A_Out();//base high
               Read_3B();
               if(Pin3B == 1)
               {
                  //check the reverse case
                  Clear3A();
                  Read_3B();
                  if(Pin3B == 0)
                  {
                      Lcd_Cmd(_LCD_CLEAR);//clear display
                      Lcd_COut(1,1,"Result_ BJT");
                      Lcd_COut(2,1,"N-P-N  B-E-C");
                      Delay_ms(3000);
                  }
                  else
                  {
                      //Its a P-N-P
                      goto PNP_Test;
                  }
               }
               else
               {
                     //check if pinC is emitter...
                     Set_Pin3C_In();//emitter
                     Set_Pin3B_Out();//collector high
                     Set_Pin3A_Out();//base high
                     Read_3C();
                     if(Pin3C == 1)
                     {
                        //check the reverse case
                        Clear3A();
                        Read_3C();
                        if(Pin3C == 0)
                        {
                            Lcd_Cmd(_LCD_CLEAR);//clear display
                            Lcd_COut(1,1,"Result_ BJT");
                            Lcd_COut(2,1,"N-P-N  B-C-E");
                            Delay_ms(3000);
                        }
                        else
                        {
                            //Its a P-N-P
                            goto PNP_Test;
                        }
                     }

               }
         }
         else
         {
             //Find the base first
             Set_Pin3A_In();
             Set_Pin3B_Out();
             Set_Pin3C_In();
             Read_3A();
             Read_3C();
             if(Pin3A==1 && Pin3C==1)//Base at PinB
             {
                 //Base at PinB
                     //check if pinC is emitter...
                     Set_Pin3C_In();//emitter
                     Set_Pin3B_Out();//Base high
                     Set_Pin3A_Out();//Collecter high
                     Read_3C();
                     if(Pin3C == 1)
                     {
                        //check the reverse
                        Clear3B();
                        Read_3C();
                        if(Pin3C == 0)
                        {
                             Lcd_Cmd(_LCD_CLEAR);//clear display
                             Lcd_COut(1,1,"Result_ BJT");
                             Lcd_COut(2,1,"N-P-N  C-B-E");
                             Delay_ms(3000);
                        }
                        else
                        {
                            //Its a P-N-P
                            goto PNP_Test;
                        }
                     }
                     else
                     {
                         //check if pinA is emitter...
                         Set_Pin3A_In();//emitter
                         Set_Pin3B_Out();//Base high
                         Set_Pin3C_Out();//Collecter high
                         Read_3A();
                         if(Pin3A == 1)
                         {
                              //check the reverse
                              Clear3B();
                              Read_3A();
                              if(Pin3A == 0)
                              {
                                   Lcd_Cmd(_LCD_CLEAR);//clear display
                                   Lcd_COut(1,1,"Result_ BJT");
                                   Lcd_COut(2,1,"N-P-N  E-B-C");
                                   Delay_ms(3000);
                              }
                              else
                              {
                                  //Its a P-N-P
                                  goto PNP_Test;
                              }
                         }
                     }
             }
             else
             {
                 Set_Pin3A_In();
                 Set_Pin3B_In();
                 Set_Pin3C_Out();
                 Read_3A();
                 Read_3B();
                 if(Pin3A==1 && Pin3B==1)//Base at pinC
                 {
                         //check if pinA is emitter...
                         Set_Pin3A_In();//emitter
                         Set_Pin3C_Out();//Base high
                         Set_Pin3B_Out();//Collecter high
                         Read_3A();
                         if(Pin3A == 1)
                         {
                             Clear3C();
                             Read_3A();
                             if(Pin3A == 0)
                             {
                                   Lcd_Cmd(_LCD_CLEAR);//clear display
                                   Lcd_COut(1,1,"Result_ BJT");
                                   Lcd_COut(2,1,"N-P-N  E-C-B");
                                   Delay_ms(3000);
                             }
                             else
                             {
                                goto  PNP_Test;
                             }
                         }
                         else
                         {
                             //check if pinB is emitter...
                             Set_Pin3B_In();//emitter
                             Set_Pin3C_Out();//Base high
                             Set_Pin3A_Out();//Collecter high
                             Read_3B();
                             if(Pin3B == 1)
                             {
                                 Clear3C();
                                 Read_3B();
                                 if(Pin3B == 0)
                                 {
                                     Lcd_Cmd(_LCD_CLEAR);//clear display
                                     Lcd_COut(1,1,"Result_ BJT");
                                     Lcd_COut(2,1,"N-P-N  C-E-B");
                                     Delay_ms(3000);
                                 }
                                 else
                                 {
                                    goto  PNP_Test;
                                 }
                             }
                         }
                 }
                 else //now check for P-N-P Transistor
                 {
//=========================  P-N-P Test =====================================//
                    PNP_Test:
                    Set_Pin3A_In();//check for base at pin A
                    Set_Pin3B_Out();
                    Set_Pin3C_Out();
                    Read_3A();
                    if(Pin3A==1)//Base at pin A
                    {
                         //check for E & C...
                            //check for Emitter at pin B
                            Set_Pin3C_In();//Collector
                            Set_Pin3B_Out();//emitter high
                            Set_Pin3A_Out();//set base high
                            Read_3C();
                            if(Pin3C==0)
                            {
                                //check the reverse case
                                Clear3A();
                                Read_3C();
                                if(Pin3C == 1)
                                {
                                     Lcd_Cmd(_LCD_CLEAR);//clear display
                                     Lcd_COut(1,1,"Result_ BJT");
                                     Lcd_COut(2,1,"P-N-P  B-E-C");
                                     Delay_ms(3000);
                                }
                                else
                                {
                                   goto end_of_bjt;
                                }
                            }
                            else
                            {
                               //check for Emitter at pin C
                               Set_Pin3B_In();//Collector
                               Set_Pin3C_Out();//emitter high
                               Set_Pin3A_Out();//set base high
                               Read_3B();
                               if(Pin3B == 0)
                               {
                                   //check the reverse case
                                   Clear3A();
                                   Read_3B();
                                   if(Pin3B == 1)
                                   {
                                      Lcd_Cmd(_LCD_CLEAR);//clear display
                                      Lcd_COut(1,1,"Result_ BJT");
                                      Lcd_COut(2,1,"P-N-P  B-C-E");
                                      Delay_ms(3000);
                                   }
                                   else
                                   {
                                      goto end_of_bjt;
                                   }
                               }
                               else
                               {
                                  goto end_of_bjt;
                               }
                            }
                    }
                    else
                    {
                        Set_Pin3B_In();//check for base at pin B
                        Set_Pin3A_Out();
                        Set_Pin3C_Out();
                        Read_3B();
                        if(Pin3B==1)//base at pin B
                        {
                            //check for E & C...
                              //check for Emitter at pin C
                              Set_Pin3A_In();//Collector
                              Set_Pin3C_Out();//emitter high
                              Set_Pin3B_Out();//set base high
                              Read_3A();
                              if(Pin3A==0)
                              {
                                  //check the reverse case
                                  Clear3B();
                                  Read_3A();
                                  if(Pin3A == 1)
                                  {
                                       Lcd_Cmd(_LCD_CLEAR);//clear display
                                       Lcd_COut(1,1,"Result_ BJT");
                                       Lcd_COut(2,1,"P-N-P  C-B-E");
                                       Delay_ms(3000);
                                  }
                                  else
                                  {
                                     goto end_of_bjt;
                                  }
                              }
                              else
                              {
                                 //check for Emitter at pin A
                                 Set_Pin3C_In();//Collector
                                 Set_Pin3A_Out();//emitter high
                                 Set_Pin3B_Out();//set base high
                                 Read_3C();
                                 if(Pin3C == 0)
                                 {
                                     //check the reverse case
                                     Clear3B();
                                     Read_3C();
                                     if(Pin3C == 1)
                                     {
                                        Lcd_Cmd(_LCD_CLEAR);//clear display
                                        Lcd_COut(1,1,"Result_ BJT");
                                        Lcd_COut(2,1,"P-N-P  E-B-C");
                                        Delay_ms(3000);
                                     }
                                     else
                                     {
                                        goto end_of_bjt;
                                     }
                                 }
                                 else
                                 {
                                    goto end_of_bjt;
                                 }
                              }
                        }
                        else
                        {
                              Set_Pin3C_In();
                              Set_Pin3A_Out();
                              Set_Pin3B_Out();
                              Read_3C();
                              if(Pin3C==1) //Base at pin C
                              {
                                 //check for E & C...
                                    //check for Emitter at pin B
                                    Set_Pin3A_In();//Collector
                                    Set_Pin3B_Out();//emitter high
                                    Set_Pin3C_Out();//set base high
                                    Read_3A();
                                    if(Pin3A==0)
                                    {
                                        //check the reverse case
                                        Clear3C();
                                        Read_3A();
                                        if(Pin3A == 1)
                                        {
                                             Lcd_Cmd(_LCD_CLEAR);//clear display
                                             Lcd_COut(1,1,"Result_ BJT");
                                             Lcd_COut(2,1,"P-N-P  C-E-B");
                                             Delay_ms(3000);
                                        }
                                        else
                                        {
                                           goto end_of_bjt;
                                        }
                                    }
                                    else
                                    {
                                       //check for Emitter at pin A
                                       Set_Pin3B_In();//Collector
                                       Set_Pin3A_Out();//emitter high
                                       Set_Pin3C_Out();//set base high
                                       Read_3B();
                                       if(Pin3B == 0)
                                       {
                                           //check the reverse case
                                           Clear3C();
                                           Read_3B();
                                           if(Pin3B == 1)
                                           {
                                              Lcd_Cmd(_LCD_CLEAR);//clear display
                                              Lcd_COut(1,1,"Result_ BJT");
                                              Lcd_COut(2,1,"P-N-P  E-C-B");
                                              Delay_ms(3000);
                                           }
                                           else
                                           {
                                              goto end_of_bjt;
                                           }
                                       }
                                       else
                                       {
                                          goto end_of_bjt;
                                       }
                                    }
                              }//pinC Base
                              else
                              {
                                  end_of_bjt:
                                  MOSFET_Test(void);
                              }
                        }
                    }

                 }
             }
         }
}//BJT test

void MOSFET_Test(void)
{
        Set_Pin3B_In();//set for Drain
        Set_Pin3C_Out();//Source or gate high
        Read_3B();
        if(Pin3B==1)
        {
            //check reverse case for S-D Diode
            Set_Pin3C_In();//set for source
            Set_Pin3B_Out();//Drain high
            Read_3C();
            if(Pin3C==0)//test pass
            {
                Set_Pin3C_Out();//set source
                Clear3C();//clear source
                Set_Pin3A_Out();//charge the gate
                Delay_ms(1000);

                Set_Pin3B_In();//drain input
                Set_Pin3C_Out();
                Read_3C();
                if(Pin3C==1)
                {
                    //check the reverse for short ckt
                    Set_Pin3C_In();//drain input
                    Set_Pin3B_Out();
                    Read_3B();
                    if(Pin3B==1)
                    {
                        Lcd_Cmd(_LCD_CLEAR);//clear display
                        Lcd_COut(1,1,"Result_ MOSFET");
                        Lcd_COut(2,1,"G-D-S    OK");
                        Delay_ms(3000);
                    }
                    else
                    {
                        Lcd_Cmd(_LCD_CLEAR);//clear display
                        Lcd_COut(1,1,"Result_ ");
                        Lcd_COut(2,1,"Open/No Device");
                        Delay_ms(3000);
                    }
                }
                else
                {
                        Lcd_Cmd(_LCD_CLEAR);//clear display
                        Lcd_COut(1,1,"Result_ ");
                        Lcd_COut(2,1,"Open/No Device");
                        Delay_ms(3000);
                }

            }
            else
            {
                Lcd_Cmd(_LCD_CLEAR);//clear display
                Lcd_COut(1,1,"Result_ ");
                Lcd_COut(2,1,"Open/No Device");
                Delay_ms(3000);
            }
        }
        else
        {
             Lcd_Cmd(_LCD_CLEAR);//clear display
             Lcd_COut(1,1,"Result_ ");
             Lcd_COut(2,1,"Open/No Device");
             Delay_ms(3000);
        }
}

void LogicGateTest(void)
{
    Lcd_Cmd(_LCD_CLEAR);//clear display
    Lcd_COut(1,1,"Scanning Gates..");
    test = 0;
    // test for logic gates
    //first check for NOR-Gate (7402)
      //case # 1
        Set_LogicA_In();
        Set_LogicB_Out();
        Set_logicB(); //1
        Set_LogicC_Out();
        Set_logicC();//1
        Read_LogicA();
        test4 = LogicA;
          //case # 2
            Set_LogicA_In();
            Set_LogicB_Out();
            Clear_LogicB(); //0
            Set_LogicC_Out();
            Set_logicC();//1
            Read_LogicA();
            test3 = LogicA;
              //case # 3
                  Set_LogicA_In();
                  Set_LogicC_Out();
                  Clear_LogicC(); //0
                  Set_LogicB_Out();
                  Set_logicB();//1
                  Read_LogicA();
                  test2 = LogicA;
                    //case # 3
                      Set_LogicA_In();
                      Set_LogicC_Out();
                      Clear_LogicC(); //0
                      Set_LogicB_Out();
                      Clear_LogicB(); //0
                      Read_LogicA();
                      test1 = LogicA;
     //match if its NOR Gate...
     if(test4==0 && test3==0 && test2==0 && test1==1)
     {
          Lcd_Cmd(_LCD_CLEAR);//clear display
          Lcd_COut(1,1,"Result_ ");
          Lcd_COut(2,1,"NOR-Gate 7402 OK");
          Delay_ms(3000);
     }
     else //check for other logic gates...
     {
          //check for inverter gate
          Set_LogicB_In();
          Set_LogicA_Out();
          Clear_LogicA(); //0
          Read_LogicB();
          if(LogicB==1)
          {
              Set_logicA();//1
              Read_LogicB();
              if(LogicB==0)
              {
                  Lcd_Cmd(_LCD_CLEAR);//clear display
                  Lcd_COut(1,1,"Result_ ");
                  Lcd_COut(2,1,"INVERTER 7404 OK");
                  Delay_ms(3000);
              }
              else
              {
                 goto other_logic;
              }
          }
          else
          {
              //check for other logic gates...
              other_logic:

              //check for other 4 logic gates
                    //case # 1
                      Set_LogicC_In();
                      Set_LogicA_Out();
                      Clear_LogicA(); //0
                      Set_LogicB_Out();
                      Clear_LogicB(); //0
                      Read_LogicC();
                      test1 = LogicC;
                       //case # 2
                          Set_LogicC_In();
                          Set_LogicA_Out();
                          Set_logicA(); //1
                          Set_LogicB_Out();
                          Clear_LogicB(); //0
                          Read_LogicC();
                          test2 = LogicC;
                            //case # 3
                                Set_LogicC_In();
                                Set_LogicA_Out();
                                Clear_LogicA(); //0
                                Set_LogicB_Out();
                                Set_logicB(); //1
                                Read_LogicC();
                                test3 = LogicC;
                                   //case # 3
                                      Set_LogicC_In();
                                      Set_LogicA_Out();
                                      Set_logicA(); //1
                                      Set_LogicB_Out();
                                      Set_logicB(); //1
                                      Read_LogicC();
                                      test4 = LogicC;
                 //now match the conditions...
                 if(test1==1 && test2 == 1 && test3 == 1 && test4 == 0)//nand gate
                 {
                     Lcd_Cmd(_LCD_CLEAR);//clear display
                     Lcd_COut(1,1,"Result_ ");
                     Lcd_COut(2,1,"NAND Gate 7400 ");
                     Delay_ms(3000);
                 }
                 else if(test1==1 && test2 == 0 && test3 == 0 && test4 == 0)// NOR gate
                 {
                     Lcd_Cmd(_LCD_CLEAR);//clear display
                     Lcd_COut(1,1,"Result_ ");
                     Lcd_COut(2,1,"NOR Gate 7402 OK");
                     Delay_ms(3000);
                 }
                 else if(test1==0 && test2 == 0 && test3 == 0 && test4 == 1)// AND gate
                 {
                     Lcd_Cmd(_LCD_CLEAR);//clear display
                     Lcd_COut(1,1,"Result_ ");
                     Lcd_COut(2,1,"AND Gate 7408 OK");
                     Delay_ms(3000);
                 }
                 else if(test1==0 && test2 == 1 && test3 == 1 && test4 == 0)// Ex-OR gate
                 {
                     Lcd_Cmd(_LCD_CLEAR);//clear display
                     Lcd_COut(1,1,"Result_ ");
                     Lcd_COut(2,1,"Ex-OR Gate 7486 ");
                     Delay_ms(3000);
                 }
                 else if(test1==0 && test2 == 1 && test3 == 1 && test4 == 1)// OR gate
                 {
                     Lcd_Cmd(_LCD_CLEAR);//clear display
                     Lcd_COut(1,1,"Result_ ");
                     Lcd_COut(2,1,"OR Gate 7432 OK");
                     Delay_ms(3000);
                 }
                 else
                 {
                     Lcd_Cmd(_LCD_CLEAR);//clear display
                     Lcd_COut(1,1,"Result_ ");
                     Lcd_COut(2,1,"Device Not Found");
                     Delay_ms(3000);
                 }

          }
     }


}//Logic Gate test
//end

The project was actually written in 2014. Anyway, I kept every part as simple as possible to keep it easy for everyone. You can add more options to it.

Only the resistor measurement function is a little complex.

void Resistor_Calculation(void)
{
    unsigned long resistor = 0;
    unsigned int adc_rd = 0;
    short kk;
    char mess_resistor[] = "R:000.000 KOhm";
    TRISA0_bit = 1;//set as input
    ADCON1 = 0b00001110;//AN0 only
    ADCON0 = 0x01;//Read AN0
    adc_rd = 0;//clear previous data
    resistor=0;
    for(kk=0;kk<10;kk++)
    {
        adc_rd = ADC_Read(0);//take sample and add
        Delay_ms(10);
        resistor += ((560000*1023/adc_rd)-560680);
    }
    resistor/=10;


       //Display the value
        mess_resistor[2] = resistor/100000 + 48;
        mess_resistor[3] = (resistor/10000)%10 + 48;
        mess_resistor[4] = (resistor/1000)%10 + 48;
        mess_resistor[5] = '.';
        mess_resistor[6] = (resistor/100)%10 + 48;
        mess_resistor[7] = (resistor/10)%10 + 48;
        mess_resistor[8] = (resistor)%10 + 48;


    Lcd_Cmd(_LCD_CLEAR);//clear display
    Lcd_COut(1,1,"Result_ Resistor");
    Lcd_Out(2,1,mess_resistor);
    Delay_ms(5000);
    ADCON1 = 0x07;// all Digital I/O
    ADCON0 = 0x00; //turn off ADC
}

There the 560000 & 560860 come from voltage divider rules with minor calibration factors.

PCB:

The project is also developed in a small pocket size PCB.

Test result:

Before proceeding, you must keep in mind that this is a simple detector, not a tester. To convert it into a tester, more features must be added including accuracy improvement. Maybe in another article, I’ll present the tester one.

Conclusion:

This project was a very basic one. As this is only a detector, the values may not be accurate. To make it more accurate, you have to improve the code. But for the basic one, this project is very helpful. I hope you can use this resource in your own project. Thanks for reading.

For Professional Designs or Help:

Loading

You can check: 5 coolest multimeters you can buy.


MKDas

Mithun K. Das; B. Sc. in EEE from KUET; Head of R&D @ M's Lab Engineering Solution. "This is my personal blog. I post articles on different subjects related to electronics in the easiest way so that everything becomes easy for all, especially for beginners. If you have any questions, feel free to ask through the contact us page." Thanks.

2 Comments

Joy · 22/10/2021 at 1:58 pm

How to check inductor.

    MKDas · 22/10/2021 at 4:18 pm

    Using frequency response method.

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *