Monday 5 November 2012

WEEK 14

This week is for presenting our project to assessor. My assessor is Miss Fatimah and Sir Razak. Below I attach with the poster for my project.



Monday 29 October 2012

WEEK 13

After completing the circuit and test it with the actual rat, next is to do the casing of the product. Below is the picture of prototype after put into the casing.



TRANSMITTER MODULE


RECEIVER MODULE 


 

Wednesday 24 October 2012

WEEK 12

Testing the Rat Repellent with the actual rat but I choose hamster to test it. It show the reaction of the rat after turn on the Rat Repellent. Below is the result show at the computer. When no detection the screen will appear "No Rat Detected" meanwhile it has a detection the screen appear "Rat Detected". The history of the detection will save on the computer.











Saturday 20 October 2012

WEEK 11

Testing all the circuit with the computer. Below is the video show the testing of the prototype.







Wednesday 10 October 2012

WEEK 10

Install the RS232 USB port to the computer in order to interface between the circuit with the computer. 


                                                                          Cable RS-232



                                            Receiver module unit combine with cable USB

Monday 1 October 2012

WEEK 9

Next, I do the Visual Basic programming. This program is show the detected of the rat and store it as record on your computer. Below is the flow chart of Visual Basic:
  

The program of  Visual Basic:

Dim record_en As Integer
Dim mydata As String
Dim mysave As String

Private Sub Command1_Click()
    Text1.Text = ""
End Sub

Private Sub Command2_Click()

End Sub

Private Sub Form_Load() 'when program open
    record_en = 1
    MSComm1.PortOpen = True
    Open "c:\tikus\record.txt" For Append As #2    'open data file
    Close #2    'close file
End Sub

Private Sub Form_Unload(Cancel As Integer)  'when program close
    MSComm1.PortOpen = False
End Sub

Private Sub MSComm1_OnComm()    'if any data in
    mydata = MSComm1.Input
  
    If mydata = "1" Then
        Label1.Caption = "Rat Detected"
  
        If record_en = 1 Then
            Open "c:\tikus\record.txt" For Append As #2     'open new file
            mysave = "Rat Detected" & "   " & Day(Date) & "-" & Month(Date) & "-" & Year(Date) & "    " & Format(Now, "h:nn:ss")
            Text1.Text = Text1.Text & vbCrLf & mysave
            Print #2, mysave  'save new record
            record_en = 0
            Close #2    'close file
        End If
    Else
        Label1.Caption = "No Rat Detected"
        record_en = 1
    End If

End Sub


Programming for Transmitter:

#include <16f877a .h=".h">  //use pic16f877a
#use delay(clock=20000000) //operating speed 20mhz
#fuses hs,nowdt,protect //default fuse setting
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, parity=N) //rf setting
#define use_portb_lcd TRUE //use portb for lcd
#include   //call lcd.c library

//set pic port address
#byte PORTA=5
#byte PORTB=6 
#byte PORTC=7 
#byte PORTD=8 
#byte PORTE=9 

void main()
{
   int i;

   //set io for each pic pin
   set_tris_a(0b00000000);
   set_tris_b(0b10000000);
   set_tris_c(0b10000000);
   set_tris_d(0b00000000);
   set_tris_e(0b00000000);

   setup_ccp2(CCP_PWM);
   output_high(pin_c4);  //on transmitter

   output_high(pin_e1);  //on green led
   output_high(pin_e0);  //on red led
   output_high(pin_e2);  //on blue led

   setup_timer_2(T2_DIV_BY_16, 149, 1);   //DO, 2097Hz
   set_pwm2_duty(75);                        
   delay_ms(500);             

   setup_timer_2(T2_DIV_BY_16, 133, 1);   //RE, 2350Hz
   set_pwm2_duty(66);                        
   delay_ms(500);                           

   setup_timer_2(T2_DIV_BY_16, 119, 1);   //MI, 2626Hz
   set_pwm2_duty(60);          
   delay_ms(500);             

   setup_timer_2(T2_DIV_BY_4, 31, 1);   //40khz
   set_pwm2_duty(0);    //off output                          
   delay_ms(100);             

   do
   {
      output_high(pin_e2); //on blue led

      if(input(pin_b7)==1) //if motion detected
      {
         set_pwm2_duty(15);   //output 40khz                              

         output_low(pin_e1);  //off green led
         output_high(pin_e0); //on red led

         //send data out
         for(i=0;i<10 br="br" i="i">         {
            putc('(');
            putc('1');
            putc(')');
            delay_ms(10);
         }

         delay_ms(5000);   //wait for 5sec
      }
      else  //if no motion detected
      {
         set_pwm2_duty(0);    //off output                          

         output_high(pin_e1);  //on green led
         output_low(pin_e0);  //off red led

         //send data out
         for(i=0;i<10 br="br" i="i">         {
            putc('(');
            putc('0');
            putc(')');
            delay_ms(10);
         }     
      }

      output_low(pin_e2); //off blue led
      delay_ms(500);             

   }while(1);


}



 Programming For Receiver:

#include <16f877a .h=".h"> //use pic16f877a
#use delay(clock=20000000) //set pic speed 20mhz
#fuses hs,noprotect,nowdt,nolvp  //default setting
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, parity=N) //set serial interfacing

#byte PORTA=5
#byte PORTB=6
#byte PORTC=7
#byte PORTD=8
#byte PORTE=9

int rx_temp1=0;
int rx_temp3=0;
int rcvdata;
int mystat=0;

//receive data from transmitter
#int_rda
void serial_isr()
{
   rx_temp1=getch();
   if(rx_temp1=='(')
   {
      rcvdata=getc();
      rx_temp3=getch();
      if(rx_temp3==')')
      {
         mystat=1;
      }
   }

   rx_temp1=0;
   rx_temp3=0;

}

void main()
{
   set_tris_a(0b00000000);    //set i/o pin for port a
   set_tris_b(0b00000000);    //set i/o pin for port b
   set_tris_c(0b10000000);    //set i/o pin for port c
   set_tris_d(0b00000000);    //set i/o pin for port d
   set_tris_e(0b00000000);    //set i/o pin for port e

   //initialize interrupt
   enable_interrupts(int_rda);
   enable_interrupts(GLOBAL);

   output_high(pin_c5);  //on receiver
   output_high(pin_c0);  //on blue led
   delay_ms(500);
   output_low(pin_c0);   //off blue led
   delay_ms(500);

   do
   {
      //if RF receiver received valid data
      if(mystat==1)
      {
         mystat=0;
         output_high(pin_c0);  //on blue led
         delay_ms(250);
         output_low(pin_c0);   //off blue led
         delay_ms(250);
        
         if(rcvdata=='1')  //if receive 1
         {        
            printf("1");   //send 1 to pc
         }
         if(rcvdata=='0')  //if receive 0
         {        
            printf("0");   //send 0 to pc
         }
      }

   }while(1);
}













Saturday 29 September 2012

WEEK 8

After finish the PCB, I want to do the software programming of my project. I use PIC 16F877A. The programming need to burn on the PIC using PIC Burner. Below is the step how to burn PIC:




1.      Connect PIC programmer to computer via serial port / USB port.
2.      Insert PIC into the programmer socket.
3.      Copy ‘Winpic800’ folder to Desktop.
4.      Look for Winpic800.exe in the folder.

5.      Double click Winpic800.exe to start the program.
 
6.      Select proper PIC name in the top right combo box. 
 
 7. Open the .hex file which you want to download into PIC e.g. if your .c filename is ‘abc.c’, suppose you need to download ‘abc.hex’ into PIC. 
  8. Go to ‘Device’ -> ‘Program All’ to start download program into your PIC.