Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

run motor via ldr and pic 16f877

Status
Not open for further replies.

lamterteg

Newbie level 3
Newbie level 3
Joined
Feb 28, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
25
Hi PIC i am new begginer on pic programming

as i want to start a project named running motor via ldr with pic16f877:

when a source light light on ldr a dc motor runs

when the source shutts off the dc motor shutdown

i've already start programming using microc but i get a problem that motor is not running

code:



HTML:
void initialise(){
   TRISC=0xfe;
  TRISA=0x01;
  ADCON0=0b10000001;
  ADCON1=0;
PORTC=0;
 }
 void convert(){
  while(GO_DONE);}
 void light(){



          int lightlv =((ADRESH<<8)+ADRESL);
          if(lightlv>365)
          PORTC=1;

 }


void main() {
    initialise();
    while(1){
    convert() ;
    light();
    delay_ms(4000);}

 
}

the simulation:
Nouvelle image bitmap.png
 

Check with this code
Code:
unsigned int adc_value;

void main()
{
     
     TRISA=0xFF;
     ADCON1 = 0x80; // Analog channel select channel2 and channel 3
     TRISC0_bit = 0;                                // set RB0 pin as output
  
     while(1)
        {            
                  
           adc_value = ADC_Read(0);   // Get 10-bit results of AD conversion
            if(adc_value>365) 
               RC0_bit= 1;
            else
               RC0_bit= 0;       
                     

        } 
}

It is not suitable to connect DC motor directly with micro controller. Better connect with L293d h bridge driver
 

Check with this code
Code:
unsigned int adc_value;

void main()
{
     
     TRISA=0xFF;
     ADCON1 = 0x80; // Analog channel select channel2 and channel 3
     TRISC0_bit = 0;                                // set RB0 pin as output
  
     while(1)
        {            
                  
           adc_value = ADC_Read(0);   // Get 10-bit results of AD conversion
            if(adc_value>365) 
               RC0_bit= 1;
            else
               RC0_bit= 0;       
                     

        } 
}

It is not suitable to connect DC motor directly with micro controller. Better connect with L293d h bridge driver


thanks so much for the code but the motor still not running
i think that i didn't calculate the adc value(365) very well i as you said "Better connect with L293d h bridge driver".
 

mikroC PRO PIC code attached. I have used PIC16F877A. PWM is used for speed control of motor. What are you trying to do ? Solar Tracking ? If yes, use stepper motor.
 

Attachments

  • LDR + Motor Control.rar
    91.3 KB · Views: 169
  • motor control.png
    motor control.png
    34.9 KB · Views: 177

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top