How to add IR remote to servo motor using motor shield L293D?

How do you use a IR remote with a servo motor using a motor shield L293D? The l293D takes up the arduino board pins that I was previously using to make the IR remote work.

How do I power this motor? It only works when plugged into my laptop. I wired 8 x AA batteries. No joy.

Servo - specification:
Stall Torque: 12 kg/cm(4.8V), 15kg/cm(6V)
Dimensions : 54.1 x 20 x 44.3 mm
Weight: 55g
Voltage: 4.8~6V

Motor shield L293D specifications:

  • Motor Voltage: 4,5 V - 25 V
  • Servo Voltage: 5 V
  • Current: 0,6 A per H-bridges
  • Dimensions: ca. 70 mm x 55 mm

Thank you.

What pins are available ?

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

Your post was MOVED to its current location as it is more suitable.

Why are you using an L293D shield with a servo?


Interfacing and using IR is one task. Operating an L293 is a totally different matter. There's nothing connecting them except for what You want to use them for.
Use example codes for each of them. When both 2 parts are well known Make the logic in code that makes them do what You want.

The designer who put two servo connectors on that L293D motor shield must have had a brain fade. Servo power on a L293D shield comes from the 5volt pin, and that's bad.
Only use that shield for tiny brushed DC toy motors, nothing else.
Continuing to use the servo through that shield could also release the magic smoke from the laptop.

Connect servo signal/ground directly to the Arduino,
and connect a separate supply to servo power/ground.
That supply must be able to deliver the stall current of the servo.

Sounds like a Sunfounder 55g from the limited specs you posted.
They have a stall current of about 1.7Amp. Way beyond USB power.

Thank you so much for your replies and help. I have removed the L293d shield and gone back to my initial circuit and code, see code below as requested. I used pin 9 for the servo and pin 2 for the IR remote along with the 2 ground pins, the 5V and Vin pins.

However, it worked intermittently for a few minutes with this set up, then the motor, which beeped SOS constantly, stopped working, which was why I tried the L293d shield. Please can you tell me what battery and resistor I need to buy and how I should wire these into my circuit? The motor will turn a cast of a hand for a book thumbs up machine. It will go in a child's bedroom, so I need it to be safely powered and wired. It's a build we made for Mark Rober's creative engineering course a few weeks ago. If you could please instruct me exactly for a complete beginner, I would be very grateful.

The hand cast weighs 300g, which is attached via a wooden strut and dowel. I removed the sculpture to test the motor without it on and the motor did not work then either, so the problem is a power one. I chose this motor for its torque:

Stall Torque: 12 kg/cm(4.8V), 15kg/cm(6V)
Dimensions : 54.1 x 20 x 44.3 mm
Weight: 55g
Voltage: 4.8~6V
SUNFOUNDER Metal Gear Digital RC Servo Motor High Torque for Helicopter Car Boat Robot Arduino AVR Toys Drone Fix-Wing Airplane - SUNFOUNDER (

Here is the code I used for the IR remote: [code]
// Written by: Mohamed Soliman
// This code is for controlling servo motor with IR remote control
// When clicking at any of two buttons the motor is toggling between the rotation and stop

#include <IRremote.h> //must copy IRremote library to arduino libraries
#include <Servo.h>
#define plus 0xFF52AD //clockwise rotation button
#define minus 0xFF6897 //counter clockwise rotation button

int RECV_PIN = 2; //IR receiver pin
Servo servo;
int val; //rotation angle
bool cwRotation, ccwRotation; //the states of rotation

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
irrecv.enableIRIn(); // Start the receiver
servo.attach(9); //servo pin

void loop()
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value

if (results.value == plus)
  cwRotation = !cwRotation;      //toggle the rotation value
  ccwRotation = false;         //no rotation in this direction

if (results.value == minus)
  ccwRotation = !ccwRotation;   //toggle the rotation value
  cwRotation = false;            //no rotation in this direction

if (cwRotation && (val != 170)) {
val++; //for colockwise button
if (ccwRotation && (val != 200)) {
val--; //for counter colockwise button
delay(20); //General speed

To add code please click this link;

Before reposting, please hit CTRL-T in the IDE to AutoFormat your code to make it read easier.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Put some serial prints in to check what actual values you're writing to the servo. Since servo.write() takes values from 0 to 180 your calculations look odd to me.

And it doesn't look as if you are catering for +/- buttons being held down which normally sends a repeat code not the standard button code.