Arduino Forum

Using Arduino => Project Guidance => Topic started by: Yovan10 on Oct 11, 2018, 03:40 pm

Title: I'm confused with my motors
Post by: Yovan10 on Oct 11, 2018, 03:40 pm
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
Title: Re: I'm confused with my motors
Post by: Delta_G on Oct 11, 2018, 03:47 pm
OP's picture fixed so you can see it. 

(http://forum.arduino.cc/index.php?action=dlattach;topic=572999.0;attach=277469)
Title: Re: I'm confused with my motors
Post by: Yovan10 on Oct 11, 2018, 04:42 pm
Pls tell me what could be the reason
Title: Re: I'm confused with my motors
Post by: groundFungus on Oct 11, 2018, 05:05 pm
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.
Title: Re: I'm confused with my motors
Post by: Yovan10 on Oct 11, 2018, 05:44 pm
Yeah you are right.

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

how to save power in the circuit
Title: Re: I'm confused with my motors
Post by: jremington on Oct 11, 2018, 05:48 pm
9V block batteries are totally unsuitable for motors.

A 6xAA battery pack should work, at least for a while.
Title: Re: I'm confused with my motors
Post by: groundFungus on Oct 11, 2018, 05:52 pm
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.
Title: Re: I'm confused with my motors
Post by: Yovan10 on Oct 12, 2018, 03:42 am
Can you tell me a way to give separate power supply to the motors and separate to the others

Thanks Bro for the help
Title: Re: I'm confused with my motors
Post by: Yovan10 on Oct 12, 2018, 04:17 am
Should I use 12 AA(each 1.5V) batteries for the power supply???

or 6AA is enough??

pls answer me bro... :)  :)
Title: Re: I'm confused with my motors
Post by: jremington on Oct 12, 2018, 04:19 am
Quote
please supply a data sheet for the motors.
Title: Re: I'm confused with my motors
Post by: Yovan10 on Oct 12, 2018, 04:28 am
I don't know what's a datasheet pls explain me bro...:(:(

What can I do with it. 
Pls help me in this regard
Title: Re: I'm confused with my motors
Post by: groundFungus on Oct 12, 2018, 04:35 am
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.
Title: Re: I'm confused with my motors
Post by: Yovan10 on Oct 12, 2018, 04:43 am
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
Title: Re: I'm confused with my motors
Post by: ChrisTenone on Oct 12, 2018, 08:10 am
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.
Title: Re: I'm confused with my motors
Post by: Delta_G on Oct 12, 2018, 04:26 pm
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. 
Title: Re: I'm confused with my motors
Post by: jremington on Oct 12, 2018, 04:51 pm
Post a link to the product page for the motors, or the robot.

For helpful hints on how to get useful advice from this forum, please read the "How to use this forum" link.
Title: Re: I'm confused with my motors
Post by: Yovan10 on Oct 12, 2018, 08:20 pm
Sure..

Thanks for the comment..

I'll follow it in the forum here afterwards...

Any clue about my problem???

I bought them from amazon.. They are 150 RPM dual shaft motors...

Do you need any other information...?
Title: Re: I'm confused with my motors
Post by: jremington on Oct 12, 2018, 09:47 pm
What part of "post a link to the product page for the motors" don't you understand?