Microcontroller based Diode and Bipolar Junction Transistor (BJT) tester


Most of the digital multimeters these days have built-in features for testing diodes and sometimes transistors. The purpose of this project is to demonstrate a simple way to construct a testing device for diodes and bipolar junction transitors (BJTs) using a microcontroller. The testing algorithm is based on a simple fact that a working PN junction conducts current in only one direction. A PIC16F688 microcontroller is used in this project that switches the bias voltage across the PN junctions of diode and transistors, and determines if a particular junction is normal, open or short.


The logic behind testing a diode is straightforward. A diode is a PN junction that allows the conduction of current only in one direction. Therefore, a good diode will conduct current in only one direction. If it does in both the directions, it means the diode is short, and if it does in neither direction, it is open. The circuit implementation of this logic is shown below.

This concept can be easily extended to test a transistor by realizing that a transistor consists of two PN junctions: one betwen the base and the emitter (BE junction), and the another between the base and the collector (BC junction). If both the junctions conduct in only one direction, the transistor is normal, otherwise it is faulty. We can also identify the type (PNP or NPN) of the transistor by considering the direction of the current conduction. Three I/O pins of a microcontroller are required to implement the testing algorithm for a transistor.

The test sequence for a transistor would go like this.

  1. Set D2 High and read D1 and D3. If D1 is High, BE junction conducts, otherwise not. If D3 is High, BC junction conducts, otherwise not.
  2. Set D1 High and read D2. If D2 is High, EB junction conducts, otherwise not.
  3. Set D3 High and read D2. If D2 is High, CB junction conducts, otherwise not.

Now, if only the BE and BC junctions conduct, the transistor is of NPN type and is working fine. And, if only the EB and CB junctions conduct, the transistor is still normal but the transistor type is PNP. All other cases (like EB and BE both conduct, or BC and CB both not conducting, etc.) indicate the transistor is not good.

Circuit Diagram and Description

The circuit diagram for this project is pretty simple. It has two push button switches for inputs, named Select and Detail. Pressing the Select button allows to choose between the diode and transistor testings, and the Detail button is active only in case of transistor testing and displays the details of the test results like the transistor type and both the junction status. The three legs of a test transistor (E, B, and C) are grounded through 1 K resistors, and the two PN junctions will be tested through RA0, RA1, and RA2 port pins of a PIC16F688 microcontroller. The testing of a diode requires only two pins, and will use the E and C pins. That’s why they have alternate labels, D1 and D2, in the circuit diagram.

Circuit setup on the breadboard


The firmware for this project is developed with MikroC compiler. While programming, you must be very careful about the direction settings of the three test pins (RA0, RA1, and RA2) because they change frequently while running the testing algorithm. Before setting any test pin to High, you must make sure that the other two pins are defined as input pins so that there won’t be any voltage conflict or short circuit between the port pins.

Project: Diode and Transistor Tester
Internal Oscillator @ 4MHz, MCLR Enabled, PWRT Enabled, WDT OFF
Copyright @ Rajendra Bhatt
November 9, 2010
// LCD module connections
sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections
sbit TestPin1 at RA0_bit;
sbit TestPin2 at RA1_bit;
sbit TestPin3 at RA2_bit;
sbit Detail at RA4_bit;
sbit SelectButton at RA5_bit;
// Define Messages
char message1[] = “Diode Tester”;
char message2[] = “BJT Tester”;
char message3[] = “Result:”;
char message4[] = “Short”;
char message5[] = “Open “;
char message6[] = “Good “;
char message7[] = “BJT is”;
char *type = “xxx”;
char *BE_Info = “xxxxx”;
char *BC_Info = “xxxxx”;
unsigned int select, test1, test2, update_select, detail_select;
unsigned int BE_Junc, BC_Junc, EB_Junc, CB_Junc;
void debounce_delay(void){
void main() {
ANSEL = 0b00000000; //All I/O pins are configured as digital
CMCON0 = 0x07 ; // Disbale comparators
PORTC = 0;
PORTA = 0;
TRISC = 0b00000000; // PORTC All Outputs
TRISA = 0b00111000; // PORTA All Outputs, Except RA3 (I/P only)
Lcd_Init();                      // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);             // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF);        // Cursor off
Lcd_Out(1,2,message1);           // Write message1 in 1st row
select = 0;
test1 = 0;
test2 = 0;
update_select = 1;
detail_select = 0;
do {
update_select = 1;
switch (select) {
case 0 : select=1;
case 1 : select=0;
} //case end

if(select == 0){   // Diode Tester
TRISA = 0b00110100; // RA0 O/P, RA2 I/P
TestPin1 = 1;
test1 = TestPin3 ; // Read I/P at RA2
TestPin1 = 0;
TRISA = 0b00110001; // RA0 I/P, RA2 O/P
TestPin3 = 1;
test2 = TestPin1;
TestPin3 = 0;

if((test1==1) && (test2 ==1)){
if((test1==1) && (test2 ==0)){
if((test1==0) && (test2 ==1)){
if((test1==0) && (test2 ==0)){

}  // End if(select == 0)

if(select && !detail_select){     // Transistor Tester
update_select = 0;
// Test for BE and BC Junctions of NPN
TRISA = 0b00110101; // RA0, RA2 I/P, RA1 O/P
TestPin2 = 1;
BE_Junc = TestPin1 ; // Read I/P at RA0
BC_Junc = TestPin3;   // Read I/P at RA2
TestPin2 = 0;

// Test for EB and CB Junctions of PNP
TRISA = 0b00110110; // RA0 O/P, RA1/RA2 I/P
TestPin1 = 1;
EB_Junc = TestPin2;
TestPin1 = 0;
TRISA = 0b00110011; // RA0 O/P, RA1/RA2 I/P
TestPin3 = 1;
CB_Junc = TestPin2;
TestPin3 = 0;

if(BE_Junc && BC_Junc && !EB_Junc && !CB_Junc){
type = “NPN”;
BE_info = “Good “;
BC_info = “Good “;
if(!BE_Junc && !BC_Junc && EB_Junc && CB_Junc){
type = “PNP”;
BE_info = “Good “;
BC_info = “Good “;
else {
Lcd_Out(2,10,”Bad “);
type = “Bad”;
if(select && !Detail){
switch (detail_select) {
case 0 : detail_select=1;
case 1 : detail_select=0;


} //case end
update_select = 1;

if(detail_select && update_select){

// Test for BE Junction open
if(!BE_Junc && !EB_Junc){
BE_info = “Open “;
// Test for BC Junction open
if(!BC_Junc && !CB_Junc){
BC_info = “Open “;
// Test for BE Junction short
if(BE_Junc && EB_Junc){
BE_info = “Short”;

// Test for BC Junction short
if(BC_Junc && CB_Junc){
BC_info = “Short”;
update_select = 0;
}       // End if (detail_select)

} while(1);

Download Source Code and HEX file


Here are some of the pictures  I took of my diode and BJT tester while testing various input conditions.

Rest of the pictures

Related Posts


  • Sudarsha Deshmukh

    how to burn hex file in this microcontroller

  • hi friend ,plz send code,given code are not run.
    plz help me

  • plz send code,given code are not run.
    plz help me

  • i want to ask if we want to test the transistor do we need to recognise the pin leg first or just put it then the system can tell which one is collector,base or emitter ?

  • it was very helpful can you send the c code for me on life cycle testing of electrical loads using pic

  • plz I want to flowchart of bjt tester its arjent

  • bojour
    R B

    j’ai trouvé votre projet tres intéréssant et atractif .
    Je l’ai réalisé.
    il a fonctionné du premier coup.
    ma question est ::
    1)) l’ afficheur LCD indique le résulta à une fréquence ” RAPIDE ” .
    trés difficile de lire le résulta .
    et pour tant :: indication ” JUSTE ” ( PNP ; B E =OK B C = OK .))
    2)) J ‘ai vérifié les FUSIBLES des BIT comme indiqué =osc :int rc-clkout.
    =inEX swich OVER
    =boden: (bod:OFF sboden::OFF )
    = Failclock Mon:(OFF)

    VOILA ce que j’ai configuré pour les FUSIBLES .

    je vous remerci d’avance pour votre aide dans la mesure du possible

    ben ali


  • hi
    it just want to ask whether i can view this program using VB on computer rather than lcd

  • hello..do you have any idea circuit for smart solar phone charger?

  • Thank you RB for this post it was very helpful to me as i am currently doing the same kind of project in School, but for mine i used PIC16F690 as the micro controller(i did make some changes to your original codes to suit my own PIC). I am not well grounded in Electronics yet .Please may i know by what mechanism does the micro controller use in (1)identifying if the transistor being tested is PNP or NPN. (2)in identifying if the diode is short,closed or good.Plese i would be really looking forward to a reply from you. Thank you

  • Why is this problem ?

    DiodeTester.c:47: warning: return type of ‘main’ is not ‘int’

  • can you update hex file for p16f84

    thanks very much

  • i am using P16f84

  • yes thanks i am sorry but really this is last question

    when compile code the mikro give me this message

    function maia not found ???

  • thanks R-B but i have another question
    there are to lines ( legs ) connected to pin 4 for reset and detail switch right ?

    and the leds in the pics of circuit why did you use them and where you connect them

    thanks for your time

  • thanks very much for replying and i want to ask the modifying the code pins and the type of pic and what should i change too

    and why did you put the MCLR pin number 4 to LCD directly

    thanks a lot

  • Hello can i use p16f877a pic for this project i am not expert in language c so i want to know why did you use the p16f688 and what the difference between p16f877 and p16f688

    thanks for your wonderful project

    • PIC16F688 is a 14-pin whereas PIC16F877A is a 40-pin device. You can use any other microcontroller for this project, but you need to modify the code accordingly.

  • Hello Mr. RB, told him that I have not been able to compile the code in the MikroC DiodeTester, I’ve checked everything with the help of this compiler MikroC and still shows me the message (‘,’Expect But LCD_RS found) on line 8 , I mean the line where this (SBIT LCD_RS at RC4_bit;) and another message that says (Internal error), if you will kindly publish the entire project would greatly appreciate it, without more, you apologize for the inconvenience, thank you.

    Regards, Joel.

  • Ok, RB going to study more with the help of MikroC, although the process of creating a project in mikroPascal MikroC is identical to and I see no difference, I’ll be more careful in repect, I owe much for your help, I am very interested in these types of projects, especially those of the instrumentation to the electronics such as development of an ESR tester, Semiconductor, and a few others, prefer to develop in mikroPascal, so I fully understand the code in mikroPascal MikroC to translate it, my interest is very particular because it means a great saving yourself money frabric their measurement instruments, good response and I owe the time to answer my questions, oh and you excuse my poor English, my language is Spanish.
    Regards, Joel.

  • RB Hi friend, told him that I can not compile the source code transistor tester, v8.0 MikroC compiler tells me error in the first line of the program, I’m no expert in programming of PICs nor expert in C, although I have good knowledge in Pascal and digital electronics, but not much of the language C, which starts here get errors, something else the while (1) has no verdict at the end, if you could help I would greatly appreciate it
    Thank you for your attention, I await your response.
    Regards, Joel.
    LCD_RS SBIT at RC4_bit / / here start errors
    LCD_EN SBIT at RC5_bit;
    LCD_D4 SBIT at RC0_bit;
    LCD_D5 SBIT at RC1_bit;
    LCD_D6 SBIT at RC2_bit;
    LCD_D7 SBIT at RC3_bit;
    LCD_RS_Direction SBIT at TRISC4_bit;
    LCD_EN_Direction SBIT at TRISC5_bit;
    LCD_D4_Direction SBIT at TRISC0_bit;
    LCD_D5_Direction SBIT at TRISC1_bit;
    LCD_D6_Direction SBIT at TRISC2_bit;
    LCD_D7_Direction SBIT at TRISC3_bit;

    • Joel,
      I didn’t get how did you get these lines. The source code has something like this.

      // LCD module connections
      sbit LCD_RS at RC4_bit;
      sbit LCD_EN at RC5_bit;
      sbit LCD_D4 at RC0_bit;
      sbit LCD_D5 at RC1_bit;
      sbit LCD_D6 at RC2_bit;
      sbit LCD_D7 at RC3_bit;

      Besides, did you read MikroC user’s manual to learn how to create a new project in MikroC? I would suggest to read this first : Flashing LED. Once you created the project, then copy the content of source code and paste it on the program editor. Delete the main() function that is automatically included in the editor window when a new project is created.

  • R-B thank you very much my friend, I’ll review the source code to see if I can compile with MikroC, after this, I will add code to test mosfet transistor, thanks again, I am aware and working on this.

    Greetings Joel.

  • Very interesting your project, I really liked the use of the LCD, if you could send me the source code to my mail would really appreciate it, I’m trying to implement some code for trasistores MOSFET, if you have any ideas or suggestions you even better, do not forget to send me the code, which is published here with errors and I can not compile in MikroC, thanks for your help, I hope your answer.

    Email: zeussnet@yahoo.es

  • You have to be kidding – using a micro with display module for something that few passive components and LED/multimeter can do?

    See here: http://sound.westhost.com/project31.htm (measures also the current amplification coefficient)
    Or this one – few logic gates and 2 LEDs: http://www.josepino.com/electronics/transistor-tester-circuit

    • You are right, there are easier ways to achieve the same goal. This project demonstrates that there exist some difficult ones too.
      Never mind, the purpose is to demonstrate a technique using microcontroller.

  • nice and simple approach.

Leave a Reply

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