My robot don't move!

Hello here !

I have a problem on the robot that I just built. The robot moves with the help of two stepper motor and detect obstacles using two sensors Ultrasonic.

For now, the robot should just be able to avoid obstacles. Then I could possibly add floors to add other functions as the return has a base for example.

So I try the robot and... nothing. The robot does not move exept one impulses (step ?) per second and per motor and theserial monitor (which gives me the distance of the two sensors) displays only the value of the left distance, the right distance is always equal to 0. I tested all the components separately with test codes and it all works correctly so no worries on that side.

I wonder if the problem is the robot itself (power, connection, ...) or his code.

So if you have an idea of the source of the probleme, please write it in the comment ;)

Here is the code :

#define trigPinD 2
#define echoPinD 3
#define trigPinG 4
#define echoPinG 5

//declare variables for the motor pins
int motorPin1D = 6;    // Blue   - 28BYJ48 pin 1
int motorPin2D = 7;    // Pink   - 28BYJ48 pin 2
int motorPin3D = 8;    // Yellow - 28BYJ48 pin 3
int motorPin4D = 9;    // Orange - 28BYJ48 pin 4
int motorPin1G = 10;    // Blue   - 28BYJ48 pin 1
int motorPin2G = 11;    // Pink   - 28BYJ48 pin 2
int motorPin3G = 12;    // Yellow - 28BYJ48 pin 3
int motorPin4G = 13;    // Orange - 28BYJ48 pin 4
                                           
// Red    - 28BYJ48 pin 5 (VCC)
                       

int motorSpeed = 1200;  //variable to set stepper speed
int lookupD[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
int lookupG[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
//////////////////////////////////////////////////////////////////////////////
void setup() {
 
//declare the motor pins as outputs
  pinMode
(trigPinD, OUTPUT);
  pinMode
(echoPinD, INPUT);
  pinMode
(trigPinG, OUTPUT);
  pinMode
(echoPinG, INPUT);
  pinMode
(motorPin1D, OUTPUT);
  pinMode
(motorPin2D, OUTPUT);
  pinMode
(motorPin3D, OUTPUT);
  pinMode
(motorPin4D, OUTPUT);
  pinMode
(motorPin1G, OUTPUT);
  pinMode
(motorPin2G, OUTPUT);
  pinMode
(motorPin3G, OUTPUT);
  pinMode
(motorPin4G, OUTPUT);
 
Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){
 
int durationD, distanceD;
  digitalWrite
(trigPinD, LOW);
  delayMicroseconds
(2);
  digitalWrite
(trigPinD, HIGH);
  delayMicroseconds
(10);
  digitalWrite
(trigPinD, LOW);
  durationD
= pulseIn(echoPinD, HIGH);
  distanceD
= (durationD/2) / 29.1;
   
Serial.print(distanceD);
   
Serial.println(" cm droit");
   
   
int durationG, distanceG;
  digitalWrite
(trigPinG, LOW);
  delayMicroseconds
(2);
  digitalWrite
(trigPinG, HIGH);
  delayMicroseconds
(10);
  digitalWrite
(trigPinG, LOW);
  durationG
= pulseIn(echoPinG, HIGH);
  distanceG
= (durationG/2) / 29.1;
   
Serial.print(distanceG);
   
Serial.println(" cm gauch e");
   
   
   
if (distanceG < 10 ){
   clockwiseG
();
   anticlockwiseD
();
   
}
   
else if ( distanceD < 10 ){
   anticlockwiseG
();
   clockwiseD
();
   
}
   
else {
   clockwiseD
();
   clockwiseG
();
   
}
   
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)
void anticlockwiseD(){

 
for(int iD = 0; iD < 8; iD++)
 
{
    setOutputD
(iD);
    delayMicroseconds
(motorSpeed);
 
}
 
}

void clockwiseD(){

 
for(int iD = 7; iD >= 0; iD--)
 
{
    setOutputD
(iD);
    delayMicroseconds
(motorSpeed);
 
}
}
 
 
void anticlockwiseG(){

 
for(int iG = 0; iG < 8; iG++)
 
{
    setOutputG
(iG);
    delayMicroseconds
(motorSpeed);
 
}
}

void clockwiseG(){

 
for(int iG = 7; iG >= 0; iG--)
 
{
    setOutputG
(iG);
    delayMicroseconds
(motorSpeed);
 
}
 
}

void setOutputD(int out){

  digitalWrite
(motorPin1D, bitRead(lookupD[out], 0));
  digitalWrite
(motorPin2D, bitRead(lookupD[out], 1));
  digitalWrite
(motorPin3D, bitRead(lookupD[out], 2));
  digitalWrite
(motorPin4D, bitRead(lookupD[out], 3));
}

 
void setOutputG(int out){

  digitalWrite
(motorPin1G, bitRead(lookupG[out], 0));
  digitalWrite
(motorPin2G, bitRead(lookupG[out], 1));
  digitalWrite
(motorPin3G, bitRead(lookupG[out], 2));
  digitalWrite
(motorPin4G, bitRead(lookupG[out], 3));
}

 

 

 

 

I try this code with only one motor and one sensor. The result was a bit better because it turned (very slowly and stopping random ways) and he has a better react to the detection of obstacles.

Sorry for spelling, i'm french ;)

thank, Théo.

avoid obstacle

  • CPU: arduino uno
  • Power source: USB for the moment
  • Sensors / input devices: ultrasonic HC-SR04 sensors

This is a companion discussion topic for the original entry at https://community.robotshop.com/robots/show/my-robot-dont-move

I would check you have good

I would check you have good power in your batteries.  I also note that you have said nothing about motor drivers.  The Arduino cannot provide enough power through it’s own pins to drive a motor - you may destroy at least part of you microcontroller (mc) if you try to do so.  The pins on the mc can only provide around 20ma maximum.

Re: motor driver

If you read thorugh his code, you will see a comment about the ULN2003.

PeteH makes a good point about batteries.

Looking at all your pics, and, reading your post shows no sign of you using any batteries. Your USB port can only supply 500mA at best. Steppers are current driven rather than voltage driven.

So the solution is to

So the solution is to increase the power of the battery and connect the controller of my motor directly to the battery ?

But what kind of batterie should i use ? I have 1500mah 20C 11.1V LIPO battery, are they adapted or will they burn my arduino ?

 

Here is my motor and controller http://www.miniinthebox.com/fr/l-electronique-automobile-et-le-bricolage-5v-moteur-pas-a-pas-avec-chauffeur-uln2003_p340890.html

Stepper motor

I have the same motors, and I made some tests. This motor contains gearbox, and therefore their output steps are too small. Try change motorSpeed = 5.

I’ve test with the

I’ve test with the “setspeed” set to 5 and the robot don’t move at all with this setting. If you have the same motor, can you pass me your code please ? :slight_smile:

Here is the schematics

|x

Switch the middle 2!!

You are using the little $5 stepper motors. The 2 middle pins need to be swapped either physically or via your code. This is just the way the steppers work. I personally would keep your stepper wiring the same, A,B,C,D and change your code.

 

I have made the modification needed in the code below. Cut and paste this, change nothing else, and it will work. (Probably)

int motorPin1D = 6;    // Blue   - 28BYJ48 pin 1
int motorPin2D = 8;    // Pink   - 28BYJ48 pin 2
int motorPin3D = 7;    // Yellow - 28BYJ48 pin 3
int motorPin4D = 9;    // Orange - 28BYJ48 pin 4
int motorPin1G = 10;    // Blue   - 28BYJ48 pin 1
int motorPin2G = 12;    // Pink   - 28BYJ48 pin 2
int motorPin3G = 11;    // Yellow - 28BYJ48 pin 3
int motorPin4G = 13;    // Orange - 28BYJ48 pin 4

I’ve already test all the

I’ve already test all the compnent separetly and it work correctly.

the LED on the controller will not turn all when it is running, only 2 or 3 are lit on each controller and they turns off randomly.


After having switching the middle, the motors  began to spin but very choppy manner and with no reaction of the obstacle detection. But i feel we are on the right track :slight_smile:

Here is the code which work perfectly with my motor :

//declare variables for the motor pins
int motorPin1 = 8;    // Blue   - 28BYJ48 pin 1
int motorPin2 = 9;    // Pink   - 28BYJ48 pin 2
int motorPin3 = 10;    // Yellow - 28BYJ48 pin 3
int motorPin4 = 11;    // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

int motorSpeed = 1200;  //variable to set stepper speed
int count = 0;          // count of steps made
int countsperrev = 512; // number of steps per full revolution
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};

//////////////////////////////////////////////////////////////////////////////
void setup() {
  //declare the motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){
  if(count < countsperrev )
    clockwise();
  else if (count == countsperrev * 2)
    count = 0;
  else
    anticlockwise();
  count++;
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay “motorSpeed” between each pin setting (to determine speed)
void anticlockwise()
{
  for(int i = 0; i < 8; i++)
  {
    setOutput(i);
    delayMicroseconds(motorSpeed);
  }
}

void clockwise()
{
  for(int i = 7; i >= 0; i–)
  {
    setOutput(i);
    delayMicroseconds(motorSpeed);
  }
}

void setOutput(int out)
{
  digitalWrite(motorPin1, bitRead(lookup[out], 0));
  digitalWrite(motorPin2, bitRead(lookup[out], 1));
  digitalWrite(motorPin3, bitRead(lookup[out], 2));
  digitalWrite(motorPin4, bitRead(lookup[out], 3));
}

 

I know my explanation is not very precise but I have a bit of trouble with the English ^^

Thank for your help :slight_smile:

Question…

I just figured out that you are stepping this motor manually. Is there any reason you are not using the built-in stepper commands?

You want to say the exemple

You want to say the exemple in the arduino librairie  ?

I don’t use those exemple because they not work correctly with my motor and make my motor very jerky and also very slow.

I take back what I said, I

I take back what I said, I just try an example of arduino library (motorknob) and it work really well :wink:

Nice Robot

Your robot looks good. The 5v steppers and drivers are the same as I use in my robot stEve, though he is yet to receive any sensors. I had stEve running off 9v batteries [hides from OddBot’s wrath] however he wouldn’t last very long (they don’t hold enough charge as they are intended for high voltage (compared to 1.5v batteries) and low current applications (such as smoke detectors). I’m in the process of swapping out the 9v battery for 6 x 1.5v AA batteries. When the voltage drops low enough on the 9v battery the arduino resets, which is only detectable on my robot because he starts playing his tune from the start again with each reset.

I’ve just creat a code who

I’ve just creat a code who make my motors turn really good. But after i added code to the function to recover the distance of the sensor, the motors stopped spinning and the monitor serial display 0 cm all the time.

So I think the problem come from the compatibility between the motor and sensors code.

Well, I came back with all

Well, I came back with all new fresh.

I realized there was an easier way to control my motors with arduino library for examples.

 
So I revised my code with one of these example (MotorSpeed​​). So I, thanks to this, I believed that solved the problem of my motor that do not run because it is turned them both.

So I then add the code to retrieves the distance between the two sensors and, nothing more, the motors restart to not move and the monitor series to display 0 cm for each distances.


Someone have an idea?


Here is the code who run my motor properly:

 

 int motorSpeedgauche = 50;
int motorSpeeddroit = 50 ;
const int trigPinD = 2;
const int echoPinD = 3;
const int trigPinG = 4;
const int echoPinG = 5;

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution



// initialize the stepper library on pins 8 through 11:
Stepper myStepperdroit(stepsPerRevolution, 10,11,12,13);  
Stepper mySteppergauche(stepsPerRevolution, 6,7,8,9);

int stepCount = 0;  // number of steps the motor has taken

void setup()
{
 
Serial.begin(9600);
}

void loop() {
 
if (motorSpeeddroit > 0)
 
 
{
    myStepperdroit
.setSpeed(motorSpeeddroit);
   
// step 1/100 of a revolution:
    myStepperdroit
.step(stepsPerRevolution/100);
 
}
   

 
if (motorSpeedgauche > 0)
 
 
{
    mySteppergauche
.setSpeed(motorSpeedgauche);
   
// step 1/100 of a revolution:
    mySteppergauche
.step(stepsPerRevolution/100);
 
}
}

here is the link for your

here is the link for your motors and spec

http://www.emartee.com/product/41886/28BYJ%2048%20High%20Quality%20Stepper%20Motor%205V

An idea someone ?

An idea someone ?

Hi Theo,Ensure that you

Hi Theo,

Ensure that you switch the ping sensor pinMode to a read when you are waiting for the echo pulse. It looks like you send out a 10uS pulse but the arduino pin is still regestered as an output when you are reading back.

Clive