Let's Make Robots!

My robot don't move !

avoid obstacle
AttachmentSize
vue_face.jpg2.73 MB
DSC_0174.JPG2.54 MB
DSC_0175.JPG3.23 MB

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.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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

impressive. upload a video of it.

I'd suggest simplifying your code as much as possible.

Only use one ultrasound to begin with and just have it display the distance without using it to make decisions.

Just in case you're not ending up with a integer after using this code:

distanceD = (durationD/2) / 29.1;

Try this instead:

distanceD = durationD

Just to be sure you're not having an iteger math problem (sorry, I don't know the Arduino well enough to know if this is a problem or not).

You said you had the motors working but the problem occurred when you added the sensors. So back up to the code that works and add little bits at a time so you know which of the many bits is causing the problem.

 

An idea someone ?

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);
 
}
}

According to your schematic your robot will never move because you are not supplying any power to the motors at all!
The ULN2003 consist of 7 darlinton transistor and all outputs are only switched to ground. They cannot suppy a +V output.

You connected common to +5V but this is only the common of the flyback diodes and is supposed to be connected to ground.

You need to use a propper motor driver such as an L293D or SN754410D. These IC's can switch their output high or low.

I have since realised you are using a motor driver from Yourduino and have drawn your schematic incorrectly. Pressumably your stepper motor is a 5wire motor in which case it will have a common +V wire going to all windings.

You need to draw accurate schematics if you want help.

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.

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.

Alkaline 9V batteries are only designed to put out very low currents for devices like pocket radios or smoke detectors.

A NiMh rechargeable 8.6V version of the batteries is better suited to robots as it will supply higher current and maintain a steady voltage but they still can't hold much power and will quickly go flat.