Project 09 (Motorized Pinwheel) problem - motor spins forever

Pando:
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 ! :slight_smile: ).

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)

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 :~

So this is my first post in this forum, Horray!
Fanfare aside....

One thing I noticed when I built this circuit is that the motor did fire up right away when I got everything connected but them I remembered that I still had the code from my previous project (the "mood Cue" servo motor project) uploaded on the Arduino. I'm not saying this is your problem but definitely upload the code for the "motorized pinwheel" project prior to hooking up the 9V battery.

Good luck!