Home » Embedded Systems

AVR | Rotating DC motor clockwise and anti clockwise using ATmega16 microcontroller

In this article, we would learn how to rotate a simple DC motor clockwise and anticlockwise using AVR microcontroller ATmega16?
Submitted by Suryaveer Singh, on June 20, 2018

It is also a very simple program, the Simple DC motor can be rotated clockwise when the input is given to the positive terminal and vice versa for Anti-clockwise rotation.

Program to Rotate DC motor clockwise and anti clockwise

#include <avr/io.h>
#define F_CPU 1000000
#include <util/delay.h>


int main(void)
{
	DDRA = 0x81;
	
	while(1)
	{
		PORTA = 0x01;
		_delay_ms(1000);
		PORTA = 0x00;
		_delay_ms(500);
		PORTA = 0x80;
		_delay_ms(1000);
		PORTA = 0x00;
		_delay_ms(500);
	}
}

Explanation

When you will connect the motor ATmega16 with the DC motor the terminals required would be PA0 and PA7.

PA7	PA6	PA5	PA4	PA4	PA3	PA2	PA1	PA0
1	0	0	0	0	0	0	0	1

The above representation can be represented in Hexadecimal as 0x81, the first four term i.e. 1000 represents 8 in binary and the last four term 0001 will represent 1 in binary. Therefore the input pins are defined as DDRA = 0x81.

Inside the while loop firstly we have given input to the PA0 i.e. (PORTA = 0x01) the motor will rotate in the clockwise direction.

Then for 500 milliseconds we have stopped our motor (PORTA = 0x00) & then again we have given our input to PA7 terminal which would move the Motor in anti-clockwise direction.

Again it is stopped and further the same cycle repeats.

Simulation

Rotating DC motor clockwise and anti clockwise

Explanation

  • Devices required:
    1. ATMEGA16
    2. Simple DC motor
  • Arrange the setup as shown in the figure.
  • Double click on the motor and click on edit properties and then change the voltage our motor to 3v or any small value, decreasing the voltage of our Motor will increase its speed of rotation.
  • Put the HEX file in ATmega16 by double clicking it and selecting the path.
  • Click on the play Button and your Simulation will run as we wanted.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.