Motor stopped working.

Okay so the problem is: Given the following code and schematic (which i've built together), instead of the motor being off initially, it's on.

int motor = 8;

void setup() {
  
  pinMode(motor, OUTPUT);
  digitalWrite(motor, LOW);
}

// the loop routine runs over and over again forever:
void loop() {
      
}

every time i went by the sensor the motor stopped spinning

suggests that the motor would work and then stop lots of times - implying that the motor is fine?

Can you test the motor separately with a suitable battery ?

Can you test the program and driver with a different motor ?

Describe exactly what you mean by

The setup worked fine

and exactly how that differs from what happens now.

...R

@Robin2:

I changed up the original post which narrows down the problem alot. Hope it's descriptive now.

If the transistor is an NPN transistor, the Fritzing (motto: "confusing, extremely poor quality circuit diagrams for idiots") suggests that you have no base resistor. That may have destroyed the output pin. Use 220 Ohms minimum.

It also suggests that you are powering the motor from the Arduino, which can actually destroy the Arduino. Use a separate power supply and connect the grounds together.

You are getting some extremely bad advice from somewhere.

Can you provide me a diagram of what would fix the problems you have listed? Ex: where would I put the resistor? And for the external power, would should I buy and how would I attach it?

You may have already damaged the Arduino irreparably, but a proper tutorial is here (scroll down to motor control). However, it is better to have a reversed diode across the motor, than the capacitor labeled C1.


Is this one that won't break?

Who could possibly tell? The transistor type and pinout is not shown.
Please try to get away from those diagrams.

Most small transistors cannot handle enough current to drive most motors. Use a
logic level MOSFET?

Typical small motors are in 0.5A to 5A range of stall currents, small BJTs range from 0.15 to 0.6A

You can easily get a logic level MOSFET with 0.01 ohm on resistance that hardly notice 5A.

prestige:
@Robin2:

I changed up the original post which narrows down the problem alot. Hope it's descriptive now.

And made a nonsense of my Reply #1 in the process.

Don't make big changes to posts - correcting typos is OK. Put new material in a new Reply to maintain the chronological sense of the Thread so other readers can follow it.

...R