Project 09 Motorized Pinwheel - Motor spins continuously

Hi, I decided to have a job at Project 9 in the starter kit. But not having great success with it. I'm using the code in it's original form (included below).

  • I can make the motor spin continuously (i.e. with no interaction from the switch, and the switch does nothing when pressed), but only when the battery wires are placed the opposite way around. It does nothing when they are connected the normal way, though I swear I had it running that way the other day (again spinning continuously)

  • After only a few seconds of spinning there is a notably smell of burning in the air. The battery is hot, and the MOSFET is burning to the touch (I cannot pick it up until it cools off.)

//Introducing the constants of the switch and the motor
const int switchPin=2;
const int motorPin=9;
int switchState=0;

void setup() {
 //Selecting as an input and output the switch and the motor
 pinMode(switchPin,INPUT);
 pinMode(motorPin,OUTPUT);
}

void loop() {
 //Reading if the switch has been pushed
 switchState=digitalRead(switchPin);
 if(switchState==HIGH){
   //If the switch has been pushed make the motor spin
   digitalWrite(motorPin,HIGH);
 }
 else{
   //If the switch hasn't been pushed don't make the motor spin
   digitalWrite(motorPin,LOW);    
 }
}

I'm pretty new to all this, so would appreciate any help.

Also with the diodes, if i connect the battery backwards, shouldn't just nothing happen on the motor?

Hi, @epideme
Have you got the 9V battery connected to the protoboard the correct way around,
It looks like the 9V battery red goes to negative and the black goes to positive.
A picture from the other side would help.
Can you post a picture of the Project 09 please, there are many tutorial kits and each is different.

Thanks Tom... :smiley: :+1: :coffee: :australia:

1 Like

Hi Tom, thanks for getting back to me.

It's basically this project. The picture used is

I've connected the battery the normal way, as suggested, nothing happens, motor doesn't spin and the MOSFET & Battery aren't getting worryingly hot


Picture from the other side.

Hi,
Thanks for the images.
Try this code, I have added the LED that is on the UNO board.
When you press the button, it should come ON.

//Introducing the constants of the switch and the motor
const int switchPin = 2;
const int motorPin = 9;
const int LEDPin = 13;
int switchState = 0;

void setup()
{
  //Selecting as an input and output the switch and the motor
  pinMode(switchPin, INPUT);
  pinMode(motorPin, OUTPUT);
  pinMode(LEDPin , OUTPUT);
}

void loop()
{
  //Reading if the switch has been pushed
  switchState = digitalRead(switchPin);
  if (switchState == HIGH)
  {
    //If the switch has been pushed make the motor spin
    digitalWrite(motorPin, HIGH);
    digitalWrite(LEDPin, HIGH);
  }
  else
  {
    //If the switch hasn't been pushed don't make the motor spin
    digitalWrite(motorPin, LOW);
    digitalWrite(LEDPin, LOW);
  }
}

To add code please click this link;

Tom... :smiley: :+1: :coffee: :australia:

Definitely getting closer.
With the battery connected normally... The motor did not spin and the LED did not light, until the switch was pressed, then the light lit and the motor spin (more vigourously than previously). The MOSFET and battery stayed cold too. The motor / LED stayed on even when the switch wasn't depressed, and hitting it again did not stop it either. Disconnecting the battery stops the motor but not the LED, and the motor resumes spinning without the interaction from the switch as soon as the battery is reconnected.

Strangely, if the battery is connected backwards as before, the exact same behaviour as above is observed but the motor spins slower (and the opposite direction as expected)

Also worth mentioning I had to add one } at the end of the code for it to compile

Hi,
Good, it sounds like you have a loose wire or something like that in the press button to pin 2 circuit.

Make sure the legs of the button are in contact with the sockets of the protoboard.
You could remove the button and use a piece of jumper the act as the switch, to open and close the circuit.

Do you have a Digital Multimeter?

Tom... :smiley: :+1: :coffee: :australia:

Worst. Introductory. Tutorial. Ever

Removing the switch and replacing it with a jumper cable results in the LED and motor coming on. Removing the jumper cable, the motor and LED stay working. So I guess I would infer the switch is not part of the circuit in some way.

I do somewhere.

Ha. Is this one known to be a problem?

Hi,
Check that the jumper from the UNO gnd pin is working and connected properly to the protoboard.
Also check that the 10K resistor is also plugged in?
Check the orange jumper that goes form the gnd rail to the resistor, make sure it is connecting properly.

Tom... :smiley::+1: :coffee: :australia:

GND pin to board is as good as it's going to get, none of those clip wires are especially snug fits, but they all make good contact.
10K resistor is plugged in and I can lift up the entire board by it
Orange jumper that goes from resistor to the - GND rail is plugged in pretty tight and makes good contact
Bit of a mystery to me. It looks like it SHOULD work, it just... doesn't.

Hi,
Okay, try this.
Lift the yellow jumper you have connected to pin2 off the protoboard and connect it to the 5V rail on the protoboard, then the gnd on the protoboard.
So you will be switching pin2 from +5V to gnd, this should make the motor start and stop.

Tom... :smiley: :+1: :coffee: :australia:

No, but you could flag it and ask a moderator to move it to a more appropriate section of the forum.

With the yellow jumper in 5V: Motor stopped
With the yellow jumper in GND: Motor spins (and remains spinning even when yellow jumper is removed
With the yellow jumper in 5V, and the black jumper in GND: Motor spins, and stops when black jumper is removed, but continues when yellow jumper is removed and black is still in GND
With yellow jumper in GND, and red jumper in 5V: motor spins, and continues spinning with either or both disconnected
With the yellow jumper in GND, and black jumper in 5V: motor does not spin
with the yellow jumper in 5V, and the red jumper in GND: motor does not spin
With no jumpers at all in: Motor spins continuously.

Ah sorry, did I put it in the wrong place?
I'm a bit confused, why in particular is this one a bad tutorial if it's not a problematic one?

Hi,
As per this image.


We are getting there..
Tom... :smiley: :+1: :coffee: :australia:

With the yellow removed from row 7, motor spins without need to be switched the first time. Replacing it into the + and - columns makes no difference, motor continues to spin at the same rate

Hi,
It sounds like you have no gnd connection to the protoboard.
Instead of connecting the yellow to the protoboard gnd, connect to the UNO gnd.
+5V should make the motor spin, gnd should make it stop, same with the LED.

Tom.. :smiley: :+1: :coffee: :australia:

Is this the same as the results in post #15?

Replacing black wire in UNO GND with yellow, momentarily makes the motor slow down, then it accelerates back up to speed, and sounds like it continues to accelerate past what it was before, but not sure on that

Replacing red wire in UNO 5V with yellow, motor spins continuous as before

With both GND and 5V disconnected, motor still spins