Thursday, February 4, 2016

Remote controlled cd-rom stepper motor

There are some topics talking about the stepper motor and how to control it using different PIC microcontrollers. In this topic the same cd-rom stepper motor is used with PIC18F4550 microcontroller. The stepper motor here is controlled from IR remote control, this remote control uses RC5 protocol, to understand what I am going to do watch the following video:

Circuit schematic is as the following below:
remote controlled cd rom stepper motor pic18f4550 mikroc code 
From the circuit schematic there is an IR receiver, this IR receiver receives the ir signals transmitted from the remote control. The remote control controls only the rotation direction of the motor using two buttons as shown in the following image, one button has an address = 0 and command = 16 and the other button has address = 0 and command = 17 as shown below.
tv rc5 remote control mikroc

Remote controlled stepper motor mikroC code:
With the help of the stepper motor library which we have discussed before, the drive of the stepper motors becomes very simple with a short code. To add this library to your mikroC Pro for PIC compiler visit the following topic:
MikroC Pro for PIC stepper motor library 

mikroC code:

 * Remote controlled stepper motor using
   PIC18F4550 and RC5 remote control
 * Stepper motor library must be installed
 * Written by: BENCHEROUDA Okba
 * E-mail:
 * Website:
 * Internal oscillator used at 8MHz
 * Use at your own risk
  // Stepper motor module connections
 sbit Stepper_pin1 at RD0_bit;
 sbit Stepper_pin2 at RD1_bit;
 sbit Stepper_pin3 at RD2_bit;
 sbit Stepper_pin4 at RD3_bit;
 sbit Stepper_pin1_Direction at TRISD0_bit;
 sbit Stepper_pin2_Direction at TRISD1_bit;
 sbit Stepper_pin3_Direction at TRISD2_bit;
 sbit Stepper_pin4_Direction at TRISD3_bit;
 // End stepper motor module connections
 bit RC_5 ;
 unsigned short i, address, command;
 void read_signal(){
   bit toggle;
   RC_5 = 0;
   // Check if the received signal is RC5 protocol
   else return;
   else return;
   else return;
   // Read signal data
   for(i = 0; i < 12; i++){
       if (PORTB.F0) toggle = 0;
       else          toggle = 1;
     else {
       if(i < 6){                   //Read address bits
         if (PORTB.F0)
           address &= ~(1 << (5 - i));  //Clear bit (5-i)
           address |= (1 << (5 - i));   //Set bit (5-i)
       else {                       //Read command bits
         if (PORTB.F0)
           command &= ~(1 << (11 - i)); //Clear bit (11-i)
           command |= (1 << (11 - i));  //Set bit (11-i)
   RC_5 = 1;
 void main() {
   OSCCON =  0X70;    // Set internal oscillator to 8MHz
   ADCON1 = 0x0F;     // Configure AN pins as digital
   CMCON = 7;         // Disable comparators
   TRISB.F0 = 1;      // Configure RB0 as input
   INTCON2 = 0;
   Stepper_Init(20);  // Initialize stepper motor(20 steps/revoltion)
   stepper_speed(500); // Set stepper motor speed to 500 rpm
   while (1) {                      // Endless loop
    if(RC_5){     // If RC_5 bit is one (Received IR signal is RC5 protocol)
     address &= 0x1F;
     command &= 0x3F;
     if((address == 0) && (command == 16))
       Stepper_Step(20) ;  // Move motor 20 steps in 1st direction(1 rev)
     if((address == 0) && (command == 17))
       Stepper_Step(-20) ; // Move motor 20 steps in 2nd direction(1 rev)
     PORTD = 0; }