To Build a Robot part 2

March 26, 2010

I was able to get the L298B working on the first run. The motor runs nicely on a couple double A batteries. I will be adding extra controllers and parts later but it was good to get it running without any issues.

L293B H-Bridge

L293B H-Bridge



The sketch I used to test was:

int enablePin = 9; //Motor's enable pin
int dPin_1 = 6;// Digital Pin to turn the motor on/off
int dPin_2 = 7;
int ledPin = 13; //LED pin

void setup()
{
pinMode(enablePin, OUTPUT);
pinMode(dPin_1, OUTPUT);
pinMode(dPin_2, OUTPUT);
pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(enablePin, HIGH);
digitalWrite(dPin_1, HIGH); //turn on the motor
digitalWrite(dPin_2, LOW);

delay(5000); //delay for 5 seconds

//switch directions
digitalWrite(enablePin, LOW);
digitalWrite(enablePin, HIGH);

delay(3000);

digitalWrite(dPin_1, LOW);
digitalWrite(dPin_2, HIGH);

blink(ledPin, 3, 500);

digitalWrite(ledPin, LOW); // turn off LED
digitalWrite(dPin_1, LOW); //turn off motor
delay(2000); //delay for 2 seconds.
}

void blink(int whatPin, int howManyTimes, int howLong) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(howLong);
digitalWrite(whatPin, LOW);
delay(howLong);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: