DC Motor PWM Speed Control with Ultrasonic Distance

Home Forums Microcontrollers PIC Microcontroller DC Motor PWM Speed Control with Ultrasonic Distance

This topic contains 1 reply, has 2 voices, and was last updated by  Ligo George 1 year, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12265

    Kimie Hakimie
    Participant

    hi and good day to you, i am working on pic16f877a , have interfaced push-button to trigger the ultrasonic sensor hc-sr04 and the range will control the motor speed by using the pwm function. i am very new to the programming mikroC and i really hope you can guide me. As now i just learn how to interface push button with my led. I tried to combine the code how to interfacing ultrasonic and lcd and it didn’t work, i am very sorry, here my code:

    void main()
    {
      TRISA.F0 = 1; //Configure 1st bit of PORTD as input
      TRISA.F1 = 1;
      TRISA.F2 = 1;
      TRISB.F5 = 0; //Configure 1st bit of PORTB as output
      TRISB.F6 = 0;
      TRISB.F7 = 0;
      TRISA.F3 = 0;
      PORTB.F5 = 1; //LED OFF
      PORTB.F6 = 1; //LED OFF
      PORTB.F7 = 1; //LED OFF
      PORTA.F3 = 1; //BUZ OFF
      ADCON1 = 7;
    
      do
      {
        // LED 1
        if(PORTA.F0 == 0) //If the switch is pressed
           PORTA.F3 = 0; //BUZ ON
        Delay_ms(100); //1 Second Delay
         PORTA.F3 = 1; //BUZ OFF
    
        {
          Delay_ms(150); //Switch Debounce
          if(PORTA.F0 == 0)//If the switch is still pressed
          {
            PORTB.F5 = !PORTB.F5; // LED out port
          }
        }
    
        // LED 2
      
        if(PORTA.F1 == 0) //If the switch is pressed
        if(PORTA.F0 == 0) //If the switch is pressed
           PORTA.F3 = 0; //BUZ ON
         Delay_ms(100); //1 Second Delay
         PORTA.F3 = 1; //BUZ OFF
        {
          Delay_ms(150); //Switch Debounce
          if(PORTA.F1 == 0)//If the switch is still pressed
          {
            PORTB.F6 = !PORTB.F6; // LED out port
          }
        }
    
    
        // LED 3
        if(PORTA.F2 == 0) //If the switch is pressed
        if(PORTA.F0 == 0) //If the switch is pressed
          PORTA.F3 = 0; //BUZ ON
        Delay_ms(100); //1 Second Delay
        PORTA.F3 = 1; //BUZ OFF
        {
          Delay_ms(150); //Switch Debounce
          if(PORTA.F2 == 0)//If the switch is still pressed
          {
            PORTB.F7 = !PORTB.F7; // LED out port
          }
        }
      }while(1);
    }
    #12269

    Ligo George
    Keymaster

    Sorry, I don’t understand what are you doing and I haven’t seen any ultrasonic distance measuring section in your program.

    One of the main mistake I found in your code is, you are not using open and closing braces of if statement correctly. Please correct it and recheck your code.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.