Go Down

Topic: loopin and controlling rotation ,direction od dc motor (Read 241 times) previous topic - next topic

sidharthsp66

hii
    I am new here with Arduino,i want to control a dc motor to make a climbing robot.
so i want to make the motor rotate 5 times in forward direction then 5 times in backward direction like a loop.when i pre the forward button it must move like this simultaneously. also I want to control this with Bluetooth module.

    i don't no how to program this.

 i have L293D motor driver,Arduino Leonardo, 12v dc motor,Bluetooth module

UKHeliBob

Have you got any way of measuring the rotation of the motor so that you can know when it has rotated 5 times ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

sidharthsp66

Hii
  i am new with arduino and i know only little c language, so can u friends help me to program arduino..?

  I want to rotate a dc motor for 5 times in forward direction and 5 time times in backward direction..
this must run until i press forward button
it must rotate forward and backward like a loop.
  I also want to control it with Bluetooth module and mobile
I have an Arduino Leonardo,HC-05 Bluetooth module,L293D motor driver

How to program this..

UKHeliBob

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

boylesg

First of all you will need a motor control shield for your Arduino.

Here are a couple of options:

https://www.ebay.com.au/itm/Motor-Drive-Expansion-Shield-Board-Module-L293D-For-Arduino-Duemilanove-Mega-UNO/232477741025?epid=591957487&hash=item3620c0cfe1:g:j6MAAOSwTUVZroam

https://www.ebay.com.au/itm/Dual-Channel-Motor-Driver-Shield-L298P-DC-Stepper-Driver-Board-For-Arduino/232418638558?hash=item361d3afade:g:JY0AAOSwgDRZcb0e

And the following is one of the example sketches from the Adafruit motor shield library.....the code should be fairly self explanatory.

Code: [Select]
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>

AF_DCMotor motor(4);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");

  // turn on motor
  motor.setSpeed(200);
 
  motor.run(RELEASE);
}

void loop() {
  uint8_t i;
 
  Serial.print("tick");
 
  motor.run(FORWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i); 
    delay(10);
 }
 
  for (i=255; i!=0; i--) {
    motor.setSpeed(i); 
    delay(10);
 }
 
  Serial.print("tock");

  motor.run(BACKWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i); 
    delay(10);
 }
 
  for (i=255; i!=0; i--) {
    motor.setSpeed(i); 
    delay(10);
 }
 

  Serial.print("tech");
  motor.run(RELEASE);
  delay(1000);
}

pert

I've merged your cross posts @sidharthsp66.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

sidharthsp66


UKHeliBob

There are a number of ways ranging from a switch that is activated each time the motor shaft passes a particular spot, detecting a mark on the shaft by optical sensor, detecting a magnet fixed to the shaft, detecting a slot or slots in a wheel attached to the output shaft, using a rotary encoder attached to the shaft, using a servo motor to move the shaft a fixed number of degrees and using a stepper motor.

What you cannot do is to rotate the output for a fixed time and hope that it will always move a fixed angle.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

sidharthsp66

then can i rotate motor forward for 10 sec and backward 10 seconds

UKHeliBob

then can i rotate motor forward for 10 sec and backward 10 seconds

Does it actually matter how much the motor rotates in the given time ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

sidharthsp66

i am using arduino leonardo AFmotor.h isnt working on it

UKHeliBob

How is it wired, how are the motors powered and what code are you using ?

What does
Quote
isnt working
mean exactly ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

sidharthsp66

i made it in circuit.io
i have attached the file


UKHeliBob

You have not said what isn't working

Where are the motors and servos are powered from ?
The picture that you provided is practically useless
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up