Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

Joystick Controlled DC Motor

By Ashutosh Bhatt

The DC motor controllers control speed and direction of DC motor. To change the direction of the motor, the supply given to motor has to be reversed and to vary DC motor speed the applied input voltage has to be varied. The PWM method is very popular method to vary DC motor speed. In this method PWM wave is applied to DC motor whose pulse width can be varied. As pulse width increases the average voltage applied to motor increases and vice versa. This means as the pulse width varies the DC motor speed also varies. To change the direction of motor, very popular H-bridge circuit is used. Using H-bridge circuit the supply given to motor can be reversed so the motor will rotate reverse.

Most of the DC motor controllers use PWM to vary motor speed and H bridge circuit to alter its direction. One of the techniques becoming very popular and widely used now a days of DC motor control is to control DC motor through joystick. Using single joystick one can control speed as well as direction of DC motor. When joystick is at centre position the motor is rest. When joystick is moved forward or reverses the motor also rotates forward and reverse. Also the motor speed increases when joystick moved further forward or reverse. Joystick control for DC motor is used in many different applications like

  1. Remote controlled toys like RC (remote controlled) plane, helicopter, boat, car etc
  2. Joystick controlled video camera crane
  3. Industrial Jog* controller
  4. Robotic arm or robotic vehicle
  5. Surveillance camera controller

Etc so many application we can list out. In all such applications the DC motor that drives the load is controlled by joystick. In some of the applications only direction of motor is altered (RC toys) while is other application direction and speed both are varied (video camera crane, jog control). The project given here controls speed and direction of DC motor using joystick. A simple potentiometer used here as a joystick. It is built using AVR micro controller ATmega32. It rotates motor forward and reverse as well as varies its speed as joystick is moved.

*note: jog control is used in industries to check DC motor will start rotating in which direction initially when it is connected with load.

Circuit description:

The circuit is build using two major components AVR micro controller ATMega32 and motor driver chip L293D.

·         A 1K pot is connected to 1st channel of ADC input (pin no. 40) as shown. It is connected such that when slider moves the voltage at ADC input varies from 0 to Vcc (5 V)

·         Two LEDs – one RED and one Green are connected to PB7 pin (7) and PD0 pin (14) respectively

·         Two PWM channel outputs OC0 pin (4) and OC2 pin (21) are connected to two inputs IN1 and IN2 of L293D chip

·         The enable input EN1 of L293D is connected to Vcc to enable one half bridge section

·         The DC motor is connected to outputs OUT1 and OUT2 of L293D

·         One 8 MHz crystal along with two 22 pF capacitors is connected to crystal input pins XTAL1 and XTAL2

Circuit operation:

·         Initially pot is turned to exact middle position this makes voltage at ADC pin input equals Vcc / 2 = 2.5 V

·         Till the pot is kept  at middle position the motor is stop and both LEDs are also off

·         As pot is slightly turned clockwise the voltage input at ADC increases and the motor starts rotating forward with low speed. The green LED becomes on to indicate motor is rotating forward

·         As pot is turned more clockwise gradually, the motor speed increases gradually

·         When pot is fully turned clockwise, the motor attains full speed in forward direction

·         When again pot is turned back to middle position, the motor speed gradually decreases and it stops. The green LED is also off

·         Now as pot is turned slightly anticlockwise, the motor starts running reverse at slow speed. The RED LED indicates motor is running reverse

·         As pot is turned further the motor speed increases and attains maximum speed in reverse direction when pot is turned fully anti clockwise

·         To stop motor again, the pot is turned back to middle position

·         Thus motor moves forward or reverse as pot is turned clockwise or anticlockwise and also the speed of motor increases as pot is turned more clockwise or anticlockwise

To implement these functionalities a software program is embedded into internal FLASH of ATMega32 micro controller.

Software program:

The software program does following tasks

·         Reads analog voltage value on ADC input pin and converts it into digital

·         If the digital value is between 510 to 515 then it sends 0 to both PWM output channels and stops the motor

·         If the digital value is less than 510 then it generates PWM on OC0 pin to start rotating motor forward. As the value is further decrease the pulse width increases to increase DC motor speed

·         Similarly if digital value increases above 515, it generates PWM on OC2 pin to rotate motor reverse. As the value is increased further the pulse width increases that increases motor speed

·         It also gives indications on LEDs of motor rotating forward or reverse

The program uses all three timers Timer 0, Timer 1 and Timer 2 of ATMega32. It uses timer 0 and timer 2 to generate PWM to vary speed of DC motor and timer 1 to generate periodic interrupts at specific time interval to read new analog voltage value on ADC input pin.

Prototype of AVR ATMega32 based Joystick DC Motor Controller

Fig. 1: Prototype of AVR ATMega32 based Joystick DC Motor Controller

Project Source Code

###


#include <avr/io.h>

#include <util/delay.h>

#include <avr/interrupt.h>

 

unsigned int adc_value,flag=0;

///////////////////////////////// ADC initialize function ///////////////////////

void adcinitliz()

  {

     ADMUX = (1<<REFS0);                              // select reference

     ADCSRA =(1<<ADPS2) | (1<<ADPS1) | (0<<ADPS0);   

     ADMUX=0x00;                                      // select 1st channel

  }

void calculate_value()

///////////////////////////// get ADC value and set PWM width//////////////////////

get_adc_value() 

{

     unsigned int tmp1,tmp2,tmp3,t;

     tmp1 = (ADCL & 0x0F);               // convert HEX value of ADCL and ADCH

     tmp2 = ADCL >> 4;                   // into decimal

     tmp3 = (ADCH & 0x0F);

     tmp2 = tmp2*16;

     tmp3 = tmp3*256;     

     t = tmp1+tmp2+tmp3;  

     adc_value = t;                      // get decimal equivalent value 

     if(t<115) OCR0 = 245;                      // set width of PWM as per

     else if((t>=115) && (t<215)) OCR0 = 0xCC;  // ADC vlaue

     else if ((t>=215) && (t<315)) OCR0 = 0x99;

     else if ((t>=315) && (t<415)) OCR0 = 0x66;

     else if ((t>=415) && (t<=510)) OCR0 = 0x33;

     else if((t>=515) && (t<615)) OCR2 = 0x33;

     else if ((t>=615) && (t<715)) OCR2 = 0x66;

     else if ((t>=715) && (t<815)) OCR2 = 0x99;

     else if ((t>=815) && (t<915)) OCR2 = 0xCC;

     else if(t>=915) OCR2 = 245; 

}

/////////////////////////////// initialize timer 1 /////////////////////////////

void timer1_init()

  {

     TCCR1B |= (1 << CS11);              // select clock

     TCNT1 = 0;                          // start count from 0

     TIMSK |= (1 << TOIE1);              // enable timer 1 interrupt

     sei();

  }

//////////////////////////// timer 1 overflow interrupt subroutine ///////////////

ISR(TIMER1_OVF_vect)

  {

      ADCSRA = (1<<ADEN) | (1<<ADSC);    // start conversion

      while(!(ADCSRA & (1<<ADIF)));      // wait till conversion end flag is set

      ADCSRA = (1<<ADIF);

      flag=1;                            // set user flag to 1

  }                 

/////////////////////////////////// main function ////////////////////////////////

int main()

 {

     int flag=0;                         // declare and initialize user flag     

     DDRB=0x48;                          // set LED pin and PWM pin as output for

     PORTB=0x40;                         // PORTB and PORTD

     DDRD=0x81;

     PORTD=0x01;

     adcinitliz();                       // initialize ADC

     timer1_init();                      // initialize timer 1

     ADCSRA = (1<<ADEN) | (1<<ADSC);     // start conversion

     while(!(ADCSRA & (1<<ADIF)));       // wait till end of conversion

     ADCSRA = (1<<ADIF);

     get_adc_value();                    // get ADC value in decimal

     ///////////////////////////////// continuous loop /////////////////////////

     while(1)

       {

              while(flag==0)             // wait till ADC conversion ends and user

             {                          // flag is set

                 get_adc_value();        // get ADC value in decimal

 

                 if(adc_value>515) // if ADC value is more than 515 

                  {

                     TCCR0=0x00;          // stop PWM on channel 0

                     TCCR2=0x6C;          // start PWM on channel 1

                     PORTB &= 0xB7;       // green LED on

                     PORTD |=0x01;        // red LED off

                }   

              else if(adc_value<510)     // if ADC value is less than 510

                {

                     TCCR0=0x6B;          // start PWM on channel 0

                    TCCR2 = 0x00;        // stop PWM on channel 1

                     PORTD &= 0x7E;       // red LED on

                     PORTB |= 0x40;       // green LED off

                }

              else if((adc_value>=510) && (adc_value<=515))   // if ADC value is in

               {                                              // middle

                     TCCR0=0x00;                              // stop both PWM

                     TCCR2=0x00;  

                     PORTB=0x40;                              // both LEDs off

                     PORTD=0x01;

               }             

             flag=0;                     // clear user flag for new value

      }

    }

  }      

###

 


Circuit Diagrams

Circuit-Diagram-AVR-ATMega32-Joystick-DC-Motor-Controller

Project Video


Filed Under: Electronic Projects

 

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Pull up via GPIO
  • Code Optimization
  • Poly Spacing Effect
  • Thyristor Gate Drive
  • Passive Harmonics Filter

RSS Electro-Tech-Online.com Discussions

  • Someone please explain how this BMS board is supposed to work?
  • HV Diodes
  • Question about ultrasonic mist maker
  • DIY bluetooth speaker
  • Disabled son needs advice please
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering