
Select input/output mode of GPIO using data direction register. This variable will be used to define direction of motor. Then, use one variable to keep track of push button pressed status. #define F_CPU 16000000UL #include #include Firstly define CPU frequency of microcontroller and include all necessary libraries. The one push button will be used to rotate DC motor in Clock Wise direction and the another push button will be used to rotate DC motor in Counter Clock wise direction. DC motor will rotate in two directions when respective push button is pressed. The DC motor is interfaced using L293D motor driver. Complete Program is given at the end of the project, just upload the program in Atmega16 and use the two Push Buttons to rotate the DC motor clockwise and Anti-clockwise. If you don’t know how to program Atmega16 using USBASP then visit the link. Here the Atmega16 is programmed using USBASP and Atmel Studio7.0. Since microcontrollers have PWM pins, so it can be used to control the speed of motor. Also its speed can be varied by varying supplied voltage. The direction of the motor is controlled by reversing the current. So when the electric current is passed through a coil in a magnetic field, a magnetic force is generated which produces a torque resulting in the movement of motor. The basic principle of motor is the interaction between the magnetic field and current to produce a force within the motor which helps the motor to rotate. Specifically, a DC motor uses DC current to convert electrical energy into mechanical energy. What is a DC motor?ĭC Motor is a device which transforms electrical energy into mechanical energy. But before going ahead let’s know more about DC motor. Today we learn to control DC motor with AVR Microcontroller Atmega16. We previously interfaced DC Motor with many other microcontrollers like Arduino, Raspberry pi and used it in many robotic projects. These motors can be found almost everywhere from small projects to advanced robotics. DC motors are the most widely used motors.
