Rotary encoders

Hi all,

I'm trying to move my robotic car in a straight line for a certain number of distance. I came across a video on youtube posted by SparksFun. I tried their method and used their codes. However, since I'm using the l293d shield I'm not sure what pins on the arduino mega would corrospond to the motor driver pin.

The shield I'm using: l293d shield - Bing

The codes they've used: Use two magnetic encoders to make a robot drive in a straight line for 1 meter · GitHub

// Pins
const int enc_l_pin = 2;          // Motor A
const int enc_r_pin = 3;          // Motor B
const int pwma_pin = 5;
const int ain1_pin = 9;
const int ain2_pin = 4;
const int pwmb_pin = 6;
const int bin1_pin = 7;
const int bin2_pin = 8;
const int stby_pin = 10;

Also in their code what is the purpose of the stby pin?

One last question. In their example they've used two motors, however, in my project I'm using four motors. Would it be fine if i just use two encoders on the front two wheels or does it have to be for all four wheels.

Thanks for taking the time to read, help is much appreciated.

The shield I'm using

A picture of the shield is useless. Post a link to the manufacturer's site.

however, in my project I'm using four motors.

Why? For what?

Would it be fine if i just use two encoders on the front two wheels

Fine by me.

Thanks for the replay Paul.

I got the shield from Jaycar: Arduino Compatible Motor Servo Controller Module | Jaycar Electronics.

Im using four motors because my car is a 4WD: 4 Wheel Drive Motor Chassis Robotics Kit | Jaycar Electronics

In the manufacturers datasheet, they have shown the Pinouts of the motors. However, for each motor there is only a single digital pin. Shouldn’t there be two pins for each motors?


"stby" sounds like "standby". Is it an input or output? If it is an output it may correspond to your enable pin.

Great screenshot but I need to know more about this shield. It looks like it might require a library to operate it because it has "clock" and "data" pins. "Drive motor 1 forwards at 50%" might be an analogWrite() and a digitalWrite() in the original code and you need to convert that into the appropriate library calls.