C Projects | Create a Simple Program to Show Transistor Experiment Result Using C Programming Language

image
C Coding

In this project, we are going to create a simple program to collect transistor experiment result using C programming language.

Table of Content

What to Expect?

This practice program will help practice the following: 

  • How to create an array for integers and float (decimal) numbers
  • How to create a continuous loop
  • How to search through an array to present the data required by the user using the for loop 
  • Making decision using the if-else statement

After reading this tutorial, be sure to type the code in your text editor and run it, to be sure it works. You can also make charges to it, as it suits you.

This program was done using code::blocks IDE.

The Transistor Connection

This program works with arrays to present the result of a PNP transistor when connected in the forward mode, as shown in the image below.

PNP transistor
PNP transistor

A transistor experiment is performed by connecting a forward voltage, and as the voltage increased from zero to any maximum number, the transistor changes to different state and each of the state determines the current flowing in the transistor. This program will show three different states of the transistor. The Forward Blocking Mode, the Forward Current Flowing Mode and The Saturation state.

One array will hold the different voltages (VBE) that can be applied to a transistor, another parallel array will hold the current flowing in the transistor at different voltage levels. If a user want to see the state of the transistor and its particular voltage and current, the experiment number will be inputted by the user which will be use to loop through the arrays and an output will be given, showing the voltage, the current and the transistor state.

Procedures

Step 1:

Define the standard input and output header file: Open an empty file in code::blocks, name the file and save. After saving type the following code

#include <stdio.h>

Step 2:

Define the experiment variable array, voltage variable array and current variable array: To define the arrays, you need to define the data types. Add the following code to the previous one.

main()
{
    int experiment[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
    float vbe[12] = {0.1, 0.3, 0.7, 1.5, 2.5, 3.7, 4.8, 5.6, 7.8,
                    9.2, 11.5, 12.7};
    float current[12] = {0.0, 0.0, 10.2, 23.5, 37.8, 48.9, 50.6,
                        66.2, 78.4, 120.6, 120.6, 120.6};

Feel free to add comment if need be.

Step 3:

Define other variables to be used in the experiment: apart from the array variables other variables with different data types are required to be added to the program. Add the following code to the previous ones

    int ctr; //this is a variable for the counter
    int pick; //this is a variable to hold the users choice
    int choice1; //this variable determines if the program will run after first trier
    int choice2 = 0; //this will help the counter loop through the three arrays

The comment attached, explain what each variable will do 

Step 4:

Write an introductory message to Guide the user and let the user make a choice if he/she wants to view the experiment result. After the message, the user will be given the choice to start the program or quit. Add the following code to the previous ones.

   printf("\nThis program carried out an experiment on a PNP transistor in the forward mode");
    printf("\n12 experiment was carried out at different voltage levels");
    printf("\nTo see the VBE, current through the junction and transistor state");
    printf("\nClick 1 otherwise click 0: ");
    scanf(" %d", &choice1);

Step 5:

Create a do-while loop; within the loop, let the user pick the experiment result he/she wants to view. Create a for loop to check the experiment number, if the number picked is available in the experiment, it should be assigned to the choice2 variable which will be used to check the voltage and current array for that particular experiment chosen. Add the following code to the previous ones

 do
    {
         printf("\nPick an experiment number: ");
         scanf(" %d", &pick);
        // Code to loop through the experiment array
        for (ctr=0; ctr<12; ctr++)
        {
            if (pick == experiment[ctr])
            {
                choice2 = ctr;
                break;
            }
        }

Step 6:

Create different if-else statement to show the experiment picked, the voltage value, the current value and the transistor state. Add the following codes to the previous ones.

// Code to output the different answers
        if (vbe[choice2] < 0.6)
        {
            printf("\nFor the experiment %d", choice2+1);
            printf("\nVBE = %.1fV.", vbe[choice2]);
            printf("\nIc = %.2fA.", current[choice2]);
            printf("\nTransistor state: forward blocking (FB)\n");
        }
        else if ((vbe[choice2] >= 0.6) && (vbe[choice2] <= 9.0))
        {
            printf("\nFor the experiment %d", choice2+1);
            printf("\nVBE = %.1fV.", vbe[choice2]);
            printf("\nIc = %.2fA.", current[choice2]);
            printf("\nTransistor state: Forward Current Flowing (FCF)\n");
        }
        else if (vbe[choice2] > 9.0)
        {
            printf("\nFor the experiment %d", choice2+1);
            printf("\nVBE = %.1fV.", vbe[choice2]);
            printf("\nIc = %.2fA.", current[choice2]);
            printf("\nTransistor state: Saturation State (SS)\n");
        } 

Step 7:

Write codes to help the user decide if he/she wants to end the program or continue viewing the result. Then close the do-while loop with a while statement. Add the following codes to the previous ones


	printf("\n\nIf you want to check another experiment click 1 otherwise click 0: ");
        scanf(" %d", &choice1);
    } while (choice1 != 0);

    return (0);
}

This is the end of the program. You can test your program by clicking on the yellow wrench icon with a green play button as shown in the image below:

play button Image 2
Image 2

View how the codes works in the video below:


Conclusion

From testing the code, you will notice how the different voltage in the array is presented according to the experiment number, and how the transistor state changes at different experiments.

Don't forget to check our C programming page for more programming projects

Follow us on our social media handles to stay updated.