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
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.
Leo..
Thank you so much for your replies and help. I have removed the L293d shield and gone back to my initial circuit and code. 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:
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.
Apologies - I have copied the code again via the 'copy for forum' button below. I hope this is better. The rotation values were funny before because we were just playing around with the settings before it stopped working. However, the code functioned fine and the hand cast turned to a thumbs up and thumbs down and middling position, as we wanted it to. The problem I need help with is the power issue. The servo motor beeped continuously, then worked erratically (the remote sensor flashed ok) and then it stopped working. So I will not plug it into my laptop again for power and 8 x AA batteries wired in did not work, so how should I power it and then wire the power into the circuit? Do I need a resistor in the circuit too? And if so, how should I add that to the circuit? I am a complete beginner. I have only done a few arduino starter kit circuits, so I would really appreciate your help and patience with my knowledge-void. I need beginner-level instructions on how to do it.
Thank you very much.
// 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()
{
Serial.begin(9600);
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 != 5)) {
val--; //for counter colockwise button
}
servo.write(val);
delay(20); //General speed
}
What version of the IRremote library do you have installed? The posted code is for an earlier version (<3.0) of the library. See the IRremote library page for instructions on what changes need to be made to the older code to work with the new version of the library.
You given us no real idea of what you have connected and where. A simple circuit diagram would help a lot. I can't see that 8 x AA batteries (12V) would do anything except perhaps cause some damage.
The servo could be powered by 4 x AA batteries connected DIRECTLY to + and - with the - also connected to the Arduino GND . Directly means not through a breadboard and definitely not from the Arduino 5V pin. That would be a good start.