motor control

hi, i followed this tutorial to control 12V DC motor. Arduino Playground - HomePage
Although it is for solenoid control, i thought the basic principle of controlling is same. so i applied it to motor control and it worked fine when i connected it to another arduino which has been uploaded with blinking LED sketch--http://www.arduino.cc/en/Tutorial/Blink
the motor was slowly rotating when digital pin #13 isn't blinking and rotated fast when it's blinking.
Questino 1) why the motor gets slowly rotated even though the digital pin is not in a HIGH state?
Is this because of the current the motor draws from the power supply?

Also, i tried to control the motor differently. This time, using conditional statements.

void loop(){
  val = analogRead(0);        
  if (val > 1 && < 20)
  {
    digitalWrite(3, HIGH);
    delay(1000);
    digitalWrite(3, LOW);
    delay(1000);
  } 
  else if (val < 30) {
    digitalWrite(5, HIGH);
    delay(1000);
    digitalWrite(5, LOW);
    delay(1000);
  }

when those conditions meet, the arduino which has this sketch uploaded makes another arduino's digital pin 13 get HIGH. So, this time, those two arduinos have conditional statements in their program. But, the motor rotates fast when the digital pin #13 is in a LOW state and rotates slowly when the pin is in a HIGH state.
so, it's the opposite situation. i want the motor not to be rotated when the input pin is in a LOW state and rotated when it is in a HIGH state.
i made the hardware connections like this.
Imgur
Imgur
Imgur
Imgur
can anyone advise me what's the reason?

Wish I could give you an answer. I took a look at your pics, and it looks like you are using a tip120.

Here is a tutorial on motor control with a tip120, I think the circuit is simpler than the one you are using.

http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads

your diode also looks to be backwards, and the motor doesn't look to be connected in the right place... I might be just mnisreading your pictures, but it would not hurt to double-check.

D

when the digital pin #13 doesn't get HIGH, the motor continuosly spins but when the digital pin #13 gets HIGH and LOW per delay(1000), it slows down the motor's speed significantly for 1000 mili sec and start to spin fast for 1000.
so, this is not what i want to achieve. i want the motor or solenoid keep calm until one of arduino's assigned output digital pin gets HIGH.
Isn't there more efficient sketch to try this tutorial?

It sound like the delay() function is messing with the timer for the PWM.

It might be a general problem with the Arduino software ????

Has anybody else had a similar problem ?

Hi. how should i make a sketch for PWM to control the speed of motors?

If you already have a H bridge, then just connect one of teh PWM pins where you would connect the digital pin to the H bridge. Then use AnalogWrite(pinnumber, xxx) substitute xxxwith a value in the range 0 - 255

If you only need control of speed, (no direction) you can make a simpler circuit like this :

http://www.tigoe.net/pcomp/code/category/code/picbasic-pro/62

Just connect the PWM pin to the base of the transistor.