in

how to use l293d motor driver/servo shield for Arduino

If you are planning on assembling your new robot, you will eventually want to learn about controlling a variety of motors like DC motors, Stepper motors & servos. One of the easiest and inexpensive ways to do that is to interface L293D Motor Driver Shield with Arduino. It’s a full-featured motor shield – perfect for many robots and CNC projects.

It can drive :

  • 4 bi-directional DC motors with 8-bit speed selection(0-255)
  • 2 stepper motors (unipolar or bipolar) with single coil, double coil, interleaved or micro-stepping.
  • 2 servo motors

L293D Motor Driver & 74HC595 Shift Register

Power Supply

Output Terminals

#include <AFMotor.h>

AF_DCMotor motor(4);

void setup() 
{
	//Set initial speed of the motor & stop
	motor.setSpeed(200);
	motor.run(RELEASE);
}

void loop() 
{
	uint8_t i;

	// Turn on motor
	motor.run(FORWARD);
	
	// Accelerate from zero to maximum speed
	for (i=0; i<255; i++) 
	{
		motor.setSpeed(i);  
		delay(10);
	}
	
	// Decelerate from maximum speed to zero
	for (i=255; i!=0; i--) 
	{
		motor.setSpeed(i);  
		delay(10);
	}

	// Now change motor direction
	motor.run(BACKWARD);
	
	// Accelerate from zero to maximum speed
	for (i=0; i<255; i++) 
	{
		motor.setSpeed(i);  
		delay(10);
	}

	// Decelerate from maximum speed to zero
	for (i=255; i!=0; i--) 
	{
		motor.setSpeed(i);  
		delay(10);
	}

	// Now turn off motor
	motor.run(RELEASE);
	delay(1000);
}

Written by Admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

GIPHY App Key not set. Please check settings

how to use IR sensor module with Arduino

How to make LED Bar graph | Arduino