ARDUINO How To Bluetooth Control 2 DC Motors Speed And Direction With A L298N

Check us out on Facebook!

APK Download Link:  This is the ANDROID APP..

AIA DownLoad Link:  This is the MIT APP INVENTOR  File..

affiliate links:

If you don’t have a L298N H bridge click here to find great prices on these and other arduino stuff!

ARDUINO CODE:

//Copy and paste this into your arduino ide….

#define pin1 2 // motor #1 +
#define pin2 3 // motor #1 –
#define pw1 9 // motor #1 pwm
#define pin3 4 // motor #2 +
#define pin4 5 // motor #2 –
#define pw2 6 // motor #2 pwm
void setup() {
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pw1, OUTPUT);
pinMode(pw2, OUTPUT);
Serial.begin(9600);
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
digitalWrite(pin3, LOW);
digitalWrite(pin4, LOW);
analogWrite(pw1, 50);
analogWrite(pw2, 50);

}

void loop() {

if (Serial.available() >= 2 )
{
unsigned int a = Serial.read();
unsigned int b = Serial.read();
unsigned int val = (b * 256) + a;

if (val == 100) // motor 1 reverse
{
digitalWrite(pin1, LOW);
digitalWrite(pin2, HIGH);

}
else if (val == 200) // motor #1 stop
{
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
}
else if (val == 300) // motor #1 forward
{
digitalWrite(pin1, HIGH);
digitalWrite(pin2, LOW);
}
else if (val == 400) // motor #2 reverse
{
digitalWrite(pin3, LOW);
digitalWrite(pin4, HIGH);
}
else if (val == 500) // motor #2 stop
{
digitalWrite(pin3, LOW);
digitalWrite(pin4, LOW);
}
else if (val == 600) // motor #2 forward
{
digitalWrite(pin3, HIGH);
digitalWrite(pin4, LOW);
}
else if (val >= 1000 && val <= 1255)
{
analogWrite (pw1, val – 1000);
}
else if (val >= 2000 && val <= 2255)
{
analogWrite (pw2, val – 2000);
}
}
}

MIT APP INVENTOR 2 BLOCK DIAGRAM 4 THE APP::    Click on the picture below to enlarge it…..

blocks