C program to print the unique elements in an unsorted array

Write a C program to print the unique elements in an unsorted array.

In this c program, we have to print the unique elements for the given Unsorted Array of length N. For example : If there are three occurrences of 7 then we have to print 7 only once.
We can find the unique element in an array by traversing the array from index 0 to N-1 and for each element again traversing the array to find any duplicated element.

C Programming Code

#include<stdio.h>

int main()

{

int n;

printf(“Enter array size: “);

scanf(“%d”, &n);

int a[n];

printf(“Enter %d numbers: “, n);

for(int i=0; i<n; i++)

scanf(“%d”, &a[i]);

int temp = a[0];

for(int i=1; i<n; i++)

{

temp = temp ^ a[i];

}

printf(“Unique element in the array is: %d”, temp);

return 0;

}

Logic behind the Program

Take input from the users and store it in an array(lets call it inputArray).
We will start traversing input Array from index 0 to N -1 and for any element at index i(inputArray[i]), we will search for duplicate element from index 0 to i.
If we find a duplicate element then we skip current element otherwise print it on screen.

Interfacing Seven Segment Display to 8051 Microcontroller with Circuit Diagram

INTERFACING SEVEN SEGMENT DISPLAY WITH 8051 MICROCONTROLLER

INTRODUCTION:

  • It is primarily an electronic device used for displaying alphanumeric values or decimal values.
  • The Seven segment display more commonly used on display board in various complexes and shopping malls.
  • The pivotal role of this display board is to show some command or instructions to the humans that is understandable to them.

CIRCUIT DIAGRAM:

WORKING:

Common Anode Configuration:

  • Depending on the decimal digits to be displayed the particular set of LED’S are forward biased.
  • Example:  If we want to light the digit 8 seven digits has to be lighted up in order to display it.

TRUTH TABLE:

 

  • The above table indicates the corresponding LED’s to be displayed in order to get the corresponding numbers.(0-9).
  • Both common cathode and common cathode is present.

PIN DIAGRAM:

CODING FOR SINGLE DIGIT:

#include<reg51.h>

void delay(int k) //delay function

{

int i,j;

for(i=0;i<k;i++)

 for(j=0;j<1275;j++);

}

void main()

{

unsigned char i;

unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};

P2=0x00;

while(1)

{

 for(i=0;i<10;i++)

 {

  P2=arr[i];

  delay(100);

 }

}

}

PROCEDURE:

  1. Firstly burn the program to microcontroller.
  2. Then make the connections as per circuit diagram.
  3. We must make sure that pins a to g of seven segment are given to P2.0 to P2.6 of microcontroller(PORT 2).
  4. Switch on the power supply then he numbers 0 – 9 starts displaying after some interval.
  5. This process repeats itself in an infinite loop.

CONNECTION DIAGRAM:

PROJECT EXECUTION VIDEO:

Click here to see the Video

C Program to Print the Age and Name of Employee.

Write a C program to print the age and name of employee using fprintf() and fscanf() operations.

So far we have seen many programs. This is not enough if we need to write characters, strings, and integers in one single file, in that case, we use fprintf() function. The fprintf() function is used to write set of characters into the file. It sends formatted output to a stream.
The fscanf() function is similar to scanf() function except for the first argument which is a file pointer that specifies the file to be read.

C Programming Code:

#include<stdio.h>

struct emp
{
   char name[10];
   int age;
};

void main()
{
   struct emp e;
   FILE *p,*q;
   p = fopen(“one.txt”, “a”);
   q = fopen(“one.txt”, “r”);
   printf(“Enter Name and Age:”);
   scanf(“%s %d”, e.name, &e.age);
   fprintf(p,”%s %d”, e.name, e.age);
   fclose(p);
   do
   {
       fscanf(q,”%s %d”, e.name, e.age);
       printf(“%s %d”, e.name, e.age);
   }
   while(!feof(q));
}

LED Interfacing with 8051 Microcontroller with Circuit Diagram Tutorial

LED INTERFACING WITH  8051 MICROCONTROLLER:

INTRODUCTION:

LED is a light emitting diode.It is used for lighting purposes in many electronic devices.

8051 Development board:

EXPLANATION:

  • Here on the development board  we can see 8 LEDS meant for interfacing with the 8051 microcontroller family.
  • The steps involved in this project are as follows:-
  1. Compiling source code on Keil using C language.
  2. Programming the microchip using debugger.
  3. Interfacing the chip with LED through 8051 development board.
  4. Creating the schematic capture simulation diagram using Proteus software.
  5. Verifying the simulation and thereby compiling the schematic after verification is done.

VIDEO OF LED TOGGLING:-

SOURCE CODE:

#include<reg51.h>

sbit LED=P1^0;

void toggle(void);

void delay(int a);

int main(void)

{

toggle();

while(1)

{

  LED=0;

  delay(50000);

  LED=1;

  delay(50000);

}

}

void toggle(void)

{

P2=0x00;

}

void delay(int b)

{

int i;

for(i=0;i<b;i++);

}

CIRCUIT WORKING:

  • Here in this circuit I have toggled the second LED (left to right from port 0) by the interfacing the 8051 microcontroller using the PORT 1 of the microcontroller.
  • Initially the Reset pin (9th pin of 8051 chip) is connected to the 5V pin before connecting the 9V Power supply.
  • After 5V passes through circuit then the RESET  pin is connected to ground.
  • A wire connection is given from the P2.0 of port 2 (single bit) to the second LED .
  • The LED starts to glow white.
  • The value of 50,000 USING Keil generates around 1s between on and off time. This is for the crystal oscillator of frequency 11.0592 Mhz.

PROTEUS SCHEMATIC:

C Program to Sort N Names in Alphabetical Order

Write a C program to sort N names in alphabetical order.

In the following C program user would be asked to enter a set of N names and the program would sort and display them in ascending alphabetical order.Learn How To Sort Names in Alphabetical Order in C Programming Language. The program is successfully compiled and tested

C Programming Code

 #include <stdio.h>

  #include <string.h>

  void main()

  {

      char name[10][8], tname[10][8], temp[8];

      int i, j, n;

      printf(“Enter the value of n \n”);

      scanf(“%d”, &n);

      printf(“Enter %d names n”, \n);

      for (i = 0; i < n; i++)

      {

          scanf(“%s”, name[i]);

          strcpy(tname[i], name[i]);

      }

      for (i = 0; i < n – 1 ; i++)

      {

          for (j = i + 1; j < n; j++)

          {

              if (strcmp(name[i], name[j]) > 0)

              {

                  strcpy(temp, name[i]);

                  strcpy(name[i], name[j]);

                  strcpy(name[j], temp);

              }

          }

      }

      printf(“\n—————————————-\n”);

      printf(“Input NamestSorted names\n”);

      printf(“——————————————\n”);

      for (i = 0; i < n; i++)

      {

          printf(“%s\t\t%s\n”, tname[i], name[i]);

      }

      printf(“——————————————\n”);

  }

 

Climate Control in Green House Using Intelligent Control Monitoring System

CONTROLLING GREENHOUSE USING INTELLIGENT CONTROL  MONITORING SYSTEM

INTRODUCTION:

  • The sole purpose of this project is to protect the nurturing plants and additional system of control is employed to conserve energy as it is the vital source for power.
  • This intelligent contraption involves the combination of sensors and microcontrollers.
  • Specific agricultural plants require specific amount of humidity, hence the application of humidity sensor is found here since it’s a big hassle for the farmers to accurately measure from the soil.

DIGITAL SENSOR:

Light sensor:

  • It is a type of resistance that can be varied.
  • Then a specific intensity of light falls on the microcontroller the controller activates the sensor and after some time it turns off.
  • This controller facilitates automatic switching of lights in order to save energy.
  • PIC16F887A is the microcontroller used in this project.

HUMIDITY SENSOR:

  • This is employed in agricultural farms since both low levels or high levels can prove detrimental to the life expectancy of the crops sown by our hardworking farmers.
  • HS1101 is an unique type of humidity sensor.
  • If the humidity in air exceeds a specific value then the microcontroller gives signal to the relay.
  • The frequency so measured is calculated  using some preallocated algorithm within the microcontroller.

MOISTURE SENSOR:

  • It is used to measure the moisture present in the soil.
  • For thism, a wire strip is inserted into the soil.
  • The way it works is like whenever the moisture content is less, the resistance of the strip goes high and vice versa.
  • Therefore the PIC16F877A is used to control the functioning of water pump using the moisture sensor.

APPLICATIONS:

  1. Wireless sensor can be incorporated along with this  circuit in order to inform the values and measurements. user who is not at a remote location.
  2. In absolutely any existing greenhouse for employing self automated control of devices.

 

C Program to Sort N Names in Alphabetical Order.

Write a C program to sort N names in alphabetical order.

Learn how to sort names in alphabetical order in c programming language. This C Program To Arrange Names in Ascending Order. In the following C Program, the user would be asked to enter some names as input & then sorts them in an alphabetical order.

C Programming Code

#include <stdio.h>                                                                                  

  #include <string.h>

  void main()

  {

      char name[10][8], tname[10][8], temp[8];

      int i, j, n;

      printf(“Enter the value of n \n”);

      scanf(“%d”, &n);

      printf(“Enter %d names n”, \n);

      for (i = 0; i < n; i++)

      {

          scanf(“%s”, name[i]);

          strcpy(tname[i], name[i]);

      }

      for (i = 0; i < n – 1 ; i++)

      {

          for (j = i + 1; j < n; j++)

          {

              if (strcmp(name[i], name[j]) > 0)

              {

                  strcpy(temp, name[i]);

                  strcpy(name[i], name[j]);

                  strcpy(name[j], temp);

              }

          }

      }

      printf(“\n—————————————-\n”);

      printf(“Input NamestSorted names\n”);

      printf(“——————————————\n”);

      for (i = 0; i < n; i++)

      {

          printf(“%s\t\t%s\n”, tname[i], name[i]);

      }

      printf(“——————————————\n”);

  }

What is PIC Microcontroller ? PIC Microcontroller Architecture, Working and Application

PIC MICROCONTROLLERS

INTRODUCTION:

  • It is created by microchip technology which originated from the PIC160.
  • The early versions of PIC had only a Read only memory and Erasable Programmable Read only memory.
  • The abbreviation originally stood  for Peripheral interface controller but was later changed to Programmable intelligent computers.
  • These PICS were introduced in 1975 for the sole purpose of off-loading Input/Output tasks from the CPU in order to enhance the efficiency of the processor.

FEATURES:

 

  • Low cost.
  • Wide availability.
  • Different communication protocols are compatible such as:-

 

 

1.CAN

2.I2C

3.UART(Universal Asynchronous Receiver transmitter)

4.USB(UNIVERSAL SERIAL BUS)

CORE ARCHITECTURE:
  • Harvard architecture is employed here in this family.
COMPONENTS:

 

1.) DRAM(DATA MEMORY):

  • The PIC family comprises of a special registers that function as general purpose RAM.
  • These devices are employed with have banking mechanisms in order to extend memory.
  • An important point to note is that the external memory is not addressable.

   2.) CODESPACE:

  • There exists no facilities for the provision of external memory in the absence of such module.
  • Therefore usually the memory storage takes place on the following:-
    • ROM
    • PROM
    • EPROM

Exceptions: – PIC18  and PIC17.

   3.) WORD SIZE:

  • Program memory is usually implemented in single word instructions instead of bytes.
  • The addresses are handled in 8-bit format by these PIC microcontroller.
  • PIC 12 and PIC 16 have addresses of the same size as the instruction width size.
  • PIC 18 has address memory size as 8-bit increments which differs from instruction width of 16 bits.

    4.) STACKS:

  • Generally the PIC devices had a hardware module known as cell stack for the sole purpose of  storing return addresses.
  • The stacks present in the earlier versions was not accessible for software editing.
  • However the latest one PIC 18 has enabled software editing for the stack hardware module.

    5.) INSTRUCTION SET

  • Te Programmable intelligent controllers(low end ) has 35 bit instructions.
  • Whereas the high end one’s have over 80 instruction sets.
ADVANTAGES:-
  1. Reduced instruction set(RISC).
  2. Internally embedded oscillator with tunable speeds.
  3. Inexpensive microcontrollers.
  4. The wide availability of Dual inline Packages which makes it convenient for usage
LIMITATIONS:
  • Unfortunately only a single accumulator is available.
  • Operations and registers are not repetitive implying that sometimes single.
  • The cell stacks that are software programmed  will not be that efficient for addressing memory.

PAGED PROGRAM MEMORY:

  • We have two separate page memories pose a problem.
  • One is known s CALL whereas the other one is called GOTO(usually implemented in lookup tables)
  • They both comprise of 11 addressing bits so the page is 2048 instruction words.

BOOTLOADING:

  • Most of the modern flash based PIC’s can self-program itself.However there exists an alternative solution for programming.
  • The bootloader firmware enables the user to load on the PIC microchip using  The Inline serial port in conjunction with specific program software.

ADVANTAGES OF BOOTLOADER:

  • Quicker programming when compared to ICSP programming.
  • On the spot execution along with programming.
  • Programming and debugging can both be done using the same cable.

HARDWARE FEATURES:

1.EEPROM

2.Flash features

3.Watchdog timer

4.Sleeping modee

5.Various oscillator crystal configurations.

DEVICE PROGRAMMERS:

  • These devices are used to feed the program coding into the PIC chip.
  • Some of the famous programmers/ debuggers are:-
  1. MPLAB ICE
  2. MPLAB ICD4

In circuit emulators:

  • MPLABICE2000 is an example of a  full circuit emulators.
  • These tools are used in conjunction with the debuggers previously mentioned above for source level of target code.

PERFORMANCE:

  • Speed to cost ratio maximized here.
  • The  latency of interrupts is constant at three instruction cycles.
  • Timing and the design of microcircuit are efficiently saved.
  • The peculiar feature is that by default all the internal interrupts are already synchronized whereas the external interrupts have to be produced simultaneously with the four input clock cycles.

APPLICATIONS:

In most modern devices such as:-

  1. Mobile phones
  2. Vehicle systems
  3. Aerospace mechanisms

C Program to Merge two Sorted Array

Write a C Program to Merge the Elements of 2 Sorted Array.

This C Program teach you how to merge the elements of 2 sorted array.

C Programming Code

 #include <stdio.h>

  void main()

  {

      int array1[50], array2[50], array3[100], m, n, i, j, k = 0;

      printf(“\n Enter size of array Array 1: “);

      scanf(“%d”, &m);

      printf(“\n Enter sorted elements of array 1: \n”);

      for (i = 0; i < m; i++)

      {

          scanf(“%d”, &array1[i]);

      }

      printf(“\n Enter size of array 2: “);

      scanf(“%d”, &n);

      printf(“\n Enter sorted elements of array 2: \n”);

      for (i = 0; i < n; i++)

      {

          scanf(“%d”, &array2[i]);

      }

      i = 0;

      j = 0;

      while (i < m && j < n)

      {

          if (array1[i] < array2[j])

          {

              array3[k] = array1[i];

              i++;

          }

          else

          {

              array3[k] = array2[j];

              j++;

          }

          k++;

      }

      if (i >= m)

      {

          while (j < n)

          {

              array3[k] = array2[j];

              j++;

              k++;

          }

      }

      if (j >= n)

      {

          while (i < m)

          {

              array3[k] = array1[i];

              i++;

              k++;

          }

      }

      printf(“\n After merging: \n”);

      for (i = 0; i < m + n; i++)

      {

          printf(“\n%d”, array3[i]);

      }

  }

Logic

  1. Create two arrays of fixed size and define their elements in sorted fashion.
  2. Take any two variables say i and j for the 0th position of these two arrays.
  3. Then the elements will be compared one by one using i and j in for loop, and whichever element is smaller than the other, that element will get inserted to final array will move by one, whereas the other array’s track position will remain in that same place.
  4. Above work will be done till we reach the end of either array. After that, one of the arrays whose elements are still to be added, its elements will get straightaway added to the final array.

Fingerprint Detection Using Microcontroller

Detecting Human Fingerprint Using AVR  Microcontroller

INTRODUCTION:

  • In the modernized world that we are living in, security plays a crucial role in identifying each individual.

Biometric fingerprint scanning is one of the most reliable security techniques and widely popular in companies.

  • Here we place any of our desired finger for a period of one second so that the image is recorded on the sensor.
  • This created finger impression is compared with the stored fingerprint collection within the security database.
  • Hence a match is initiated and  produced if existing in database.
  • After the corresponding match is detected precisely then the details of the individual with that fingerprint emerges onto screen.

Necessary Components:

  1. Fingerprint scanner module device.
  2. 16×2 alphanumeric LCD display.
  3. ATMega16 microcontroller board
STEPS INVOLVED IN FINGER SCANNING:

These are the following steps involved in fingerprint scanning:-

  1. Recording image of finger impression.
  2. Producing a character file from the recorded image
  3. Creating corresponding template for the character file.
  4. Storage of this template in database(flash memory)
  5. Searching finger library.

WORKING OF SCANNING MODULE:

  1. Initially when the device is powered on that is for about half a second, It is in an inactive state, it cannot accept any commands.
  2. A memory size of 512 bytes is allocated to the user when the data for power-protection can be stored.
  3. There exists two separate buffers for storing character and template files.
  4. The communication employed here is half duplex asynchronous serial communication
  5. The Baud rate is initially set to 57600 kbps which can be alternated from 9600 to 115200 bps.

ENROLLING:

  • The use has to enroll the fingerprint twice.
  • The device record both the instance of finger impressions.
  • Flash templates can extend upto N numbers.
  • Usually around 1000 flash templates are used.
  • The Liquid Crystal Display is connected to PORTB of the microcontroller.(Works under 4 bit mode).
  • The light emitting diodes are connected to PORTC of the microcontroller.
  • For a ratio of 1:1 matching the input fingerprint impression is compared with a specific module in template.
  • Otherwise if the ratio needed is 1:N the input is matched with the entire flash templates.

COMMUNICATION PROTOCOL USED:

  • This module uses UART protocol to transmit and receive data with the aid of Tx and Rx pins of microcontroller ATMega16.

1.) ADDER:

  • The primary default value is 0xFFFFFFFF which can be altered later on.

2.) HEADER:

  • Here a constant hexadecimal value 0xEF01 is used.

3.) PACKAGE LENGTH:-

  • This denotes the maximum size of package.The size of checksum is 2 bytes and maximum length is 256 bytes.

4.) PACKAGE CONTENTS

  • Can comprise of the following:-
  1. Data
  2. Commands
  3. Acknowledge signal
  4. Parameters for command signals

5.) CHECKSUM:

  • It is the sum total of package contents, package identifier and package length.
  • The bits that overflow are ignored.

6.) PACKAGE IDENTIFIER:

  • The size it occupies is 1 byte.
  • The memory address for command data packet  is 01H
  • For acknowledge data packet memory address is 07H.

Fig 2. Command Package

APPLICATIONS:

  1. Used for  biometric attendance.
  2. In security gates for high level personnels(VIP).

En-Query

Your Name*
Subject*
Phone Number*
Email Address*

Message*