I am using two DC motors for my robot project. I have been trying to experiment with motor controls. but one thing that I couldn't figure out is something like initialization. when you first start the robot, it is moving very fast for one sec without any control. then my program starts.
I don't know what is happening. it tried stop the motors in the SETUP() function. but it didn't work.
I appreciate if you can help to make it stop initially. then move it according to my program.
Hey Farhad- post the code please and a description / schematic of the arrangement.
Seems the power to the motor is "on" by default before you get hold of it by getting a pin under your control... show us how it's hooked up and coded in the sketch.
On mine for example, the motors are off because I set the PWM value as 0 in setup, then only enable each motor (via the 298 shield) when I click the tv remote to start moving.
Thanks for the reply, I am not using any shields, there is a board already designed and I barely understand it because it is all missed up with wires like Spagati. I was giving this board to work on. I don't even have the circuit diagram.
as you said, I tried to off the power of the motor by setting the PWM value to 0. but it still doesnt work. my code is some thing like:
Do away with the board for a while, and hook some LEDs (with series resistors) up to the Arduino pins. Then you should see if the LEDs light up bright at startup (which would be analogous to full PWM speed for the motor) until they fall under your control.
Might need to put some delays in so you can actually see the LED flash 8)
(Don't hook the motors up to the Arduino pins tho.... the current draw may be too much and the back emf when they power off may fry the pin unless you use a diode to prevent that... but motors on uC pins seems not to be a good idea)
Yea, you are right, I am gona try it without the board today.
I think, there is something wrong as I noticed that it does it during the Arduino Boot process. when the arduino starts it starts my code. but before that its power is on by default.
do you think it is possible to turn if off before the Arduino booting process.
Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as inputs with pinMode(). Pins configured as inputs are said to be in a high-impedance state. One way of explaining this is that input pins make extremely small demands on the circuit that they are sampling, say equivalent to a series resistor of 100 megohm in front of the pin. This means that it takes very little current to move the input pin from one state to another, and can make the pins useful for such tasks as implementing a capacitive touch sensor, reading an LED as a photodiode, or reading an analog sensor with a scheme such as RCTime.
or in other words, it aint doing crap for output ]
You failing to understand what Osgeld said. The delay is while the boot loader looks for a down load. During that time all arduino pins are inputs. This means that they can float to a state which will turn on your motor driver. If you don't know the circuit then you don't stand a hope in hell of fixing it. It normally involves a pull up or pull down resistor.
I think I found the problem, it is not with the sketch. It is something to do with the board because the board turns the motors on. After a while the motors stops because Arduino gets control and I have analog(pin, 0) inside setup block. I think it is only happening during Arduinos boot up.
As Grumpy_Mike said, I have got to make some changes on the board. Can you guys provide a simple example or any clues how to use a pull up and pull down resister. A simple circuit diagram or anything you can help me to fix this. Where to use resistor. I just want to cut the motors power until Arduino is ready to control the motors.
Can you guys provide a simple example or any clues how to use a pull up and pull down resister.
No you only use EITHER a pull up OR a pull down.
It is simply a resistor from the output pin to 5V - That's pull up or ground that's pull down.
BUT
You need to know how your board is controlling the motor driver. If a logic HIGH turns on the motor then you need a pull down, if a logic LOW turns on the motor then you need a pull up.
Start off with 4K7 resistors but you might have to drop as low as 560R