hh.jpeg (225794Bytes)
source.zip (2455Bytes)
SETUP:
I have a test circuit using an Arduino UNO that is wired to a L293D chip on a seperate breadboard. I followed the "Goduino II" schematic.
The L239D has two small DC motors connected to it. I also have a PING ))) Sensor sitting on top of a Servo. The Servo is connected to pin 6 and the Sensor is on A4 on the Arduino. The sensor works fine.
PROBLEM STATEMENT:
Enabled Servo Code:
Servo responds to write() commands
DC motors attached to L239D are unresponsive
Commented Out Servo Code:
DC motors attached to L239D respond as expected.
CODE SNIPPET:
//-----------------------------------------------------------
void setup() {
PingServo.attach(6);
PingServo.write(90);
pinMode(enablePin1, OUTPUT);
pinMode(enablePin2, OUTPUT);
pinMode( motor1pole1 , OUTPUT);
pinMode( motor1pole2, OUTPUT);
pinMode( motor2pole1, OUTPUT);
pinMode( motor2pole2 , OUTPUT);
Serial.begin(9600);
motorSpeed(0, 0);
}
//-----------------------------------------------------------
Any help is appreciated....I'm currently at a loss. Thanks :)
The first problem I see is
The first problem I see is the power source. A 9v battery may just not have the ability to power your motors and the sensor/servo. This could cause a voltage drop such that the Arduino reboots. It is usually better to use rechargeable batteries rather than normal batteries because most rechargeables can produce their power faster.
It would also help if you included the entire source code as an attachment. You may have a pin allocation problem which I can’t see until I see the definitions of your constants. Also I’m not sure which library you are using (I’m assuming PingServo but I only getting that from the object name).
One thing I would strongly suggest is to separate variables from constants. I use lower case with intercaps (example: lowerCase) for variables and functions, and all caps (ex: ALL_CAPS) for constants. This makes it obvious to myself and anybody reading my code which things are constants; this includes myself a month from now.
One test that could tell a lot is to leave the first PingServo statement in, but comment out the second. What does that do?
Another thing: please put a link to the Goduino II schematic in your post. I have no idea what it is.
Servo.h
Are you using the Servo library?
If so, are you expecting PWM on pins 9 or 10? The Servo library disables the PWM on these pins.
Something that hasn’t been asked,
Are either of your motors connected to pin 6?
And please, ahollis70, let
And please, ahollis70, let us know how things are going.
Also, are the motors being powered by the battery through the H-Bridge chip, or are you using the 5v from the UNO? Likewise for the servo?
The UNO’s 5v output is meant for sensors and such. There isn’t enough power for motors.
If you do have multiple power sources, make sure you connect the grounds together.
Thanks for responding guys
@DangerousThing: In the original picture the L293D is powered via the 9v battery on its pin 8. However, VCC is getting 5v from the Arduino UNO on pin 16.
In regards to your point about PWM. Yes I am expecting to control the duty cycle as the maxSpeed is 0 to 255, or 0 to E1. I’m including <Servo.h> in the source. If the use of this h file disables PWM on pins 9 & 10 is there a workaround to include the servo in my circuit?
Goduino Schematic (The Author is also a member of LMR) :
http://www.instructables.com/files/orig/FY2/SZKB/H0OJ5NNI/FY2SZKBH0OJ5NNI.jpg
@Birdmun: Nope neither of the motors are connected to pin 6 on the Arduino.
@Duane Degn: You will get no argument for me Sir The orginal picture is just a test bed and then I pop out the ATMEGA328pu chip and place it in the circuit of my actual bot not shown. However, in my design I have the 9v included with the bot. The motors are driven by the 9v battery and the ATMEGA328PU is driven by 4 AA non rechargeable batteries.
However, as being one to take advice from those I deisre to learn from. I will augment my design and switch out both power sources to rechargeables; putting the 9v battery back in my smoke detector
Based on the replies thus far, I’m wondering if this issue is what DangerousThing alluded to which was expecting PWM on pins 9 & 10. The code I’m using enables pins 9 & 10 because it maps the L293D to the Arduino. For the sake of completeness. I did take out the 9v battery and attached my bench power source to the L293D chip - same result.
So this has me at a loss with my limited expereince. I really wanted to avoid using a motor shield with my first bot. Is there are to include the servo in my setup based on the design of L293D circuit?
Thanks.
**I will try to edit the orignal post to include the source code.
The Arduino has power
The Arduino has power management to a limited degree: it uses linear regulators to lower the voltage from 9 to 5 and also from 5 to 3.3 (I think, it may be that it uses the second regulator to lower the voltage from 9 to 3.3).
You will need about two or three power supplies (sets of batteries), though you might be able to do this one.
Hobby servos typically take 4-6 volts. They motors you are using can take 3-6 volts if I’m remembering correctly. So you could use any 5 volt source to run the AVR chip, and a 4-6 volt source, say 4 AA NiMN’s to run both the motors and the power for the servo. If you do this, you must connect the ground wires of the two power sources.
When I’m not using lithium batteries (I got a pair of 7.4 volt 8 amp*hr batteries on a holiday sale) I use rechargeable AA NiMN’s. For the motors, a four pack will do, and for the chip, I’d use a five-six pack and a good five volt regulator.
I try to use switching regulators when possible.
For example, I will be using an Arduino to power a bot I’ll be building while my wife is in surgery. I’ll use a single 7.4 v battery to power everything, but I’ll lower the voltage with a switching regulator for the motors and servos to 5-6 volts just to be able to put the motors and servos on the same power rail.
Have a Happy New Gear!