PID Controller using DC motors to follow a line

I am currently having trouble getting my motors to respond to inputs from my Arduino. I am following this lesson to setup my motors correctly: The only variation with my setup is that I am using an external power supply instead of the 5V from the Arduino because my motors require more power than the Arduino can supply.

This is my setup: []](http://)

The only thing I am writing to the motors in my program at the moment is analogWrite(motorPin, speed). I have not yet been able to test my PID controller because I cannot get the motors to respond at all. Anyone have any suggestions?


Your external power supply and the Arduino have to share a Ground or your transistor won't work.

Also a circuit diagram would be clearer I think. Which transistor are you using to switch the motors and how much current can it tolerate?

I am using P2N222A Transistors and when you mean they both have to use the same ground does that mean I ground everything through the Arduino or through the power supply?

2N2222 has a maximum of 1A collector current (which is barely enough), but more to the point it has so little gain at 1A out that its useless for driving from an Arduino pin at that level. Expect perhaps 0.5A out with 30mA in, but with poor saturation. That means 150 ohm base resistors.

Altogether it will struggle to power a motor which needs perhaps several amps peak, a power darlington or MOSFET would be much more capable.

Or are your motor really small with 0.5A stall current max?