Go Down

Topic: I'm confused with my motors (Read 323 times) previous topic - next topic

Yovan10

I'm doing my robot.I have done everything right.
I have attached my circuit below

This is my code:
Code: [Select]
const byte enA = 9;//defining the pins for usage
const byte in1 = 4;
const byte in2 = 5;
const byte enB = 11;
const byte in3 = 6;
const byte in4 = 7;

int val = 0;//The Values recieved by the Bluetooth is assigned to this variable
int starttime = 0;//For running a command for desired secs
int endtime = 0;//        ""

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  //Read input from bluetooth module:
  if ( Serial.available())
  {
    val = Serial.read();
  }


  //Input key switch
  switch (val) {
    case '0':
      analogWrite(enA, 0);//controls speed
      analogWrite(enB, 0);
      //Code when no key is pressed
      break;
    case '1':
      // Set Motor A Forward
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      // Set Motor B Forward
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
      starttime = millis();
      endtime = starttime;
      while ((endtime - starttime) <= 3000) // do this loop for up to 1000mS
      {
        // code here
        analogWrite(enA, 250);
        analogWrite(enB, 250);
        Serial.println("<Forward>");
        endtime = millis();
      }
      analogWrite(enA, 0);
      analogWrite(enB, 0);

      //Code when DOWN key is pressed
      Serial.println("<Forward>");
      break;
    case '2':
      // Set Motor A backward
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      // Set Motor B backward
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      starttime = millis();
      endtime = starttime;
      while ((endtime - starttime) <= 3000) // do this loop for up to 1000mS
      {
        // code here
        analogWrite(enA, 250);
        analogWrite(enB, 250);
        Serial.println("<Backward>");
        endtime = millis();
      }
      analogWrite(enA, 0);
      analogWrite(enB, 0);

      //Code when DOWN key is pressed
      Serial.println("<Backward>");
      break;
    case '3':
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
       starttime = millis();
      endtime = starttime;
      while ((endtime - starttime) <= 3000) // do this loop for up to 1000mS
      {
        // code here
          analogWrite(enA, 200);
          analogWrite(enB, 200);
          Serial.println("<Left>");
        endtime = millis();
      }
      analogWrite(enA, 0);
      analogWrite(enB, 0);
      Serial.println("<Left>");
      //Code when LEFT key is pressed
      break;
    case '4':
      //Code when RIGHT key is pressed
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
       starttime = millis();
      endtime = starttime;
      while ((endtime - starttime) <= 3000) // do this loop for up to 1000mS
      {
        // code here
          analogWrite(enA, 200);
          analogWrite(enB, 200);
          Serial.println("<Right>");
        endtime = millis();
      }
      analogWrite(enA, 0);
      analogWrite(enB, 0);
      Serial.println("<right>");
      break;
    case '5':
      //Code when X key is pressed
       starttime = millis();
      endtime = starttime;
      while ((endtime - starttime) <= 1000) // do this loop for up to 1000mS
      {
        // code here
          analogWrite(enA, 0);
          analogWrite(enB, 200);
          Serial.println("<Drift left>");
        endtime = millis();
      }
      analogWrite(enA, 0);
      analogWrite(enB, 0);
      break;
    case '6':
    starttime = millis();
      endtime = starttime;
      while ((endtime - starttime) <= 1000) // do this loop for up to 1000mS
      {
        // code here
          analogWrite(enA, 200);
          analogWrite(enB, 0);
          Serial.println("<Drift right>");
        endtime = millis();
      }
      analogWrite(enA, 0);
      analogWrite(enB, 0);
      //Code when O key is pressed
     
      break;
    default:
    starttime = millis();
      endtime = starttime;
      while ((endtime - starttime) <= 1000) // do this loop for up to 1000mS
      {
        // code here
          analogWrite(enA, 0);
          analogWrite(enB, 0);
        endtime = millis();
      }
      analogWrite(enA, 0);
      analogWrite(enB, 0);
     
      // default code (should never run)
  }
}


The problem is that One of my motors run both sides and another that is the motor connected to my OUT 3 and 4 Does'nt run forward

I'm supplying a voltage of 18V(2 9V batteries)

What could be wrong?

pls help me

Delta_G

OP's picture fixed so you can see it. 

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Yovan10

Pls tell me what could be the reason

groundFungus

Quote
I'm supplying a voltage of 18V(2 9V batteries)
Are the 9V batteries those small rectangular ones made for smoke alarms?  Your diagram shows 12V.

Yovan10

Yeah you are right.

Also suggest me another way, my battery gets drained faster.

how to save power in the circuit

jremington

9V block batteries are totally unsuitable for motors.

A 6xAA battery pack should work, at least for a while.

groundFungus

You need batteries (or other power supply) that can deliver the motor's rated voltage to the motors and the stall current of the motors (X2 current  if both motors are to start at once).  There is no way around that.  9V transistor batteries will never supply enough current.

If you are concerned with saving power, get rid of that L298 and get a proper modern motor driver.

If you want help to choose a driver, please supply a data sheet for the motors.

Yovan10

Can you tell me a way to give separate power supply to the motors and separate to the others

Thanks Bro for the help

Yovan10

Should I use 12 AA(each 1.5V) batteries for the power supply???

or 6AA is enough??

pls answer me bro... :)  :)

jremington

Quote
please supply a data sheet for the motors.

Yovan10

I don't know what's a datasheet pls explain me bro...:(:(

What can I do with it. 
Pls help me in this regard

groundFungus

A data sheet for a part is where you find detailed specifications for the part.  Do you know the part number of the motor?   If not, post any numbers written on the motor and we can try to find a data sheet.  We need to know the motor's rated voltage and the stall current.

Yovan10

The Motors Rated Voltage is 5V-9V

I have a number written on it.

2016301077161

I don't what this means but This is only number on it

Thanks for the reply

ChrisTenone

Where did you get the motors, where did you find the circuit? Show a picture of the motors if you found them in a basket at your front door. Folks need to know more about your specific hardware if you want them to help you design your robot.

ps, just for good measure, don't say "pls", say "please", and not so often. And don't call us bro. We aren't your brother, nor are we in a 1973 crime drama.
Atmosphere carries combustion vapors to places where they will do good instead of harm - Mike Faraday's 'History of a Candle': https://www.youtube.com/watch?v=6W0MHZ4jb4A

Whoops ::)

Delta_G

Quote
ps, just for good measure, don't say "pls", say "please", and not so often. And don't call us bro. We aren't your brother, nor are we in a 1973 crime drama.
+1.  People are volunteering to help you for free.  Please show them at least a little respect and speak like you have a little bit of education and care at least a little. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up