Pages: [1]   Go Down
Author Topic: l298p shield & serial control  (Read 264 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I am pretty new to C and the arduino. I am looking to control two channels via the l298p motor shield on top of an arduino uno with atmega 328.

The chassis I'm using has four DC motors and I have the left two motors wired together, and the right respectively. I'm looking to code basic forward, backward, left or right functions.

Essentially, left or right would run the sided in opposite directions to turn my robot. forward and reverse would just be all ahead fordward or reverse.

So far I have forward, but how would I handle the other directions? Should I nest them in the same loop?

//Arduino PWM Speed Control:
int E1 = 6;
int M1 = 7;
int E2 = 5;
int M2 = 4;
void setup()
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
while (! Serial);
Serial.println("Enter the Direction")
void loop()
if (serial.available()))
int forward = Serial.parseInt();
if (forward = F)
digitalWrite(M2, HIGH);
analogWrite(E1, 100); //PWM Speed Control
analogWrite(E2, 100); //PWM Speed Control

Thanks in advance!


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
Karma: 543
Posts: 27348
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Search my recent posts, I did just what you are looking for for someone else.
Needed a little tweaking to compile right, but it was very close.

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at
Arduino for Teens available at

Pages: [1]   Go Up
Jump to: