mercredi 6 avril 2016

IR Led using PIc 16f877


In this post I am going to show you how to use and program IR LED with too pic 16f877a

IR LED:

IR LED means Infrared Light Emitting Diode. The IR LED emits Infrared light which is not visible to human eye. we can find these IR LED's in our TV Remotes. IR LED's works like normal LED's but the material used in the core is different, it emits Infrared Light when current passed through it.


Photodiode:

Photodiode is a light sensitive semi-conductor diode which converts the light energy into voltage or current based on the mode of operation. In general Photodiodes are operated in reverse bias condition. The clear Photodiode can detect visible and IR rays to limit the Photodiode to detect only IR rays a black cotting is applied to the glass of the Photodiode. The photodiode allows the current to pass through it if the photodiode is exposed to IR rays and it doesn't allow current to pass through it if no IR rays falls on it. The amount of current passed through the photodiode is directly proportional to amount of IR rays falls on it.



Materials required:

1) 2*Pic      16f877a              
2) IR LED   
                   
3) 3*Button                     
4) 4*Capacitor 22p
5) 2*Quartz 4 MHZ
6) Led Red
7)3*Resistance 220hom

Circuit diagram:



Program :

EM:


#include<16F877A.h>
#device adc=10
#fuses HS
#use delay (clock=8M)
#byte portb=6
#byte trisb=0X86
#bit bouton1=portb.0

 void main()
  {
   port_b_pullups(true);
   setup_timer_2(T2_div_by_1,52,1);//pwm period=Tosc*4*mode*(periode+1)=0,125*4*1x=26,3 us
   //0,5x=26,3
   //x=26,3:0,5=53
    set_pwm1_duty(48);
   
    while(true)
     {if(bouton1==0)
         {
          setup_ccp1(ccp_pwm);
          delay_ms(100);
          setup_ccp1(ccp_off);
          delay_ms(100);
          }
     }
  }

RE

#include<16F877A.h>
#device adc=10
#fuses HS
#use delay (clock=8M)
#byte portb=6
#byte trisb=0X86
#bit bouton1=portb.0
#byte portd=8
#byte trisd=0x88
#bit led=portd.0
#bit data=portb.0

int1 i;
 void main()
  {
   port_b_pullups(true);
      trisb=0Xff;
      i=0;
      trisd=0X00;
      portd=0;
      while(true) //recepteur
       {
        if(data==0)
          {
           //delay_ms(200);
           if(data==0)
               {
                delay_ms(51);
                 if(data==0)
                    {i++;
                    
                     if (i==1)
                      led=1;
                       else
                       { led=0;}
                    }    
                   
          
                 }
           }
  
        }
  }

 Video :























Continue Reading...

dimanche 27 mars 2016

Digital Ammeter circuit using pic microcontroller 16f877A




In this project i will expalin  :

  • how to measure dc current. using 16f877  microcontroller  
  •  how to convert current into voltage from using shunt resistor?
  •  how to design low resistance shunt resistor using simple wire?
  •  How to display current value on LCD?

Circuit Diagram :

   In this circuit diagram, 24 volt dc source is applied to 40ohm load 
   Current passing through this load is measured with the help of shunt resistor 
  Now the question is why we need shunt resistor to measure current?




Shunt resistor value is known and voltage is measured with pic microcontroller. So current can be easily calculated by using above Ohm’s law formula.


                                   I = V/R




1N4733A zener diode is used to protect microcontroller from over voltage appearing across it. Because voltage more than 5 volt may damage microcontroller permanently







PROGRAM:




Complete code of digital Ammeter circuit using pic microcontroller is given below. In this code TRISA is used to define port A as input because voltage is measured with pin number AN0 of port A. TRISB instructions defines PORTB as an output PORT. It is used to send data to LCD.  LCD_Init() funtion initialize LCD libraries and ADC_Init() initialized ADC libraries functions.



""cur = read_adc();"" statement used to read voltage across shunt resistor and ""cur=(cur*4.89)/0.50 ; ""statement converts voltage back into current according to ohms law formula. Rest all the lines in below given code is self explanatory, but if you still need any help. You are welcome to comment on this post




Vidéo : 












Continue Reading...

mardi 23 février 2016

voice command using PIC 16f877A






voice command using  PIC 16f877A  using PIC 16f877







Continue Reading...

vendredi 5 février 2016

Interfacing 7 Segment Display ccs and 16f877a






OBJECTIVE:

    • 7seg display
    • common anode
    • common cathode
    • Interception









COMPONENTS:

  • 1 7seg display common anode
  • 1 7seg display common cathode
  • 2 cap 22p
  • 1 quartz
  • 2 button
  • 2 resistance 220 hom




Discription:

1.The Common Cathode (CC) – In the common cathode display, all the cathode connections of the LED segments are joined together to logic “0” or ground. The individual segments are illuminated by application of a “HIGH”, or logic “1” signal via a current limiting resistor to forward bias the individual Anode terminals (a-g).


2. The Common Anode (CA) – In the common anode display, all the anode connections of the LED segments are joined together to logic “1”. The individual segments are illuminated by applying a ground, logic “0” or “LOW” signal via a suitable current limiting resistor to the Cathode of the particular segment (a-g).


Segment Display Segments for all Numbers.


7-segment Display Truth Table


CIRCUIT DIAGRAM:




CODE in this Video ;
























Continue Reading...

dimanche 31 janvier 2016

PWM Mode Using PIC16F877A microcontroller


 


OBJECTIVE:


  • speed variation
  • Digital display of Potentiometre 
  • LCD display(duty cycle %)
  • How to work with function

COMPONENTS:

  • Potentiometre 
  • 2 CAp (22pic)
  • 1 quartz (4MHZ)
  • pic 16F877A
  • Motor
  • L293D
  • LCD 16*2
Definition :

PWM (Pulse Width Modulation) is a method of generating signal shown above.
In short, PWM allows easy control the amount of power provided to external device e.g. motor or LED. When frequency of the signal is changed in time it can be used to generate sound.



motor animated

Led  animated


Discription:

PWM Mode (PWM) In Pulse Width Modulation mode, the CCPx pin produces up to a 10-bit resolution PWM output. Since the CCP1 pin is multiplexed with the PORTC data latch, the TRISC<2> bit must be cleared to make the CCP1 pin an output

A PWM output  has a time base (period) and a time that the output stays high (duty cycle). The frequency of the PWM is the inverse of the period (1/period).






The PWM period is specified by writing to the PR2 register. The PWM period can be calculated using the following formula: 


  Period = [(PR2) + 1] • 4 • TOSC • (TMR2 Prescale Value)

 PWM frequency is defined as 1/[ period]

PWM DUTY CYCLE:


 Duty Cycle =(CCPR1L:CCP1CON<5:4>) • TOSC • (TMR2 Prescale Value)


CIRCUIT DIAGRAM:






Video:



















Continue Reading...

vendredi 29 janvier 2016

Temperature sensor using PIC16F877A microcontroller




Temperature sensor using PIC16F877A microcontroller




OBJECTIVE:

  • Temperature measurement
  • Digital display of temperature
  • used of microcontroller to measure temperature
  • used of microcontroller to Display temperature value on LCD

COMPONENTS:


  • pic 16f877
  • lm35
  • 2 cap (22p)
  • quartz (4 mhz)
  • LCD 16*2

Only 5 volt power supply is required for LM35 and there is no need of extra circuitry to operate it. PIC16F877A micrcontroller is used to read temperature value. 16X2 LCD is used to display temperature value on LCD. Code of this project written in Pic C Compiler .

IMPLEMENTATION:



LM35 temperature sensor converts temperature into its proportional analog voltage value. LM35 is three terminal device.Pin number one and three are for 5 volt voltage supply. Pin two is analog voltage output with respect to temperature value.Relation between measured temperature and analog output voltage is:
                                                              1°C = 10m volt
Hence for every 1 degree increase in temperature there will be a increment of 10m volt in output voltage of LM35 sensor. PIC16F877A microcontroller is used to measure analog voltage value.  PIC16F877A  microcontroller built in ADC (analog to digital converter) is used to measure analog voltage.  PIC16F877A PORTA have seven built in ADC channels. So one can inerface upto seven sensors with this microcontroller very easily.I will post a project on green house system.In green house system project I have used four ADC channels to measure temperature , light, humidity and moisture. Coming back to our digital thermometer, ADC has been used to read analog voltage. After reading ADC value, using voltage and temperature relationship voltage is converted back into temperature. A conversion factor is used to convert voltage back into temperature. All these conversion has been done through programming. LCD is connected to PORTB of  PIC16F877A microcontroller. I will disucss it in programming part. LCD is used to display temperature value.

CIRCUIT DIAGRAM:




NOTE: BEFORE MAKING THIS PROJECT , I RECOMMEND YOU SHOULD LEARN ABOUT LCD INTERFACING WITH MICROCONTROLLER ESPECIALLY HARDWARE PART. BECAUSE I HAVE SEEN MANY STUDENTS STRUGGLING WITH LCD DISPLAY.



CODE:


#include <16F877.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)                                           
#include "LCD.c"                                                                         
//#define use_portb_lcd TRUE  
#define LCD_ENABLE_PIN  PIN_B0                                    ////
#define LCD_RS_PIN      PIN_B1                                    ////
#define LCD_RW_PIN      PIN_B2                                    ////
#define LCD_DATA4       PIN_B4                                    ////
#define LCD_DATA5       PIN_B5                                    ////
#define LCD_DATA6       PIN_B6                                    ////
#define LCD_DATA7       PIN_B7   
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 
float adc_value,temp;
void     main() {                                                                 
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);delay_us(10);
lcd_init();              
while(1){
adc_value = read_adc();            // convert to volts avec précision 0.001V
temp=(float)((adc_value * 5)/1023.0)*100; // calculer 
lcd_gotoxy(1,1); 
printf(lcd_putc,"  Temperature ");   //lcd 
lcd_gotoxy(1,2); 
printf(lcd_putc,"     %2.1f%cC",temp,223);
printf("%2f\n\r",temp ); 
printf("\nsmart tech\n\r" );
}                       
}

Video:
























Continue Reading...

dimanche 24 janvier 2016

Digital Voltmeter Using PIC Microcontroller 16F877A and





Digital Voltmeter Using PIC Microcontroller                             16F877A and


Here I’m explaining the constructional details of digital panel voltmeter using PIC16F877Amicrocontroller. It can measure voltage between 0V to 30V DC.
The program for digital voltmeter using pic microcontrolle is compiled using CCS.



Circuit Schematics of Digital Voltmeter Using PIC Microcontroller


The following figure shows digital voltmeter panel circuit diagram with microchip PIC.


Components Required for Digital Voltmeter Using PIC Microcontroller


  1. PIC16F877A Microcontroller
  2. LCD 16*2
  3. Resistor ( 1KΩ; 9KΩ)
  4. Crystal (20MHz)
  5. Capacitor ( 22PF x2)

Working of Digital Voltmeter Using PIC Microcontroller


  • PIC programming is quite easy if you have a perfect C compiler like Mikro C proMPLAB Hi-tech C etc.
  • PIC16F877A has inbuilt ADC (Analog to Digital Converter) Module, I used ADC to read input voltage value.

Measuring Voltage and Design of Voltage Divider Circuit

  • First of all let I discuss how do we measure voltage? Actually PIC’s ADC can measure 0V to +5V, but here our voltage range is 0V to +100V.
  • Hence we can’t feed the input voltage directly to the controller’s ADC pins. Instead of feeding directly, input voltage is reduced by a combination of voltage divider resistors.
Maximum allowed drop will be 5V.

diviseur de tension


V out = (R1/R1+R2 )  V in 
AN. 

Vout = (1/1+9 ) 12 = 0.12 

Mapping ADC Values to Input Voltage 

  • PIC microcontroller ADC is a 10 bit ADC, that means the output of ADC can be vary from0 to 1023 maximum while input varies from 0 to 5V.
  • That is when the input voltage is +5V then ADC value is 1023, when input voltage is 0V ADC value will be 0.
  • We have to map 0 → 1023 to 0 → 5; it can be done by multiplying ADC value with a 
5-------------->1023
?---------------> ADC val 


voltge = (5* adc val /1023)

I multiply by 10 to display the exact value Battery 

TBAT=voltge *10


program 


#include <16F877A.h>
#device ADC=10
#FUSES HS
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay (clock=4000000)

#define LCD_DATA_PORT getenv("SFR:PORTD")
#include <lcd.c>
int16 tbat;
float test;

 void batrie()
 { 
   set_adc_channel( 1);
   delay_us(20);
   tbat = read_adc();
   test=tbat;
   test=test*0.04887585532746823069403714565;

   lcd_gotoxy(1,1);
   printf(LCD_PUTC, "Tb=%2.1f V",test);
 }
void main()
{  setup_adc_ports( ALL_ANALOG );
   setup_adc(ADC_CLOCK_INTERNAL );
   lcd_init();
   lcd_gotoxy(1,2);
   printf(LCD_PUTC, "Smart_tech naim ");   
 while(true)
    {
      batrie();
  }
}

video  













Continue Reading...