Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to use 2 servo Motor, 3 IR set, and LCD with PIC18F4550?

Status
Not open for further replies.

Ragens

Member
hi,

i started this thread : https://www.electro-tech-online.com...ximity-inductive-sensor-in-pic18f4550.134000/

but the cost of proximity sensor too expensive for me right now, i change to IR set... many people said that IR Set is common one for sensor and cheap. I not good in Microcontroller so i need help around here which are expect in microcontroller.

what i want to do is detect object using IR set then move the servo Motor, after that display on LCD how many object that is already detected.

I from IT student so i do not know much about MicroC since im not in engineering Course, somehow they give me assignment about this...

I will post the Circuit after i done with proteus.

Sorry im not good in english, Thanks...
 
here i have attach the LCD and servo motor on circuit. But i do not know where to put the IR set... how to upload attachment file? easier to put whole design...

sorry i forgot the servo motor just two...
Untitled.png
 

Attachments

  • Untitled.png
    Untitled.png
    38.8 KB · Views: 658
here is IR set, it need LM324... i do not know what is that... :

a.png

for this i see LED use at the Output pin maybe to detect if got object or not. if i want to use servo motor with IR should i replace the LED with servo motor or let the LED be? where should i connect the servo motor to make it work?

example that i learn C programming the condition is:

i = 0; //this just count number

if(IR1==1 && i>0)
{ Motor rotate 90 degree //i do not know the servo motor coding yet
i++;
}
 
here after many googling, read datasheet and put piece of puzzle together but still missing something. i tested on Proteus/ISIS but it not functioning. I replace the IR with Switch for testing since I can not test IR input on proteus.

Please help me, Thank you.

Provided attachment of Proteus+Code in Mikcro C Pro
 

Attachments

  • TESTING.rar
    188.4 KB · Views: 366
when it comes to proximity sensor you can get em of ebay from about us$ 3 free shipping atleast if you can do with an inductive type ...
 
hi, i have done simulation on this circuit after couple month of research... but when i want to make hardware, the LCD give me 2 row of Black Box.

the connection almost same as this:Untitled1.jpg

I not using variable resistor instead i connect to ground vss+vee.

here how it look like:DSC_0078.jpg

Code:
#define IR1 PORTB.B0
#define IR2 PORTB.B1
#define IR3 PORTB.B2
#define RC_SERVO1 LATC.B0
#define RC_SERVO2 LATC.B1

sbit LCD_RS at LATA.B2;
sbit LCD_RW at LATA.B1;
sbit LCD_EN at LATA.B0;
sbit LCD_D0 at LATD.B0;
sbit LCD_D1 at LATD.B1;
sbit LCD_D2 at LATD.B2;
sbit LCD_D3 at LATD.B3;
sbit LCD_D4 at LATD.B4;
sbit LCD_D5 at LATD.B5;
sbit LCD_D6 at LATD.B6;
sbit LCD_D7 at LATD.B7;

sbit LCD_RS_Direction at TRISA2_bit;
sbit LCD_RW_Direction at TRISA1_bit;
sbit LCD_EN_Direction at TRISA0_bit;
sbit LCD_D0_Direction at TRISD0_bit;
sbit LCD_D1_Direction at TRISD1_bit;
sbit LCD_D2_Direction at TRISD2_bit;
sbit LCD_D3_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;

#define LCDPORT LATD

void dynamic_delay_10us(unsigned char delay);

void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);

void main() 

{
     unsigned int delay=0;
     unsigned int emptyspace=13;
     unsigned IntToSTR(int input, unsigned char *output);
     char text1[7];
     char text2[]= "Space Available";


     ADCON1=0x0F;

     TRISA=0;
     LATA=0;
     TRISB=0b00000111;
     TRISD=0;
     TRISC.B0=0;
     TRISC.B1=0;
     LATC.B0=0;
     LATC.B1=0;
     
     delay=(43+0*148/180);
     RC_SERVO1=1;
     dynamic_delay_10us(delay);
     RC_SERVO1=0;
     dynamic_delay_10us(200-delay);
     delay_ms(500);
        
     delay=(43+0*148/180);
     RC_SERVO2=1;
     dynamic_delay_10us(delay);
     RC_SERVO2=0;
     dynamic_delay_10us(200-delay);
     delay_ms(500);
     
     while(1)
     {
        Delay_ms(100);
        Lcd_Init();

        Lcd_Cmd(_LCD_CLEAR);
        Lcd_Cmd(_LCD_CURSOR_OFF);
            {
              Lcd_Out(1,4,text1);
              Lcd_Out(2,2,text2);
              Delay_ms(1000);
            }
     IntToStr(emptyspace, text1);
     
      if(IR1==1 && emptyspace>0)
      {
        delay=(43+111*148/180);
        RC_SERVO1=1;
        dynamic_delay_10us(delay);
        RC_SERVO1=0;
        dynamic_delay_10us(200-delay);
        delay_ms(500);
      
      }
     
      else if(IR2==1 && emptyspace>0)
      {
       delay=(43+0*148/180);
       RC_SERVO1=1;
       dynamic_delay_10us(delay);
       RC_SERVO1=0;
       dynamic_delay_10us(200-delay);
       emptyspace-=1;
      }
     
      else if(IR3==1 && emptyspace<13)
      {
       delay=(43+111*148/180);
        RC_SERVO2=1;
        dynamic_delay_10us(delay);
        RC_SERVO2=0;
        dynamic_delay_10us(200-delay);
        delay_ms(5000);
        delay=(43+0*148/180);
        RC_SERVO2=1;
        dynamic_delay_10us(delay);
        RC_SERVO2=0;
        dynamic_delay_10us(200-delay);
        emptyspace+=1;
      }
     }
}


void dynamic_delay_10us(unsigned char delay)
{
    for( ;delay>0;delay-=1)Delay_us(10);
}

void lcd_ini()
{
     lcdcmd(0x38);
     lcdcmd(0x0c);
     lcdcmd(0x01);
     lcdcmd(0x06);
     lcdcmd(0x80);
}

void lcdcmd(unsigned char cmdout)
{
     LCDPORT=cmdout;
     LCD_RS=0;
     LCD_RW=0;
     LCD_EN=1;
     Delay_ms(10);
     LCD_EN=0;
}

void lcddata(unsigned char dataout)
{
     LCDPORT=dataout;
     LCD_RS=1;
     LCD_RW=0;
     LCD_EN=1;
     Delay_ms(10);
     LCD_EN=0;
}

how to fix this problem?
 
You MUST wait 15mS before you can initialize the LCD..

Try this...

Code:
void lcd_ini()
{
     Delay_Ms(15);
     lcdcmd(0x38);
     Delay_Ms(5);
     lcdcmd(0x38);
     Delay_Ms(5);
     lcdcmd(0x0c);
     lcdcmd(0x01);
     lcdcmd(0x06);
     lcdcmd(0x80);
}
 
should i replace
Code:
 while(1)
     {
        Delay_ms(100);
        Lcd_Init();

with
Code:
while(1)
     {
        Delay_ms(100);
        lcd_ini();

???
when recheck my main() i not using function lcd_ini()
 
Oh mow I see your problem..... You can't initialise the LCD more than once... Place the LCDinit() BEFORE the while(1) statement

so if i put the lcd initialize before while(1) then the command to change the text or command in the while(1) what will happen?

thank you very much for the delay before initialize... it not work at first then i test couple of time it suddenly work...

what should i do to increase the servo motor accuracy or speed? because it not even reach at the position then it stop... i measure it voltage around 4.6-4.8 V, current each pulse will give 25mA even with NPN 2N 2222A transistor to increase the current will give same measurement 25mA at each pulse...
 
I've not really messed with servo's.... All I know is the position is pretty much governed by the pulse width...

I don't use mikroC either... There WILL be a library for servo driving....Its best to use a PWM output rather than generate your own..
 
I have test only using servo motor without condition(sensor or switch) code... the servo run smoothly, then when i change back using my IR sensor condition if detect object the motor will move, it move abit then stop and repeat the process till get to the position. I think i got problem with IR sensor code...

maybe same like switch debounce? but how to fix that on IR sensor? it not mechanical switch...
 
How to make infinity loop that has 2 important repeat command in coding that not interfere with other command?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top