Go Down

### Topic: Project 09 (Motorized Pinwheel) problem - motor spins forever (Read 16271 times)previous topic - next topic

#### Pando

##### May 29, 2013, 10:24 pm
Hello,

being a student in software development, I am currently learning to program with an Arduino Uno with the Arduino Starter Kit (it is great, by the way !).

I arrived to Project 09 (Motorized Pinwheel) and I run into a problem that may be simple but that I cannot seem to resolve :

I made the circuit according to the drawing in the book, but when I plug the 9V battery to the 9V snap, the motor immediately starts spinning, without stopping.

If I understand well, the goal of this project is to make the motor spin only when we press the switch.
But therefore in my case, it makes nothing (the motor spins, the switch being pressed or not ...).

I really don't understand what I am doing wrong, so I am today asking for your help !
Maybe I didn't understand the real purpose of this project, and/or I'm missing the obvious (I think that's it ! ).

I put a photograph of my circuit in attachment.
Because everything doesn't appear on it : the red and black wires on top right lead to the 9V battery snap and the ones at bottom right lead to the motor (like in the book's circuit drawing).
I believe that it perfectly fits the schema, so I really don't understand !

I also put the sketch I upload to my Arduino, despite the fact that I don't think it changes something...
(it is a complete copy-paste of the book's code, if there is a problem with it, I'm missing the obvious)
Code: [Select]
`const int switchPin = 2;const int motorPin = 9;int  switchState = 0;void  setup() {  pinMode(motorPin, OUTPUT);  pinMode(switchPin, INPUT);}void  loop() {  switchState = digitalRead(switchPin);    if (switchState == HIGH) {    digitalWrite(motorPin, HIGH);  }  else {    digitalWrite(motorPin, LOW);  }}`

Thank you for your time, and bear with me if I'm doing something obviously wrong, I'm a complete beginner at electronics  :~

#### dean_1230

#1
##### May 31, 2013, 02:51 pmLast Edit: Jun 01, 2013, 03:52 pm by dean_1230 Reason: 1
I don't have the book or schematic in front of me, but from the pictures it looks like you're wiring the motor directly to the power.  You have the hot/red wire directly connected to the right-side power strip (assuming that the 9v supply is attached at the top) and you have the black  connecting through the diode to ground.  Where's the "switch" to turn that off?

EDIT (6/1/13)
Am now at home, looking at the diagram it seems that the diode goes to the positive bus, not the negative bus as your picture shows...

#### Pando

#2
##### Jun 02, 2013, 11:23 pmLast Edit: Jun 03, 2013, 07:13 pm by Pando Reason: 1

Well maybe I was wrong on that point, but the thing is that I tried again today (with the diode being at the right place !) and guess what...

Now the motor never spins... =( (I mean in the circuit, if I plug it only in circuit with the 9V battery, it still works)

Actually I think that at my previous attempt, I inverted the battery snap poles, plugging the (-) one to the battery's (+), and vice versa.
It may explain why it was spinning before, and why it isn't now.
The thing is that when I press the button, it still doesn't spin...

I begin to wonder if, during my many manipulations trying to get it to work, I haven't broken something like the transistor.
Especially if, as I think, the current has been reversed at any time.
(If that's it, given that I tried with the two transistors bundled with the kit, they may be both broken   )

By the way this may seem very silly, but, following the book's circuit schema, when they say the metal tab to be "facing away from you", they of course mean that the face with the little black rectangle thing must be facing the Arduino, right ?

I must admit I'm running out of ideas ...  :|

EDIT: After having changed all the pieces of the circuit (push button, transistor, resistor ...) I finally got it to work as expected ! This way, I'm not afraid anymore to have something broken since I know it worked at least once. Thanks for the help !

#### danipisca07

#3
##### Aug 10, 2013, 01:41 amLast Edit: Aug 10, 2013, 11:23 am by danipisca07 Reason: 1
Hi guys.

I'm in the same condition of Pando, I plug the 9v battery and the motor never stop to spin, and I haven't solved the problem changing all the pieces (mosfet, button...) and I have the same code...what I can do to solve?

I tried with the second scheme too, but the result is the same...

#### LuKux

#4
##### Sep 01, 2013, 11:17 am
I tried using pin 8 instead of pin 9 and it worked!
I think it could be a problem in using PWM pin 9...
Another solution could be to use analogWrite(9,255) instead of digitalWrite(9,HIGH) and analogWrite(9,0) instead of digitalWrite(9,LOW).

#### sdragou

#5
##### Sep 17, 2013, 07:36 pmLast Edit: Sep 17, 2013, 07:52 pm by sdragou Reason: 1
I am using the wiring from project09 and analogWrite(PWMpin,speed) to vary the rotation freq of the dc motor...

The problem is that the speed varies from a max (analgWrite(PWMpin,255) to a minimum (analogWrite(PWMpin,0) but it never stops. Even if I write analogWrite(PWMpin,0) it doesn't stop.

Any Idea?

#### Palliser

#6
##### Sep 17, 2013, 08:41 pm
Hello sdragou,

Verify that your PWMpin is not asigned to pins 5 or 6.
According to Arduino's analogWrite 'Notes and Known Issues', see http://arduino.cc/en/Reference/analogWrite

Quote
The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.

If that is your case, then, it explains the behavior of your project. Regards!

P.S. Remember also that the motor slows down for certain amount of seconds.

#### djpd

#7
##### Apr 03, 2014, 06:12 pm
can any body tell me the full name of n-channel mosfet

#### jn-wp

#8
##### Apr 06, 2014, 06:44 pm
should be this one:

http://arduino.cc/documents/datasheets/MOS-irf520npbf.pdf

#### sarizpe

#9
##### Jan 21, 2015, 05:40 am
My transistor was also facing the wrong way and that is why it wouldnt run at all.  The metal tab faces away from the arduino bord, the black box that protrudes outward faces towards arduino.

#### joeclark77

#10
##### Mar 13, 2017, 05:11 pm
I realize this is an old topic, but the problem is apparently perennial because I just experienced it today.  In my case the error was in my copying over of the software.  Where the code should say...

if (switchState == HIGH) {

I had a single equal sign (=) rather than a double equal sign (==).  Instead of a comparison I was making a variable assignment, which always returned TRUE.  It's valid code, so the error wouldn't be caught by the compiler, and it made the motor run under any condition.

Go Up

Please enter a valid email to subscribe

To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy