Go Down

Topic: Working on a robot, need some help with the coding aspect (Read 112 times) previous topic - next topic

Cold_springs_coder

May 23, 2018, 09:40 pm Last Edit: May 23, 2018, 09:51 pm by Cold_springs_coder
Hi there! I'm working on a four-wheeled robot and need it to drive straight, then rotate, and then drive straight again for a certain time and stop. I have most of that taken care of but have no idea how to "stop" it through my code. I'm new to the Arduino game so I could use any help or guidance! Thanks in advance and here's what I have so far:
Code: [Select]
const int inAPin = 6;
const int inBPin = 8;
const int PWMPin = 7;
const int inCPin = 2;
const int inDPin = 4;
const int PWMPin2 = 3;
const int inEPin = A0;
const int inFPin = A1;
const int PWMPin3 = 5;
const int inGPin = A3;
const int inHPin = A2;
const int PWMPin4 = 9;

void setup() {

  pinMode(inAPin, OUTPUT);
  pinMode(inBPin, OUTPUT);
  pinMode(inCPin, OUTPUT);
  pinMode(inDPin, OUTPUT);
  pinMode(inEPin, OUTPUT);
  pinMode(inFPin, OUTPUT);
  pinMode(inGPin, OUTPUT);
  pinMode(inHPin, OUTPUT);
  pinMode(PWMPin, OUTPUT);
  pinMode(PWMPin2, OUTPUT);
  pinMode(PWMPin3, OUTPUT);
  pinMode(PWMPin4, OUTPUT);
}

void loop() {
  int i;

  delay(200);
  digitalWrite(inAPin, HIGH); //
  digitalWrite(inBPin, LOW);
  digitalWrite(inCPin, LOW); //
  digitalWrite(inDPin, HIGH);
  digitalWrite(inEPin, LOW); //
  digitalWrite(inFPin, HIGH);
  digitalWrite(inGPin, LOW); //
  digitalWrite(inHPin, HIGH);

  for (i = 0; i < 175; i++){
     analogWrite(PWMPin, i);
     analogWrite(PWMPin2, i);
     analogWrite(PWMPin3, i);
     analogWrite(PWMPin4, i);
 }
 delay(1500);                         // Stop and rotate

  digitalWrite(inEPin, HIGH); // Wheel 3
  digitalWrite(inFPin, LOW);
  digitalWrite(inCPin, HIGH); // Wheel 1
  digitalWrite(inDPin, LOW);
  digitalWrite(inAPin, HIGH); // Wheel 2
  digitalWrite(inBPin, LOW);
  digitalWrite(inGPin, LOW); // Wheel 4
  digitalWrite(inHPin, HIGH);

  for (i = 0; i < 175; i++){
     analogWrite(PWMPin, i);
     analogWrite(PWMPin2, i);
     analogWrite(PWMPin3, i);
     analogWrite(PWMPin4, i);
 }
 delay(700);                    //~700 millisec for a 90 degree turn
 
  digitalWrite(inAPin, HIGH); //
  digitalWrite(inBPin, LOW);
  digitalWrite(inCPin, LOW); //
  digitalWrite(inDPin, HIGH);
  digitalWrite(inEPin, LOW); //
  digitalWrite(inFPin, HIGH);
  digitalWrite(inGPin, LOW); //
  digitalWrite(inHPin, HIGH);

}

TolpuddleSartre

"I've gone off the idea of progress. It's overrated."
Arthur Dent

Cold_springs_coder


TolpuddleSartre

Turn the speed down to zero (or 255, depending on how it is wired)
"I've gone off the idea of progress. It's overrated."
Arthur Dent

Cold_springs_coder

If you look at the code though, I don't control the speed, just set it as high or low

slipstick

Can you please provide links to your motors and the motor driver(s) you're using and a schematic showing how they're all connected to the Arduino.

I bet there's plenty of information available for the motor driver to tell you how to stop the motors.  But without any information about what you're trying to use there's not a lot we can do.

Steve

Go Up