Go Down

Topic: DC Motors on Arduino UNO obstacle avoiding robot do not work (Read 4138 times) previous topic - next topic

kmshah423

Hello,

The DC motors on my obstacle avoiding robot do not work. Being a beginner, I am unaware of what is causing this issue. I am using the following to construct:

1.Arduino UNO
2.Motor Shield
3.Ultrasonic Sensor HC-SR04
4.Breadboard
5.2 DC Motors

Here is the Instructables link I am using to construct the robot (exact replica) for further guidance:

http://www.instructables.com/id/Arduino-Ultimate-Obstacle-Avoiding-Robot/

I am using the code that is published on that link:

Code: [Select]

#include <AFMotor.h> //import your motor shield library
#define trigPin 12 // define the pins of your sensor
#define echoPin 13
AF_DCMotor motor1(1,MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor2(2, MOTOR12_8KHZ);
 
void setup() {
  Serial.begin(9600); // begin serial communitication  
  Serial.println("Motor test!");
   pinMode(trigPin, OUTPUT);// set the trig pin to output (Send sound waves)
  pinMode(echoPin, INPUT);// set the echo pin to input (recieve sound waves)
  motor1.setSpeed(105); //set the speed of the motors, between 0-255
motor2.setSpeed (105);  
}
 
void loop() {

   long duration, distance; // start the scan
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2); // delays are required for a succesful sensor operation.
  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10); //this delay is required as well!
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;// convert the distance to centimeters.
  if (distance < 25)/*if there's an obstacle 25 centimers, ahead, do the following: */ {  
   Serial.println ("Close Obstacle detected!" );
Serial.println ("Obstacle Details:");
Serial.print ("Distance From Robot is " );
Serial.print ( distance);
Serial.print ( " CM!");// print out the distance in centimeters.

Serial.println (" The obstacle is declared a threat due to close distance. ");
Serial.println (" Turning !");
    motor1.run(FORWARD);  // Turn as long as there's an obstacle ahead.
    motor2.run (BACKWARD);

}
  else {
   Serial.println ("No obstacle detected. going forward");
   delay (15);
   motor1.run(FORWARD); //if there's no obstacle ahead, Go Forward!
    motor2.run(FORWARD);  
  }  
  
  

  
  
  
 
}


I have uploaded the code to the Arduino. Upon connecting a 4 AA battery supply to the motor shield and connecting my computer to the Arduino (I do not have a 9V power supply yet so this is just for testing purposes), the Arduino lights up green and orange and the power light on the motor shield also lights up, indicating that they both function. However, there is no observable motion on the DC Motors. I have uploaded pictures but if more information is needed, I will provide. I'd like to fix the issue that is preventing the motors from working. Thank you for your help!

Cactusface

Hi,
     Two problems as I see it! Your using one of the most useless motor driver boards i know and the code that goes with it, AND instructables are well known for being useless. The L293 is very poor at providing power as you lose power in the output transistors, get something using FETS. If you used a normal driver board I could help, but with that code and the AF Library that goes with it leave me clueless.

Take a look at my Robots here. www.melsaunders.co.uk user electronics. I will help it I can...

Regards

Mel.
Open your mind! But not too far, your brains might fall out.
Also like Photography, model building and my 300+ Cacti and Succs.

slipstick

So what are exactly you seeing from all those serial.writes? List the output here. Is it even trying to run the motors? Is the ultrasonic sensor working?

Since that motor driver loses so much voltage you'd have a better chance with a 9V supply or maybe 6 x AA batteries.

Steve

kmshah423

Thank you both for replying. This is the output message upon compiling/uploading:

Code: [Select]

WARNING: Spurious .github folder in 'Adafruit Motor Shield library' library

Sketch uses 4,782 bytes (14%) of program storage space. Maximum is 32,256 bytes.
Global variables use 396 bytes (19%) of dynamic memory, leaving 1,652 bytes for local variables. Maximum is 2,048 bytes.
Invalid library found in C:\Users\kush\Documents\Arduino\libraries\Blink: C:\Users\kush\Documents\Arduino\libraries\Blink
Invalid library found in C:\Users\kush\Documents\Arduino\libraries\Blink: C:\Users\kush\Documents\Arduino\libraries\Blink



I will try to obtain a better motor board or use a 9V power supply. I don't have experience in Arduino code (first robot) but is there anything I should do as far as that is concerned? Also, @Mel, can you elaborate on the term "FETS" I apologize, but I'm quite unfamiliar with the kinds of motor boards available. P.S. You've made some spectacular robots!


kenwood120s

A FET is a type of transistor, usually a MOSFET. A driver made from mosfets won't exhibit the voltage drops that an L293 has. Right now, you'll be losing something like 2V (from my memory, not sure of exact value) so your motors won't be getting the power you think they're getting.

But you didn't answer slipstick: what's the serial monitor saying? I'm not qualified to say if that warning you're getting is preventing a proper upload, but you need to be sure your sketch is actually running. Do you, for example, get the message "Motor test!"?

[gumby]I've got my head stuck in the cupboard[/gumby]

kenwood120s

[gumby]I've got my head stuck in the cupboard[/gumby]

kmshah423

Based on what the serial monitor says below, the motor and ultrasonic sensor appear to be functioning:

Code: [Select]


Motor test!
Close Obstacle detected!
Obstacle Details:
Distance From Robot is 0 CM! The obstacle is declared a threat due to close distance.
 Turning !
No obstacle detected. going forward
No obstacle detected. going forward
No obstacle detected. going forward
No obstacle detected. going forward



Every time I cover the sensor with my hand, the serial monitor will report the distance of my hand to the sensor and report that it is now turning.

slipstick

That's all looking good so now it's just a question of whether the problem is that old motor shield and its library or just the power supply.

Steve

kmshah423

Thank you to everyone for helping me out, your advice is much appreciated. I'll check the power supply first before I acquire another motor board. Is it possible to run the current motor board with a 9V battery and also run the arduino with another 9V battery? I have multiple 9V snap connectors but I don't have a 6 or 4 AA battery pin to plug into the Arduino.

Cactusface

Hi,
    What 9 v batteries are you using? I usually find I can power the motors and the arduino from the same battery pack, but that's usually 4-6 AA good rechargables or even 2 x AA lithiums at 3.7v each, but you need high cacapacity cells. Use the Vin pin to supply the Arduino NOT the 5v in.

Mel.
Open your mind! But not too far, your brains might fall out.
Also like Photography, model building and my 300+ Cacti and Succs.

slipstick

"snap connectors" sounds like those rectangular PP3-style batteries used in smoke detectors etc. They are completely useless for running any sort of motors because they simply can't deliver enough current.

Steve

kmshah423

I meant to use Duracell 9V rectangular batteries using this to connect it to the arduino/motor (See attachments):

https://www.bananarobotics.com/shop/image/cache/data/sku/BR/0/1/0/1/4/BR010140-9V-Battery-Snap-Connector-with-Power-Plug/9V-Battery-Snap-Connector-with-Power-Plug-600x600.JPG

I've heard it can power the arduino but not the motor shield, however, I don't have experience with it so I can't confirm.

I used 6AA carbon-zinc batteries (Panasonic) and hooked it up to the motor shield while using my USB to power arduino, but even 6 could not get the motors to move. I can try a 9V rechargeable NiMH battery, but how can I connect the same battery pack to both the Arduino and the Motor board?

Cactusface

HI kmshah423,
                        I told you just connect 9v to motor sheild and then to the Vin on the Arduino, make sure you connect all common/ground points. Do they still make carbon-zinc batteries their petty useless TOO! As I said you need lots of current to drive the motors, they will perhaps move with less volts as that's not what makes them work, it current, big batteries or a few good one's..

Mel.
Open your mind! But not too far, your brains might fall out.
Also like Photography, model building and my 300+ Cacti and Succs.

Go Up