Sunday, July 8, 2018

40V DC Voltmeter using PIC16F877a

As we all are playing with electronics and micro controller, we all know what is voltmeter. It is a meter which is used to measure volt. Today we will make a voltmeter using PIC16F877a. But the voltage measure limit is 40V. One important thing is micro controller can not tolerate more than 5V in it's input pin. So what we will do? We will make a voltage divider circuit, so that input pin's voltage doesn't exceed 5V. 

To do this we need following software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2

MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language for programming. Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F877a  IC. 

To do this project we need following components;

   1. PIC16F877a
   2. Resistor 18k and 2.2K
   3. 20 MHz Crystal Oscillator
   4. Breadboard
   5. Wires
   6. 5V DC Power source
   7. Soil Moisture Sensor
   8. 16*2 LCD
   9. header for connecting LCD
 10. 10K potentiometer


CODE

sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;

unsigned int k,j,i;
char *l,*m,n[7],o[7];

void main()
{

    int t;
    ADCON1=0x04;
    PORTA = 0;
    TRISA = 0X01;
    PORTB = 0x00;
    TRISB = 0x00;

    LCD_Init();
    ADC_Init();
    LCD_Cmd(_LCD_CURSOR_OFF);
    LCD_Cmd(_LCD_CLEAR);
    LCD_Out(1,1, "   ABDUR ROUF  ");
    LCD_Out(2,1, "   VOLTMETER   ");
    delay_ms(2000);
    LCD_Cmd(_LCD_CLEAR);

       while (1)
        {
            t=ADC_Read(0);
            k = t;
            k =k*0.458;                            //k*0.458;
            j = k/10;
            i =k%10;
            inttostr(j,o);
            inttostr(i,n);
            l =ltrim(o);
            m =ltrim(n);
           
            if(j<=9)
            {
            lcd_out(1,1,"***Voltmeter***");
            lcd_out(2,1,"Volt:");
            lcd_out(2,8,l);
            lcd_out(2,9,".");
            lcd_out(2,10,m);
            lcd_out(2,12,"V");
            }
           
            else
            {
            lcd_out(1,1,"***Voltmeter***");
            lcd_out(2,1,"Volt:");
            lcd_out(2,7,l);
            lcd_out(2,9,".");
            lcd_out(2,10,m);
            lcd_out(2,12,"V");
           
            }
           
        }
}


Schematic


Schematic 1




Schematic 2




Schematic 3



Saturday, July 7, 2018

Automatic Irrigation System Using Soil Moisture Sensor and PIC16F887



In this project we will interface soil moisture sensor with PIC16F887. The micro controller PIC16F887 is a  very popular micro controller in PIC16 series. The sensor can detect if the soil is humid or not. If the soil is dry, then micro controller will turn on the motor to give water in the soil. When There is enough water in the soil, that means the soil is not dry, we will turn off the motor. We will also use a lcd and a led to indicate that motor is on or off. For driving the motor we will use L293D motor driver. This L293D is a dual channel motor drive. Here we will only use 1 channel, because we will run only on motor. The current limit for L293D is 1A. So, choose a motor which doesn't require more 500mA - 700mA current. We will use small motor to demonstrate the process. 



PIC16F887 Pin Diagram


Soil Moisture Sensor


To do this we need following software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2


MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language for programming. Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F887  IC. 

To do this project we need following components;


   1. PIC16F887
   2. LED
   3. 16 MHz Crystal Oscillator
   4. Breadboard
   5. Wires
   6. 5V DC Power source
   7. Soil Moisture Sensor
   8. 16*2 LCD
   9. L293D Motor Driver
  10. DC motor
  11. 470 ohm resistor
  12. Header for connect LCD
  13. 10K potentiometer

CODE

 sbit LCD_RS at RD0_bit;
 sbit LCD_EN at RD1_bit;
 sbit LCD_D4 at RD2_bit;
 sbit LCD_D5 at RD3_bit;
 sbit LCD_D6 at RD4_bit;
 sbit LCD_D7 at RD5_bit;
 sbit LCD_RS_Direction at TRISD0_bit;
 sbit LCD_EN_Direction at TRISD1_bit;
 sbit LCD_D4_Direction at TRISD2_bit;
 sbit LCD_D5_Direction at TRISD3_bit;
 sbit LCD_D6_Direction at TRISD4_bit;
 sbit LCD_D7_Direction at TRISD5_bit;
 // End LCD module connections

 double source=0;
 double temp=0;
 int view=0;
 char txt[6];

 void main()

 {

  TRISC = 0x00;
  PORTC = 0x00;
  ADC_Init();                   // Initialize ADC
  Lcd_Init();                   // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);          // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);     // Cursor off
                                // clear LCD

  Lcd_Out(1, 1, "     EEE 332    ");
  Lcd_Out(2, 1, "    ABDUR ROUF  ");
  delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1, 1, "  SOIL MOISTURE ");
  Lcd_Out(2, 1, " MICROCONTROLLER");
  delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);          // Clear display
                                //  char code for degree
                                // Display "C" for Celsius
  while(1)
  {
        source=Adc_Read(1);
     
        if(source>600)
        {
          PORTC = 0b11111101;                  //motor on
          delay_ms(500);
          Lcd_Cmd(_LCD_CLEAR);
          Lcd_Out(1,5, "Dry Soil");
          Lcd_Out(2,5, "Motor On");
        }
     
        if(source<=600)
        {
          PORTC = 0b00000000;
          delay_ms(500);                  //motor on
          Lcd_Cmd(_LCD_CLEAR);
          Lcd_Out(1,5, "Humid Soil");
          Lcd_Out(2,5, "Motor OFF");
        }
     }

 }


Schematic



Schematic 1




Schematic 2




Schematic 3



Gas Leakage Detection System Using PIC18F452



In this project we will interface MQ2 gas leakage detector with PIC18F452. MQ2 is suitable for detecting H2, LPG, CH4, CO, Alcohol, Smoke or Propane. PIC18F452 is a popular micro controller in PIC18 series. If this sensor can sense a gas leakage then the buzzer will beep and if there is no gas leakage then buzzer won't beep. Also a LED will turn on and off, if gas leakage is detected. Also we will have a lcd to show that if the alarm is on or not. 


MQ 2 Gas Sensor




PIC18F452 Pin Diagram



To do this we need following software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2

MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language for programming. Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC18F452  IC. 

To do this project we need following components;


   1. PIC18F452
   2. LED
   3. 16 MHz Crystal Oscillator
   4. Breadboard
   5. Wires
   6. 5V DC Power source
   7. MQ2 Gas Sensor
   8. 16*2 LCD
   9. BC547 
  10. Buzzer
  11. 150 ohm and 470 ohm resistor
  12. Header for connect LCD
  13. 10K potentiometer


CODE


// 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 main()
{
      unsigned int input = 0;
      TRISD = 0;                  // output register
      PORTD = 0;                  // output port

      ADCON1 =0x0E;               // Analog to digital converter turning on

      Lcd_Init();
      Lcd_Cmd(_LCD_CURSOR_OFF);

      Lcd_Cmd(_LCD_CLEAR);
      Lcd_out(1,1, " EEE 332 PROJECT");
      delay_ms(100);
      Lcd_out(2,1, "Micro Controller");
      delay_ms(1000);
      Lcd_Cmd(_LCD_CLEAR);
      delay_ms(200);

      Lcd_Cmd(_LCD_CLEAR);
      Lcd_out(1,1, "   GAS LEKEAGE  ");
      delay_ms(100);
      Lcd_out(2,1, "DETECTION SYSTEM");
      delay_ms(1000);
      Lcd_Cmd(_LCD_CLEAR);
      delay_ms(200);

      Lcd_Cmd(_LCD_CLEAR);
      Lcd_out(1,1, "  DEVELOPED BY  ");
      delay_ms(100);
      Lcd_out(2,1, "   ABDUR ROUF   ");
      delay_ms(1000);
      Lcd_Cmd(_LCD_CLEAR);
      delay_ms(200);



      while(1)
      {

         input = ADC_read(0);           // Reading the ADC value from PORT A0

               if(input>=400)
         {

            PORTD = 0b11111111;         // Turning on LED on PORTB
            delay_ms(250);
            PORTD = 0b00000000;         // Turning off LED on PORTB
            delay_ms(250);
            Lcd_Cmd(_LCD_CLEAR);
            Lcd_out(1,1, "   GAS LEKEAGE  ");
            Lcd_out(2,1, "    DETECTED    ");
            delay_ms(1000);             // Turning on LED for 5 seconds

         }
               else
         {
            PORTD = 0b00000000;         // Turning off LED
            delay_ms(500);              // Turning off LED for 5 seconds
            Lcd_Cmd(_LCD_CLEAR);
            Lcd_out(1,1, "    ALARM OFF    ");
            Lcd_out(2,1, "  NO GAS LEAKAGE ");
      }
}

}



Schematic


Schematic 1


Schematic 2



Schematic 3



Schematic 4


Monday, May 14, 2018

LDR Based Automatic Light with PIC16F90



Hello, today I will do an interesting project which is LDR Based Automatic Light with PIC16F690. This is a simple project using LDR and PIC16F90. This PIC16F690 is a very popular microcontroller. PIC16f690 micro controller has 3 port. These are PORT A, PORTB, and PORTC. Each port has some specific purpose. 

The purpose of this project is to make an automatic light with the help of LDR and microcontroller. If there is sunlight or light from other sources then systems light will be turned off and if there is no sunlight or other source of light then systems light will be turned on. For sensor will will use LDR. 

LDR is basically a photoresistor or  light dependent resistor. This is a light controlled variable resistor. The resistance of a LDR decreases with increasing incident light intensity and the resistance of a LDR increases with increasing incident of light intensity.



Figure 1: Light Dependent Resistor


To do this we need following software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2

MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language.
Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F690  IC.



To do this project we need following components;


   1. PIC16F690
   2. LED
   3. 16 MHz Crystal Oscillator
   4. Breadboard
   5. Wires

   6. 5V DC Power source
   7. 5V Relay Module
   8. LDR


CODE

void main()
{
      unsigned int input = 0;
      TRISC = 0;                             // output register
      PORTC = 0;                           // output port

      ADCON1 =0x0E;                  // Analog to digital converter turning on

      while(1)
      {

         input = ADC_read(0);         // Reading the ADC value from PORT A0

         if(input<=500)                     // 500 is corresponding value of LDR
         {
            PORTC = 0b01111111;     // Turning on LED on PORTC
            delay_ms(1000);               // Turning on LED for 1 seconds

         }

         else
         {
            PORTC = 0b00000000;   // Turning off LED
         }

      }
}


SCHEMATIC





Figure 2: Schematic


Figure 3: Schematic



Monday, April 30, 2018

LED Flashing with PIC16F877



Hello, today I will do very simple project using PIC16F877. This is a basic project for begginer.
PIC16F877 is a very popular microcontroller. Those who are new with PIC micro controller, this project will demonstrate that how to make a specific pin of a port make high or low. PIC16f877 micro controller has 5 port. These are PORT A, PORTB, PORTC, PORTD and PORTE. Each port has some specific purpose. May be in other post we will discuss about this. To do this we need following software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2



MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language.

Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F887  IC.



To do this project we need following components;


   1. PIC16F877

   2. LED
   3. 16 MHz Crystal Oscillator
   4. Breadboard
   5. Wires
   6. 5V DC Power source

In the following figure we have the pinout of PIC16F877



Figure 1

MikroC Code:


// LED Flashing

void main() 

{
   TRISB = 0;
   PORTB = 0;
   ADCON1= 0x06;
   
   while(1)
   {
   
      PORTB = 0b00000001;
      delay_ms(200);
      
      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00000010;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00000100;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00001000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00010000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b00100000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b01000000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b10000000;
      delay_ms(200);

      PORTB = 0b00000000;
      delay_ms(200);
      
      PORTB = 0b10101010;
      delay_ms(1000);

      PORTB = 0b00000000;
      delay_ms(500);
      
      PORTB = 0b01010101;
      delay_ms(1000);

      PORTB = 0b00000000;
      delay_ms(500);
      
      PORTB = 0b11111111;
      delay_ms(1000);

      PORTB = 0b00000000;
      delay_ms(500);
   
   }
}

Diagram




Figure 2

Please don't forget to connect pin 1,11 and 32 to 5V source.
Connect pin 12 and 31 with Gnd. Also connect 16 MHz oscillator with pin 13 and 14.

THANKS A LOT.

Interfacing 16*2 LCD with PIC16f877



Today I will interface 16*2 LCD with PIC16F877. This is a very popular microcontroller. In this tutorial we will use the following Software:

   1. MikroC pro for PIC (student verison)
   2. Proteus 8 professional
   3. PicKit 2

MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language.
Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F877  IC.

 16*2 LCD has 16 columns and 2 rows. To do this project we need following components: 

  1. PIC16F877
  2. 16*2 LCD
  3. 5V power source
  4. 16 MHz Crystal Oscillator
  5. Male header (to solder with LCD)
  6. 10K potentiometer (To control the brightness of the LCD)
  7. Breadboard
  8. Wires

LCD has 16 pins. We can transfer the data from microcontroller to LCD in 8 bits mode or in 4 bit modes. In this project we will transfer the data in 4 bit modes. In below I have given the pin out of 16*2 LCD.

  Pin 1  : GND
  Pin 2  : VCC
  Pin 3  : VEE
  Pin 4  : RS
  Pin 5  : R/W
  Pin 6  : EN
  Pin 7  : DB0
  Pin 8  : DB1
  Pin 9  : DB2 
  Pin 10: DB3
  Pin 11: DB4
  Pin 12: DB5
  Pin 13: DB6
  Pin 14: DB7
  Pin 15: Led +
  Pin 16: Led -


Figure 1

MikroC has some built in library to print the string in the LCD. In this code part we will demonstrate how to print something on the LCD. Following code will demonstrate how to print something on the LCD.

/*
Project Name: Showing name on LCD using PIC16F877
*/
// LCD connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;


sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End LCD connections


void main()
{
   Lcd_Init();                            // Initialize LCD
   Lcd_Cmd(_LCD_CLEAR);                   // Clear display
   Lcd_Cmd(_LCD_CURSOR_OFF);              // Cursor off
   Lcd_Out(1,1,"  Hello WORLD   ");
   Lcd_Out(2,1," ARTECH-AHAMOD  ");
}


I have written another code which will scroll the lcd from left to right and again scroll from right to left. The code is given below:


/* 
Project Name: Showing name on LCD using PIC16F877
*/
// LCD connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;


sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End LCD connections

 unsigned int i;

void main()
{
   Lcd_Init();                            // Initialize LCD
   Lcd_Cmd(_LCD_CLEAR);                   // Clear display
   Lcd_Cmd(_LCD_CURSOR_OFF);              // Cursor off
   Lcd_Out(1,1,"  Hello WORLD   ");
   Lcd_Out(2,1," ARTECH-AHAMOD  ");
   delay_ms(3000);
   
   while(1) 
   {                                      // Endless loop
    for(i=0; i<8; i++) 
    {                                     // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      delay_ms(500);
    }

    for(i=0; i<8; i++) 
    {                                     // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      delay_ms(500);
    }
    
    delay_ms(2000);
  }
}


Circuit diagram is given below:


Figure 2



Figure 3

Please don't forget to connect pin 1,11 and 32 to 5V source.
Connect pin 12 and 31 with Gnd. Also connect 16 MHz oscillator with pin 13 and 14.

Pin 15 and pin 16 are backlight power of the LCD. Connect pin 15 with 5V and connect pin 16 with Gnd.
THANKS A LOT.

Line Follower Robot using Arduino

This project was a part of Line Follower Robot Competition